Replay sound after it is ended

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

Replay sound after it is ended

Postby Pap » 23 Jan 2014 18:56

Greetings VideoLAN community,
being a fan of VLC player for years now, I decided to use libVLC for developing multimedia applications. Note that I am only interested on sound playback for now. Compared to other APIs, I found libVLC to be much easier to use. I am also developing Fortran 2003/2008 bindings for libVLC, which work pretty well.

However, I have a problem concerning sound replay; specifically, I can initialize a libvlc_media_player_t struct, with libvlc_media_player_new_from_media(), which is played as expected with libvlc_media_player_play(). Once the sound is "ended" (as verified with libvlc_media_player_get_state()), I cannot replay the sound. Any further call of libvlc_media_player_play() produces no sound at all. The only way I found to replay a sound once it is ended is to call libvlc_media_player_stop() first, then call libvlc_media_player_play(), in which case the sound is replayed. I am probably missing something important here, as I don't see why I should stop a sound that is already ended in order to replay it.

The problem is irrelevant to said Fortran bindings, as it appears in C/C++ programs as well. It is also irrelevant to the operating system, as it appears in both Debian Linux 64-bit, and Windows 7 (32-bit) applications. I am using libVLC 2.1.2 (Rincewind).

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Replay sound after it is ended

Postby Jean-Baptiste Kempf » 11 Feb 2014 17:39

This is weird. Please share your logs.
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

Pap
New Cone
New Cone
Posts: 4
Joined: 23 Jan 2014 18:25

Re: Replay sound after it is ended

Postby Pap » 12 Feb 2014 22:50

The following simple program demonstrates the problem:

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; char ch; vlc_instance = libvlc_new(0, NULL); media = libvlc_media_new_path(vlc_instance,"sample.ogg"); player = libvlc_media_player_new_from_media(media); libvlc_media_release(media); libvlc_media_player_play(player); // Play the sound. std::cin>>ch; // This is to delay program execution until the sound is "ended". std::cout<<"Media player state: "<<libvlc_media_player_get_state(player) <<std::endl; // libvlc_media_player_stop(player); libvlc_media_player_play(player); // Try to replay the sound. std::cin>>ch; libvlc_media_player_release(player); libvlc_release(vlc_instance); return 0; }
The media player is played normally with the first call of libvlc_media_player_play(), while the program is waiting for a character to be entered by the user (with std::cin>>ch). I wait for the sound to be played, then I enter a character to continue. The call of libvlc_media_player_get_state() is there to ensure the sound is "ended". Indeed, reported state is 6, which, according to libvlc_state_t documentation, corresponds to "ENDED". Now, the second call of libvlc_media_player_play() produces no sound at all. The only way to hear the sound again is to uncomment the call of libvlc_media_player_stop() in the above code. So, it seems I cannot replay a media player, even if it's ended, unless I stop the media player first. This is weird, and I think I might be missing something important here.

Note that I have similar issues with other functions such as libvlc_audio_set_volume() and libvlc_audio_set_channel(), which won't work as expected. For example, libvlc_audio_set_volume() doesn't change the volume unless I stop the media player first.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 22 guests