Video: Getting Started with JavaFX Media
A very simple demo, showing the absolutely simplest approach to creating a JavaFX media player in under 5 minutes.
Published at DZone with permission of its author, Geertjan Wielenga.For offline viewing, download it here.
The demo is, in fact, so simple that the end result isn't very useful. However, without going into any kind of detail, it gives you an understanding of the basic JavaFX concepts and you see a movie running at the end of it.
And here's all the code you end up with at the end of the demo:
package samplemovieplayer1;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.media.*;
import javafx.ext.swing.SwingButton;
var media = Media{
source:"http://capra.sfbay.sun.com/~jm158417/javafx_videos/big_buck_bunny_512x288_h264.flv"}
var player = MediaPlayer{
media:media,
autoPlay:false}
Stage {
title: "Application title"
width: 250
height: 250
scene: Scene {
content: [
MediaView {
mediaPlayer:player
}
SwingButton {
text: "Play"
action: function() {
player.play()
}
}
]
}
}





Comments
Hannah Myeres replied on Thu, 2008/12/11 - 12:04pm
Jose Jeria replied on Thu, 2008/12/11 - 12:50pm
Roland Carlsson replied on Thu, 2008/12/11 - 2:56pm
Perhaps this isn't a nice question to ask but why isn't the demo itself a javafx applet? Show us the fine stuff instead of crappy flash :-)
To be a little more serious, if the team around Netbeans uses flash why should anyone else make the switch? If SUN doesn't push good content that shows how nice javafx is, who are going to do it?
Jon Antoine replied on Thu, 2008/12/11 - 3:27pm
Hey,
You also have a good how-to on this site : http://lexique-du-net.com/blog/index.php?post/2008/12/09/Create-your-VideoPlayer-with-JavaFX-part-one
+++
Geertjan Wielenga replied on Thu, 2008/12/11 - 4:29pm
Carl Dea replied on Sat, 2008/12/13 - 1:24am
Geertjan,
I'm not sure if the file is available online anymore.
I use this old video of Robert Eckstein:
http://blip.tv/file/get/Reckstei-TheUpdateCenter1JavaFX131.flv
-Carl
Geertjan Wielenga replied on Sat, 2008/12/13 - 9:51am
Carl Dea replied on Sat, 2008/12/13 - 10:05pm
in response to:
Geertjan Wielenga
Geertjan,
Odd, I put the address:
http://capra.sfbay.sun.com/~jm158417/javafx_videos/big_buck_bunny_512x288_h264.flv
and it seems that I can't get to it.
I'm getting MediaUnavailableException:
FX Media Object caught Exception com.sun.media.jmc.MediaUnavailableException: Media unavailable: http://capra.sfbay.sun.com/~jm158417/javafx_videos/big_buck_bunny_512x288_h264.flv
All in all I am impressed by how easy it is to do! If you did it in minutes I've done it in seconds, by cutting and pasting your code.
Question: Is there a free way to encode a movie to a *.flv file?
If not, can the media player play other formats?
I'm sure this is somewhat difficult to answer. (Codecs jungle)
I hope the media play can play mpeg4.
-Carl
Carl Dea replied on Sat, 2008/12/13 - 11:58pm
in response to:
Carl Dea
I think the answer to my question is here:
http://java.sun.com/developer/technicalArticles/Interviews/wyant_jfx.html
I went ahead and tried to play other formats and it worked fine!
Thanks.
-Carl
Wojciech Halick... replied on Mon, 2008/12/15 - 1:37pm
in response to:
Roland Carlsson
Carla Brian replied on Sun, 2012/04/15 - 10:16am
Passion Lab replied on Sun, 2012/09/02 - 3:52pm