我使用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);
}
}
......
}`