Geertjan is a DZone Zone Leader and has posted 457 posts at DZone. You can read more from them at their website. View Full User Profile

Video: Getting Started with JavaFX Media

12.11.2008
| 23697 views |
  • submit to reddit
A very simple demo, showing the absolutely simplest approach to creating a JavaFX media player in under 5 minutes.

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()
}
}
]
}
}

 

Published at DZone with permission of its author, Geertjan Wielenga.

Comments

Hannah Myeres replied on Thu, 2008/12/11 - 12:04pm

Now it make sense for me for the first time, thankyou.

Jose Jeria replied on Thu, 2008/12/11 - 12:50pm

Very nice.

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

Hi Kirill. I hear you. Watch this space! You should realize also that everyone is learning at more or less the same speed right now, since all this is quite new, so all the discoveries are somehow similar. However, I hadn't seen a video with this subject matter before and so thought it made sense to make this available. I also wanted to have something available that showed the absolute basics, no frills, absolute bare minimum code for a media player. And this certainly does that. And I personally learned a lot putting it together (I'm as much a newbie as anyone else when it comes to JavaFX). But a follow up will appear soon with many of the bells and whistles promised by JavaFX.

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

Nope, the movie is still there, not going anywhere. But thanks very much for that Robert Eckstein reference, it's really good stuff.

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

I personally wouldn't be happy with Sun releasing intructional videos for JavaFX only - please read my comments on bug RT-2530 at javafx-jira.kenai.com. If anyone is experiencing problems described in the bug please vote for it.

Carla Brian replied on Sun, 2012/04/15 - 10:16am

I am new to this. I am looking for new resources for this so that I can review on it. - Paul Perito MD

Passion Lab replied on Sun, 2012/09/02 - 3:52pm

The writing essay paper http://www.termpapers.cc/ 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.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.