0

我想在 Jframe 中播放视频并将其附加到必须播放的 jpanel (jPanel1) 上。它一直在说:

“从源头读取错误。”

而且我觉得我的媒体 URL 是正确的。这是一个小型 MP4 视频。

这是我的代码:

public void Player()  {

    try{
        //create a player to play the media specified in the URL


        Player mediaPlayer = Manager.createRealizedPlayer(new URL("C:\\Users\\Michael\\Downloads\\mike.jar"));

        Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);

        //get the components for the video and the playback controls
        Component video = mediaPlayer.getVisualComponent();
        Component controls = mediaPlayer.getControlPanelComponent();

        if ( video != null )
            jPanel1.add( video, BorderLayout.CENTER ); //add video component
        if ( controls != null )
            jPanel1.add( controls, BorderLayout.SOUTH ); //add controls

            mediaPlayer.start(); //start playing the media clip
    } //end try
    catch ( NoPlayerException noPlayerException ){
        JOptionPane.showMessageDialog(null, "No media player found");
    } //end catch
    catch ( CannotRealizeException cannotRealizeException ){
        JOptionPane.showMessageDialog(null, "Could not realize media player.");
    } //end catch
    catch ( IOException iOException ){
        JOptionPane.showMessageDialog(null, "Error reading from the source.");
    } //end catch
4

1 回答 1

2
new URL("C:\\Users\\Michael\\Downloads\\mike.jar")

这不是您希望创建指向本地文件的 URL 的方式。利用

new File(path).toURI().toURL()
于 2013-07-18T20:34:43.793 回答