无法在 Eclipse 中关闭小程序
我有一个运行 VLCJ 的小程序 (http://code.google.com/p/vlcj/) - 基本上将 VLC 播放器嵌入到小程序中。 在 Eclipse 中运行时,它运行良好,但我无法关闭调试小程序窗口或以某种方式终止它。我想知道,这是为什么呢?代码中是否有任何内容阻止其停止调试?我必须重新启动 Eclipse 才能使其退出。我很确定您不需要添加 destroy() 来关闭调试窗口。
谢谢
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Frame;
import javax.swing.JApplet;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
public class Main extends JApplet {
/**
* @param args
*/
/* entry point */
public void init() {
String file = "110825-155446.wmv"; // only 2-3 seconds clip for minimum storage
runVideo(file);
}
/* runs the video file */
public void runVideo(String file) {
setSize(400,300);
setLayout(new BorderLayout());
Canvas vs = new Canvas();
add(vs,BorderLayout.CENTER);
setVisible(true);
MediaPlayerFactory factory = new MediaPlayerFactory();
EmbeddedMediaPlayer mediaPlayer = factory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(factory.newVideoSurface(vs));
mediaPlayer.playMedia(file);
try {
Thread.currentThread().join();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
I have an applet that runs VLCJ (http://code.google.com/p/vlcj/) - basically embedding a VLC player in an applet.
When running in eclipse, it runs well but I cannot close the debugging applet-window or terminate it somehow. I wonder, why is this? Is there anything in the code that prevents it from stopping debugging? I have to restart eclipse in order to make it quit. Im quite sure you dont need to add destroy() to enable closing of the debugging window.
Thanks
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Frame;
import javax.swing.JApplet;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.sun.jna.NativeLibrary;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
public class Main extends JApplet {
/**
* @param args
*/
/* entry point */
public void init() {
String file = "110825-155446.wmv"; // only 2-3 seconds clip for minimum storage
runVideo(file);
}
/* runs the video file */
public void runVideo(String file) {
setSize(400,300);
setLayout(new BorderLayout());
Canvas vs = new Canvas();
add(vs,BorderLayout.CENTER);
setVisible(true);
MediaPlayerFactory factory = new MediaPlayerFactory();
EmbeddedMediaPlayer mediaPlayer = factory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(factory.newVideoSurface(vs));
mediaPlayer.playMedia(file);
try {
Thread.currentThread().join();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原因在于此代码片段部分:
它阻止应用程序关闭,因为它不想返回系统。
Thread.join()
使当前线程等待另一个线程完成,基本上它会永远等待。要改进它,您可以这样做(如http://code.google. com/p/vlcj/wiki/MinimalMp3Player):
但是,我们不能在 Java servlet 代码(甚至 applet 代码)中使用
System.exit()
方法,因为它可以关闭其他 Java 应用程序/servlet/applet 代码可能需要的代码所使用的 JVM。请参阅 System.exit(1) 的替代方案、在 Servlet 的 destroy() 方法中调用 System.exit()The reason is at this code snippet part:
It blocks the application from closing since it doesn't want to return to the system.
Thread.join()
makes the current thread waits for another thread to complete, basically it waits forever.To improve it, you can do like this (as in http://code.google.com/p/vlcj/wiki/MinimalMp3Player):
However, we cannot use
System.exit()
method in a Java servlet code (or even applet code) as it can shutdown the JVM used by the code which may be needed by other Java application/servlet/applet codes. See Alternatives to System.exit(1), Calling System.exit() in Servlet's destroy() method