javaaudiovlcj

VLCJ controlling multiple audio files from a single java program


I want to play multiple audio files from a single java process via vlcj (old version 3.10.1). Below is the snippet of java code that I wrote to play audio from two files:-

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "video-plugins");
Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
for (int i = 0; i < 2; i++) {
            List<String> vlcArgs = new ArrayList<String>();
            vlcArgs.add("--no-video");
            MediaPlayerFactory factory = new MediaPlayerFactory(vlcArgs);
            MediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer();
            if (i == 0)
                mediaPlayer.startMedia("D:\\a.mp4");
            else
                mediaPlayer.startMedia("D:\\b.mp4");
            mediaPlayer.setVolume(10 * (i + 10));
        }
        Thread.currentThread().join(); 

In this sample program, I am playing audio from two files and want to control them individually(mute, unmute, change volume of audio of individual file) from windows control panel sound section but I only see one "VLC Media Player" in windows 10 volume mixer.(see below attached image)

I thought that this is due to the same MediaPlayerFactory instance used in playing audio of two files and then I tweaked MediaPlayerFactory but with no avail, I see only one "VLC Media Player" in windows 10 volume mixer. If I change the volume from "VLC Media Player" in windows 10, it does the operation for the audio of both files.

Is there a way to play these two files individually via vlcj from single java program so that they can be controlled individually?enter image description here

Although, I can run both files individually from two different java programs, it will show two "VLC Media Player" in windows sound section but this is not what I want. I want to control multiple files from single java program via vlcj.


Solution

  • This can not be done with the version of VLC/LibVLC that you are using (3.x).

    All native media player instances in the same process share the same audio controls.

    I have however heard that this may be dependent on the audio output plugin that is being used, but on Linux I have never personally seen this work.

    Early testing of the upcoming VLC/LibVLC 4.x offers some hope that in the future you do in fact get separate audio controls, but at time of writing this answer that version of VLC may still be some way off.

    In short, there's nothing you can "fix" here.

    You could run multiple media players in separate processes and somehow control them, but that is not trivial.