Playback problems using C
Posted: 08 May 2009 20:26
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
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;
}