0

`这是
jmf 视频播放器放入面板的第一类

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

这是将 JPanel 中的视频播放器调用到帧的第二个类

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

问题是当我选择视频文件时,我只能听到音频,但视频不显示/显示
请帮忙

4

0 回答 0