Reputation: 2294
I can play .mpg format video with the Java media framework. But I can not play all format of video. When I want to play .AVI format video, the video is play but the sound is not come. How to play other format such as FLV, mp4, avi?
public class MediaPanel extends JPanel
{
public Player mediaPlayer;
public Component video;
public Component controls;
public MediaPanel(URL mediaURl)
{
setLayout(new BorderLayout());
Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
try
{
//Player
// this. mediaPlayer.stop();
//this.mediaPlayer.close();
mediaPlayer=Manager.createRealizedPlayer(mediaURl);
//Component
video=mediaPlayer.getVisualComponent();
//Component
controls=mediaPlayer.getControlPanelComponent();
if(video!=null)
add(video,BorderLayout.CENTER);
if(controls!=null)
add(controls,BorderLayout.SOUTH);
mediaPlayer.start();
}
catch(NoPlayerException noPlayerException)
{
System.err.println("No media");
}
catch(CannotRealizeException cannotRealizeException)
{
System.err.println("Could not");
}
catch(IOException iOException)
{
System.err.println("Error");
}
}}
Upvotes: 0
Views: 9660
Reputation: 168815
You need to add a Service Provider Interface for the encoding in question. E.G. The JMF provides an SPI for MP3 that can be added to the run-time class-path of an app. to allow it to read MP3s using Java Sound.
Upvotes: 1