Home > Mobile >  How to change video in vlcj-4
How to change video in vlcj-4

Time:10-07

i'm trying to change the video thats being played by vlcj. But when it's supposed to switch video, the application just closes. It does not throw any errors, it just exits. This is my code:

import javax.swing.JFrame;
import java.awt.event.*;

import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;

public class Main {

    private final JFrame frame;

    private final EmbeddedMediaPlayerComponent mediaPlayerComponent;

    public static void main(String[] args) {
        new Main();
    }
    public Main() {
        frame = new JFrame("My First Media Player");
        frame.setBounds(100, 100, 600, 400);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                mediaPlayerComponent.release();
                System.exit(0);
            }
        });

        mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
        frame.add(mediaPlayerComponent);
        frame.setVisible(true);
        
        mediaPlayerComponent.mediaPlayer().submit(new Runnable(){
            @Override
            public void run() {
                mediaPlayerComponent.mediaPlayer().media().play("E:\\Somevideo1.mkv");
            }
        });

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e1) {
        }


        mediaPlayerComponent.mediaPlayer().submit(new Runnable(){
            @Override
            public void run() {
                System.out.println("Reached 1");
                mediaPlayerComponent.mediaPlayer().media().play("E:\\Somevideo2.mkv");
                System.out.println("Reached 2");
            }
        });

    }
}

It prints "Reached 1" but the application exits before it reaches "Reached 2".

CodePudding user response:

Okay apparently its not a VLCJ issue, because when i change the video in VLC media player it also just crashes, so something is wrong with my VLC.

I'll just try fixing my VLC then :/

  • Related