Play Video Using Java
Monday, 10 March 2014Posted by
Amrishwa
0 Comments
Playing Multimedia Files Using java ,So to do this job we need to download Java Media Framework (JMF)
here is the link
JMF
Note:-JMF does’nt supports all media or video formats ex; .mp4,.flv etc. for more information kindly visit Oracle website Thanks.
I have used a .mpg file in this project
Now Import the following packages
import java.awt.BorderLayout;
import java.awt.Component;
import java.net.URL;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.Player;
import javax.swing.JFrame;
Now write down the following code on Jbutton action performed or Jframe Load as you wish
try
{
String mdurl=”file:///C:/Users/xyz/Desktop/phantom.mpg”;URL url=new URL(mdurl);
Player player=Manager.createRealizedPlayer(url);Component cmpt=player.getVisualComponent();
Component ctrls=player.getControlPanelComponent();
cmpt.resize(600, 400);
this.add(cmpt,BorderLayout.CENTER);
ctrls.resize(600, 400);
this.add(ctrls,BorderLayout.SOUTH);
player.start();
this.resize(600, 400);
}
catch(Exception sdd)
{
System.out.println(sdd);
}
Subscribe to:
Post Comments (Atom)