0

我使用 javax.media.Player 在 java Swing 中播放视频,它工作得恰到好处。但是当我需要删除刚刚播放的视频时,它会提示该视频被某些程序占用,肯定是MediaPlayer。谁能教我如何在视频播放结束时释放资源?

代码如下:

public class VideoPlayerPanel extends javax.swing.JPanel {
    private Player mediaPlayer;
    private Component video = null;
    private Component controls = null;

    /**
     * Creates new form VideoPlayerPanel
     */
    public VideoPlayerPanel() {
        initComponents();
    }

    public void play(URL url) {
        if (video != null) {
            remove(video);
        }
        if (controls != null) {
            remove(controls);
        }
        try {
            mediaPlayer = Manager.createRealizedPlayer(url);
            video = mediaPlayer.getVisualComponent();
            controls = mediaPlayer.getControlPanelComponent();
            this.add(video, BorderLayout.CENTER);
            this.add(controls, BorderLayout.SOUTH);
            validate();
            revalidate();
        } catch (IOException ex) {
            Logger.getLogger(VideoPlayerPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoPlayerException ex) {
            Logger.getLogger(VideoPlayerPanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CannotRealizeException ex) {
            Logger.getLogger(VideoPlayerPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

   ......               
}`
4

0 回答 0