JMC / JavaFX - Playing video
I've tried to create a small application, to just play a video from my hdd. I've tried for 3 days now but I don't know, how to do it. There a开发者_StackOverflowre no good tutorials or examples on the net, to do this with the current javafx (jmc) release. I wanna create a swing application, that is using the jmc classes from javafx. I tried this:
...
MediaProvider mp;
String mediaURI = "G:\\teste2.avi";
JFrame jf = new JFrame();
JPanel j = new JPanel();
j.setLayout(new BorderLayout());
mp = new MediaProvider();
try {
mp.setSource(new URL("file://" + mediaURI).toURI());
} catch (MalformedURLException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}catch (URISyntaxException ex2) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex2);
}
mp.setRepeating(false);
j.setSize(800, 600);
j.setVisible(true);
jf.add(j);
jf.setSize(800, 600);
j.setBackground(Color.red);
jf.setVisible(true);
mp.play();
...
But now: How to add the "mp" to my jpanel? "j.add(mp);" doesn't work (jpanel is red only, because of the color.red, but no video is shown). Is there an easy way to do it? Thank you.
I've also tried with a second class:
public class Player implements VideoRendererListener{
private MediaProvider prov; //This is the most important class!
private VideoRenderControl renderer; //It's a interface to control the rendering
private Graphics2D ig;
private JPanel panel;
public void Player(File path, JPanel panel) {
ig = (Graphics2D) panel.getGraphics();
this.panel = panel;
prov = new MediaProvider(path.toURI());
renderer = prov.getControl(VideoRenderControl.class);
renderer.addVideoRendererListener(this);
prov.play();
System.out.println(prov.getDuration());
}
@Override
public void videoFrameUpdated(VideoRendererEvent arg0) {
float ratio = renderer.getFrameHeight() / (float)renderer.getFrameWidth();
int diff = ( panel.getHeight() - Math.round(ratio * panel.getHeight())) / 2;
System.out.println(renderer.getFrameHeight());
/* renderer.paintVideo(ig,
new Rectangle(0, 0, renderer.getFrameWidth(), renderer.getFrameHeight())
,
new Rectangle(0, diff, panel.getWidth(), Math.round(ratio * panel.getHeight())));
*/
}
}
and adding this to my jpanel in main class:
Player p = new Player();
p.Player(f,j);
but the "renderer.paintVideo()" method isn't available :( so also this is not working (maybe with an old version of jmc, because i found this on the internet as example).
Does anyone know, how to add a local video to a swing application with the current release of javafx, jmc ?
I also searching about how to play video and I found this:
http://www.informit.com/articles/article.aspx?p=1326515&seqNum=4
Check the "Listing 3 XMP2.java" that work for me.
Regards.
精彩评论