0

`this is the first class
the jmf video player is put into a panel

import java.awt.BorderLayout;
import java.awt.Component;
import java.io.IOException;
import java.net.URL;
import javax.media.CannotRealizeException;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.swing.JPanel;

public class MediaPanel extends JPanel {

public MediaPanel(URL mediaURL) {
    setLayout(new BorderLayout());

    Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);

    try {

        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");

    } catch (CannotRealizeException cannotRealizeException) {           
        System.err.println("Could not media Player");

    } catch (IOException ioException) {
        System.err.println("Err reading from the source");
    }
}
}

this is the second class that calls the video player in the JPanel to the frame

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class MediaTest {

public static void main(String[] args) {
    JFileChooser filechooser = new JFileChooser();
    int result = filechooser.showOpenDialog(null);

    if (result == JFileChooser.APPROVE_OPTION) {
        URL mediaURL = null;

        try {
            mediaURL = filechooser.getSelectedFile().toURI().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 problem is when I choose a video file, I can only hear the audio, but video does not display/show
please help

MastaOpec
  • 39
  • 9
  • *"when I choose a video file"* Can you vague that up for us? It is in danger of containing useful information. Or to put that another way. What file-type is it? What enconding? BTW - you do realize that JMF was obsolete 8 years ago, right? It does not support enough formats and encodings to be used as a general purpose player. – Andrew Thompson Oct 04 '13 at 10:52
  • sorry, when i choose an mpeg/mpg video file because i converted an mp4 video format to mpg format – MastaOpec Oct 04 '13 at 11:23
  • You should take a look at the JavaFX `MediaPlayer`. – Josh M Oct 04 '13 at 11:43
  • yah, just thought of that thanks dough – MastaOpec Oct 04 '13 at 11:59

0 Answers0