Search code examples
javahttpaudiostreamingvlcj

VLCJ Can' t open audio streaming using http on client-side


I'm using VLCJ for audio streaming between a server and a client. The server-side is all set up as once its running I can open the stream by just using the vlc itself and I'm able to listen any file that I have selected on the server. However, on the client-side, I'm doing the following:

String url = "http://127.0.0.1:5555";
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
HeadlessMediaPlayer mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer();
mediaPlayer.startMedia(url);

But don't get any sound at all. If I run vlc http://127.0.0.1:5555 in a terminal, it opens the vlc and plays back the music track that is being streamed by the server, without any problem.

Recently, I found out that the problem is with the path. By using System.out.println(mediaPlayer.mrl()); it shows that it is opening file:///home/user/workspace/audioProject/http%3A//127.0.0.1%3A5555 instead of the MRL directly from the HTTP address (http://127.0.0.1:5555).

Here, it shows an example of how the client opens a stream.

Any guesses about what I'm doing wrong? And a workaround to it?

Thanks in advance!


Solution

  • You are using a version of VLC that is incompatible with the version of vlcj that you are using.

    There are two methods in LibVLC to set media, one is for setting "local" file media, and the other is a "location" - essentially a URL:

    libvlc_media_new_location(instance, media);
    libvlc_media_new_path(instance, media);
    

    In earlier versions of VLC, it was possible to get away with just using one of these functions to set the media whether it was a local file based media or a URL. That one function, libvlc_media_new_path, would work for both types of media.

    That changed with a recent version of VLC (I do not recall specifically which version it was).

    At that time, because of this change in VLC, vlcj was changed to guess the type of media (file or URL) and call the appropriate LibVLC function.

    So, the solution is to use a compatible version of VLC/vlcj.

    The change in vlcj was version 2.2.0, but of course I would recommend you use the latest version of vlcj which at time of writing is 3.0.1.