playing video using jmf

13,147

What kind of video are you trying to play? JMF is a pretty old library and won't be able to play most of modern video formats, only a few old ones (i am not even sure which ones).

Actually, if I am right, to play something specific you will have to write/add your own video-encoders into JMF or at least download and use existing ones, which are usually outdated.

If you really want to have something like tunable video player that could play any modern video there are two options (in my opinion):

  1. Use vlcj library to embed VLC video player into your Java-application

  2. USe JavaFX media player

I am offering only those two because I have dig through tons of libraries some time ago and there were nothing else even close to these two. Plus most of other libraries are outdated as well as JMF itself and these two are getting frequent updates and are supported with lots of users so those two are the best choice.

In case you don't mind embedding Java FX player into your application - that might be your choice.

On the other hand - vlcj is stable and easily integrated into Swing applications (its not like its hard with Java FX, but vlcj might be better for some cases).

Anyway, it is your call what to choose.

Share:
13,147
Ruby
Author by

Ruby

Software Engineer, Love Java Coding

Updated on June 14, 2022

Comments

  • Ruby
    Ruby almost 2 years

    I am trying to play a video file using JMF but it gives me No Media Player found exception.

    Here is my code, can anyone tell me what I am doing wrong here?

    public class MediaPanel extends JPanel {
    public MediaPanel(URL mediaURL) {
        setLayout(new BorderLayout());
    
        try {
            Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
            Player 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 player found");
        } // end catch
        catch (CannotRealizeException cannotRealizeException) {
            System.err.println("Could not realize media player");
        } // end catch
        catch (IOException iOException) {
            System.err.println("Error reading from the source");
        }
    }
    }
    
    
    
    public class MediaTest {
    
    public static void main(String args[]) {
        // create a file chooser
        JFileChooser fileChooser = new JFileChooser();
    
        // show open file dialog
        int result = fileChooser.showOpenDialog(null);
    
        if (result == JFileChooser.APPROVE_OPTION) // user chose a file
        {
            URL mediaURL = null;
            Player mediaPlayer = null;
    
            try {
                // get the file as URL 
                mediaURL = fileChooser.getSelectedFile().toURL();
            } catch (MalformedURLException malformedURLException) {
                System.err.println("Could not create URL for the file");
            }
    
            if (mediaURL != null) {
                JFrame mediaTest = new JFrame("Media Tester");
                mediaTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
                MediaPanel mediaPanel = new MediaPanel(mediaURL);
                mediaTest.add(mediaPanel);
    
                mediaTest.setSize(300, 300);
                mediaTest.setVisible(true);
            }
        }
    }
    }
    

    The exception that I am getting is No media player found

  • mKorbel
    mKorbel almost 12 years
    for stinky dead fish (JMF) +1
  • Ruby
    Ruby almost 12 years
    @Mikle Garin thanks for your response , actually i am trying to use vlcj ...my main task is to capture the live video stream from an ip camera and show the video on my application ...any suggestions or simple code example using vlcj would be very helpful
  • Mikle Garin
    Mikle Garin almost 12 years
    @Ruby well, actually i am not that good at vlcj - just used it once in my own project some long time ago and it worked like a charm for simple video playback case (even on non-win OS). Maybe this (code.google.com/p/vlcj/wiki/Streaming) specific tutorial and some others on the same resource might help you start working with vlcj.