无法在 Eclipse 中关闭小程序

发布于 2024-12-01 13:58:03 字数 1504 浏览 3 评论 0原文

我有一个运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2024-12-08 13:58:03

原因在于此代码片段部分:

try {
    Thread.currentThread().join();
} catch (InterruptedException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

它阻止应用程序关闭,因为它不想返回系统。 Thread.join() 使当前线程等待另一个线程完成,基本上它会永远等待。

要改进它,您可以这样做(如http://code.google. com/p/vlcj/wiki/MinimalMp3Player):

mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
  public void finished(MediaPlayer mediaPlayer) {
    System.exit(0);
  }
  public void error(MediaPlayer mediaPlayer) {
    System.exit(1);
  }
});
mediaPlayer.playMedia(args[0]);
Thread.currentThread().join();

但是,我们不能在 Java servlet 代码(甚至 applet 代码)中使用 System.exit() 方法,因为它可以关闭其他 Java 应用程序/servlet/applet 代码可能需要的代码所使用的 JVM。请参阅 System.exit(1) 的替代方案在 Servlet 的 destroy() 方法中调用 System.exit()

The reason is at this code snippet part:

try {
    Thread.currentThread().join();
} catch (InterruptedException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

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):

mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
  public void finished(MediaPlayer mediaPlayer) {
    System.exit(0);
  }
  public void error(MediaPlayer mediaPlayer) {
    System.exit(1);
  }
});
mediaPlayer.playMedia(args[0]);
Thread.currentThread().join();

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文