caprica / vlcj

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

Playing two files in sync #1230

Closed mainrs closed 1 month ago

mainrs commented 1 month ago

I have two audio tracks. The first track contains the vocals of a song. The second the instruments.

I want to play them in sync. For that I create two instances of AudioMediaComponent and prepare the files.

I then call play on both of them. However, this does introduce sometines a noticable delay. Sometimes it doesn't.

What can be the cause for that? My guess would be that it puts the playback onto another thread, one for each component. And this it can introduce small delays when calling the play method (since one is called before the other).

caprica commented 1 month ago

You can't synchronise like that reliably, there's nothing in VLC to keep them in sync either. What you said is almost certainly right, I mean the reasons for the drift.

However, what you can try is adding a new "slave" track, although I don't think you can play two audio tracks at the same time. Might be worth a quick try though.

I do seem to remember there was some kind of support for multi-track audio in the LibVLC API, but I never got it working. I can't remember how hard I tried tbh.