Forcing libVLC to work in synchronous mode is a must.

This forum is about all development around libVLC.
Pap
New Cone
New Cone
Posts: 4
Joined: 23 Jan 2014 18:25

Forcing libVLC to work in synchronous mode is a must.

Postby Pap » 11 Apr 2014 00:45

Hi there,
After quite some experiments with libVLC, I realized that, although the library is neat in many ways and very easy to use, it works in "asynchronous mode", meaning whatever libVLC command you issue it is actually executed later, asynchronously. This leads to strange problems, and makes the library almost impossible to use. For example, consider the following example:

Code: Select all

#include <iostream> #include <vlc/vlc.h> int main(void) { libvlc_instance_t *vlc_instance; libvlc_media_t *media; libvlc_media_player_t *player; vlc_instance = libvlc_new(0, NULL); media = libvlc_media_new_path(vlc_instance,"long_sample.ogg"); player = libvlc_media_player_new_from_media(media); libvlc_media_release(media); libvlc_media_player_play(player); std::cout<<"Volume: "<<libvlc_audio_get_volume(player)<<std::endl; .......... rest of the program .......... libvlc_media_player_release(player); libvlc_release(vlc_instance); return 0; }
The media player starts to play, as expected, then it is supposed to print media player's volume. Guess what it prints:

Code: Select all

Volume: -1
This is clearly wrong. Here is the proof: Modify the above program to

Code: Select all

#include <chrono> #include <thread> #include <iostream> #include <vlc/vlc.h> int main(void) { libvlc_instance_t *vlc_instance; libvlc_media_t *media; libvlc_media_player_t *player; vlc_instance = libvlc_new(0, NULL); media = libvlc_media_new_path(vlc_instance,"long_sample.ogg"); player = libvlc_media_player_new_from_media(media); libvlc_media_release(media); libvlc_media_player_play(player); std::this_thread::sleep_for(std::chrono::milliseconds(100)); //Delay. std::cout<<"Volume: "<<libvlc_audio_get_volume(player)<<std::endl; .......... rest of the program .......... libvlc_media_player_release(player); libvlc_release(vlc_instance); return 0; }
This is exactly the same program as before, except we wait a bit before calling libvlc_audio_get_volume(). It prints:

Code: Select all

Volume: 100
which is correct.
The problem is not only about libvlc_audio_set_volume(). It is actually about any other libVLC function. For example, modify the above programs so that you call, e.g., libvlc_audio_set_volume(), or libvlc_audio_set_channel(), or whatever affecting the media player object. It does NOT work, unless you set a small delay before issuing the command. This is extremely annoying, and as I said, it makes the library almost impossible to work properly.

I realize developers swiched to asynchronous mode for a reason. However, there must be a way to force libVLC executing commands synchronously, immediately, right at the time, not whenever the library wants to do so. Even if the libVLC command I issue takes some time to be executed, the program must wait for the time needed before proceeding. This way, you could ask for the current media player's volume or whatever else, and you would get precisely what you ask, not erroneous results. Is there any way to do that?

Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 16 guests