Page 1 of 1

Playback problems using C

Posted: 08 May 2009 20:26
by hulud
Hi,
i'm facing some problems using libvlc with C.

Adding a media using "libvlc_media_list_add_media" and starting playback using "libvlc_media_list_player_play", when the media finish playing my program hangs if i try to play again.

I've compressed my code into this source to reproduce the problem:

after the first media the time fprintf stop displaying and the program hangs somewhere into the while...
do i have to handle some events? is something missing or wrong?

Andrea

Code: Select all

#include <stdio.h> #include <stdlib.h> #include <vlc/vlc.h> int is_exception_raised(libvlc_exception_t *exceptions) { if (libvlc_exception_raised(exceptions)) { printf("%s\n", libvlc_exception_get_message(exceptions)); libvlc_exception_clear(exceptions); return 1; } return 0; } int main(void) { libvlc_instance_t *handler = NULL; libvlc_exception_t exceptions; libvlc_media_list_t *medialist = NULL; libvlc_media_list_player_t *medialist_player = NULL; libvlc_media_player_t *player = NULL; const char * const vlc_args[] = { "-I", "dummy", /* Don't use any interface */ "--no-media-library", "--ignore-config"}; /* Don't use VLC's config */ libvlc_exception_init(&exceptions); /* init vlc modules, should be done only once */ handler = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args, &exceptions); if (handler == NULL) return 1; if (is_exception_raised(&exceptions)) return 1; // Playlist medialist = libvlc_media_list_new (handler, &exceptions); if (is_exception_raised(&exceptions)) return 1; if (medialist == NULL) return 1; // Player player = libvlc_media_player_new(handler, &exceptions); if (is_exception_raised(&exceptions)) return 1; if (player == NULL) return 1; // Playlist player medialist_player = libvlc_media_list_player_new (handler, &exceptions); if (is_exception_raised(&exceptions)) return 1; if (medialist_player == NULL) return 1; // Set Playlist player list & player libvlc_media_list_player_set_media_player(medialist_player, player, &exceptions); if (is_exception_raised(&exceptions)) return 1; libvlc_media_list_player_set_media_list(medialist_player, medialist, &exceptions); if (is_exception_raised(&exceptions)) return 1; // INIT DONE // ADD FIRST MEDIA libvlc_media_t *media = libvlc_media_new(handler, "/home/andrea/1.mpeg", &exceptions); if (is_exception_raised(&exceptions)) return 1; libvlc_media_list_add_media (medialist, media, &exceptions); if (is_exception_raised(&exceptions)) return 1; libvlc_media_list_player_set_media_list( medialist_player, medialist, &exceptions ); if (is_exception_raised(&exceptions)) return 1; // ADD SECOND MEDIA libvlc_media_t *media1 = libvlc_media_new(handler, "/home/andrea/2.mpeg", &exceptions); if (is_exception_raised(&exceptions)) return 1; libvlc_media_list_add_media (medialist, media1, &exceptions); if (is_exception_raised(&exceptions)) return 1; libvlc_media_list_player_set_media_list( medialist_player, medialist, &exceptions ); if (is_exception_raised(&exceptions)) return 1; // PLAY libvlc_media_list_player_play(medialist_player, &exceptions); if (is_exception_raised(&exceptions)) return 1; sleep(1); while (libvlc_media_list_player_is_playing(medialist_player, &exceptions)) { fprintf(stderr, "time: %d ", libvlc_media_player_get_time(player, &exceptions)); sleep (1); } // CLOSE // Close playlist libvlc_media_list_release(medialist); if (is_exception_raised(&exceptions)) return 1; // Close player libvlc_media_player_release(player); if (is_exception_raised(&exceptions)) return 1; libvlc_media_list_player_release(medialist_player); if (is_exception_raised(&exceptions)) return 1; // Close liblvc if (handler != NULL) libvlc_release(handler); if (is_exception_raised(&exceptions)) return 1; return 0; }

Re: Playback problems using C

Posted: 11 May 2009 20:39
by hulud
uhmm no hints? i noticed that also "libvlc_media_list_player_next" cause my program to freeze.

Re: Playback problems using C

Posted: 03 Jun 2009 20:39
by hulud
I'm trying to avoid using libvlc_media_list_player by using only media_list and caching endreached event:

Inside the callback i'm trying to:
1) get the next media
2) set the new media using libvlc_media_player_set_media

this cause the program to crash due to this error
[00000392] main input warning: joining the active thread (VLC might crash)
[00000392] main input debug: thread 2998487952 joined (control/media_player.c:100)
LibVLC fatal error destroying mutex in thread 2998487952 at misc/events.c:151: 16
Error message: Dispositivo o risorsa occupata at:
/usr/lib/libvlccore.so.0(vlc_pthread_fatal+0xb5)[0xb72628e5]
Aborted

so i'm trying to play all the medias using libvlc_media_player_new_from_media (thus creating a new media player for every media in my playlist) and this time seems to work, except that the previous media remains (a window with the last frame remains, do i have to force a stop?) and a new windows for media reproduction is opened.
Is this the correct behaviour or can i reuse the same media_player for all my playlist?

Re: Playback problems using C

Posted: 04 Jun 2009 18:51
by Rémi Denis-Courmont
Yes, this is a known bug that was fixed recently in the development version.

Re: Playback problems using C

Posted: 04 Jun 2009 19:16
by hulud
do you think it's safe for me to move to a development version of vlc? i got this work to complete in a few months...
or it's better wait for a stable release?

Re: Playback problems using C

Posted: 05 Jun 2009 15:54
by Rémi Denis-Courmont
That should be backported to 1.0 release. But it seems unlikely that 0.9 will ever be fixed in that regard.

Re: Playback problems using C

Posted: 05 Jun 2009 21:58
by hulud
looks like 1.0 version is going to be released soon right?

Re: Playback problems using C

Posted: 06 Jun 2009 01:10
by hulud
Whith the latest git version reusing the same player cause a freeze when i try to set the new media with "libvlc_media_player_set_media".
Any hints?

Re: Playback problems using C

Posted: 06 Jun 2009 16:05
by Rémi Denis-Courmont
You should rather post to vlc-devel for that sort of problems.

Re: Playback problems using C

Posted: 13 Jul 2009 02:24
by brain!ac
sory for going out of the discussion way but

im using libvlc from marx wraper on C# (because the original libvlc.dll could not open as reference on a c# project)

I want to display the playback-program menu as a tree on my API ,so please if somebody can tell me how it is possible to do it.
What i want to do is i can Open a TS IP Stream from an Reciever on DVB-S which contains many Services and i like to chose one service on the Program Tree than stream or transcode it on Mpeg4 .

Sory for my bad english ,i wish i was understandable .

Best on advance.