elzaksspro / gstreamer-java

Automatically exported from code.google.com/p/gstreamer-java
0 stars 0 forks source link

Swing components should be created on the event dispatcher #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
According to Swing's single-thread rule, SwingPlayer's main should become
something like:

    public static void main(String[] args) {
        final GMainLoop loop = new GMainLoop();
        args = Gst.init("Swing Player", args);

        if (args.length < 1) {
            System.err.println("Usage: SwingPlayer <filename>");
            System.exit(1);
        }

        final PlayBin playbin = new PlayBin("play");
        playbin.setInputFile(new File(args[0]));

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {

                // System.setProperty("sun.java2d.opengl", "True");
                JFrame frame = new JFrame("Swing Test");

                GstVideoComponent panel = new GstVideoComponent();
                panel.setPreferredSize(new Dimension(640, 480));
                frame.add(panel, BorderLayout.CENTER);

                // Element xsink = ElementFactory.make("ximagesink", "xsink");
                // Element xvsink = ElementFactory.make("xvimagesink",
                // "xvsink");
                // Element sdlsink = ElementFactory.make("sdlvideosink",
                // "sdlsink");
                // Element audio = ElementFactory.make("gconfaudiosink",
                // "audio");
                // playbin.setAudioSink(audio);

                playbin.setVideoSink(panel.getElement());
                // playbin.setVideoSink(xsink);
                // playbin.setVideoSink(getGLSink());

                playbin.setState(State.PLAYING);
                loop.startInBackground();
                frame.setSize(640, 480);
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);

            }
        });

Original issue reported on code.google.com by ing...@gmail.com on 23 May 2007 at 9:34

GoogleCodeExporter commented 8 years ago
You are indeed correct. (though 90% of the code out on the net doesn't do it -
including most sun examples - so somehow it manages to work).

Should be fixed now.

Original comment by wmeiss...@gmail.com on 23 May 2007 at 12:50

GoogleCodeExporter commented 8 years ago
Nice. It's just that it might fail *in some cases* otherwise.

The threading rule has changed a few times in Swing's history. I remember a 
(JavaOne
2005?) presentation about that issue. The newer sun tutorials already adhere to 
the
recent version, e.g.:
http://java.sun.com/docs/books/tutorial/uiswing/examples/start/HelloWorldSwingPr
oject/src/start/HelloWorldSwing.java

Original comment by ing...@gmail.com on 23 May 2007 at 1:35