Media player using java swing -
i beginner in java programming. going play video in java stuck. first tried vlcj, 32-bit jdk(is right?) , trying jmf using mpg file. problem hear sound of file, not see video. shows: unable handle format: mpeg, 640x360, framerate=29.9, length=345600 code using is:
import java.awt.borderlayout; import java.awt.component; import java.io.file; import java.net.malformedurlexception; import java.net.url; import javax.media.manager; import javax.media.medialocator; import javax.media.player; import javax.swing.jframe; import javax.swing.jpanel; public class mediaplayer extends jpanel { public mediaplayer(url mediauurl) { setlayout(new borderlayout()); try { player mediaplayer=manager.createrealizedplayer(new medialocator(mediauurl)); component video=mediaplayer.getvisualcomponent(); component control=mediaplayer.getcontrolpanelcomponent(); if (video!=null) { add(video, borderlayout.center); // place video component in panel } add(control, borderlayout.south); // place control in panel mediaplayer.start(); } catch (exception e) { } } public static void main(string[] args) { url mediaurl=null; file file = new file("src/media/jellyfish.mpg"); try { mediaurl = file.tourl(); } catch (malformedurlexception ex) { system.out.println(ex); } jframe mediatest = new jframe( "movie player" ); mediatest.setdefaultcloseoperation( jframe.exit_on_close ); mediaplayer mediapanel = new mediaplayer( mediaurl ); mediatest.add( mediapanel ); mediatest.setsize( 800, 700 ); // set size of player mediatest.setlocationrelativeto(null); mediatest.setvisible( true ); } }
can help? in advance
Comments
Post a Comment