caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.13k stars 259 forks source link

Local m3u8 videos not playing #920

Closed moulichandu closed 4 years ago

moulichandu commented 4 years ago

I have a video which is m3u8, if i place it on my server and pass that url to vlcj player inside In one of my Java Application it is playing very well, where as i downloaded that video and placed it in local drive and try to play it, i am unable to play. it nothing showing. If i placed the same video inside local server(xampp server) again it is playing, could you pls share solution to how to play the local videos which are in my local drive.

caprica commented 4 years ago

Sorry, your problem statement is not clear enough to me.

Just about every example in the vlcj test sources shows how to play a local video.

What specifically are you trying that doesn't work?

moulichandu commented 4 years ago

I have m3u8 file in my local drive, i tried to play with vlcj code EmbeddedMediaListPlayerComponent cc=new EmbeddedMediaListPlayerComponent(); JFrame jf=new JFrame(); jf.setContentPane(cc); jf.setBounds(200,200,600,600); jf.setVisible(true); jf.addWindowListener(new WindowAdapter() {

                 @Override
                 public void windowClosing(WindowEvent e) {
                     cc.release();
                     //System.exit(0);
                     super.windowClosing(e); //To change body of generated methods, choose Tools | Templates.
                 }

                });

cc.mediaListPlayer().list().media().add("E:\videos\3\chunklist_b1177584.m3u8"); // Another line of vlcj code to play the media... cc.mediaListPlayer().controls().play();

I am unable to play this file

caprica commented 4 years ago

An m3u is a playlist, when you play a playlist it actually parses the playlist and creates subitems. You then need to play whichever subitem you want from the list.

There are a number of ways to do it.

You could wait for a finished event via the event listener and then inspect the subitems.

You could wait for the various subitem events via an event listener.

You could use a MediaListPlayer rather than a MediaPlayer.

caprica commented 4 years ago

Oh, I just realised you are using a medialistplayer already... hmm...

moulichandu commented 4 years ago

I already tried with MediaListplayer, but no luck

moulichandu commented 4 years ago

I have gone through Java Media Player code

public ConnectionHolder createConnectionHolder() throws IOException { // first check if it's cached if (null != cacheEntry) { if (Logger.canLog(Logger.DEBUG)) { Logger.logMsg(Logger.DEBUG, "Locator.createConnectionHolder: media cached, creating memory connection holder"); } return ConnectionHolder.createMemoryConnectionHolder(cacheEntry.getBuffer()); }

    // then fall back on other methods
    ConnectionHolder holder;
    if ("file".equals(scheme)) {
        holder = ConnectionHolder.createFileConnectionHolder(uri);
    } else if (uri.toString().endsWith(".m3u8") || uri.toString().endsWith(".m3u")) {
        holder = ConnectionHolder.createHLSConnectionHolder(uri);
    } else {
        synchronized (propertyLock) {
            holder = ConnectionHolder.createURIConnectionHolder(uri, connectionProperties);
        }
    }

    return holder;
}

In the first condition it checks the file, but in the second condition verifying the m3u8 files and creating HLSStream, but when we pass local file first condition will satisfy and will not go second condition, will it same for this VLCJ also? If so how to play local m3u8 files? Could you please share solution an urgent base...

caprica commented 4 years ago

Here's the MinimalTestPlayer example from the vlcj sources, I changed it to hard-code the command-line arguments to play an m3u8 file:

public class MinimalTestPlayer extends VlcjTest {

    public static void main(String[] args) throws Exception {
        args = new String[] {"/home/mark/test.m3u8"};

        if(args.length != 1) {
            System.out.println("Specify an MRL to play");
            System.exit(1);
        }

        final EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

        JFrame f = new JFrame("Test Player");
        f.setIconImage(new ImageIcon(MinimalTestPlayer.class.getResource("/icons/vlcj-logo.png")).getImage());
        f.setSize(800, 600);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                mediaPlayerComponent.release();
            }
        });
        f.setContentPane(mediaPlayerComponent);
        f.setVisible(true);

        mediaPlayerComponent.mediaPlayer().media().play(args[0]);

        Thread.sleep(1000);

        mediaPlayerComponent.mediaPlayer().controls().setPosition(0.95f);

        Thread.currentThread().join();
    }
}

After playing, I set the position to almost the end so I don't have to wait long for the next item to start, obviously you wouldn't normally do that.

Here's my m3u8 file:

mark@serenity:~$ cat /home/mark/test.m3u8
/home/mark/sekiro.mp4
/home/mark/bloodborne.mp4
mark@serenity:~$ 

When I run that application, it correctly plays both files in sequence.