我正在尝试在关闭jframe时停止流。我不想EXIT_ON_CLOSE因为我不想退出我的申请。当我使用DISPOSE_ON_CLOSE时,帧关闭但是音频流继续播放。有没有办法在不使用某些外部按钮的情况下停止此流。(我想通过单击" X"在jframe上关闭流)。 谢谢你的帮助。
public class MediaPlayer {
private JFrame ourFrame = new JFrame();
private EmbeddedMediaPlayerComponent ourMediaPlayer;
private String mediapath = "";
MediaPlayer(String vlcPath,String mediaURL) {
this.mediapath = mediaURL;
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcPath);
ourMediaPlayer = new EmbeddedMediaPlayerComponent();
ourFrame.setContentPane(ourMediaPlayer);
ourFrame.setSize(1200, 800);
ourFrame.setVisible(true);
ourFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void run() {
ourMediaPlayer.getMediaPlayer().playMedia(mediapath);
}
}
答案 0 :(得分:1)
您可以在窗口关闭时处理流关闭操作,如下所示:
ouFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
// close/stop audio stream here
System.out.println("closed");
}
});