Animesh Kumar Paul
Animesh Kumar Paul

Reputation: 2294

How to play flv, mp4, avi format video in JAVA?

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

Answers (1)

Andrew Thompson
Andrew Thompson

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

Related Questions