Question

I'm trying to make my little program that plays songs switching from one song to another when the latter reaches the end, to do the whole thing i'm using vlclib, the problem is, it seems to get stuck on media_player_set_media(), any advise??

Thanks in advance.

void on_media_end(const struct libvlc_event_t *event, void *data){
   libvlc_media_t **song;
   struct callback_data *cdata = (struct callback_data *) data;
   printf("Song ended\n");
   libvlc_media_player_t **mp =  cdata->mp;
   song = cdata->song;
   libvlc_media_player_set_media(*mp,*song);
   /* play the media_player */
   libvlc_media_player_play(*mp);
   printf("New Song should be playing\n");
}

that's the struct Im passing to the callback function

struct callback_data{
   libvlc_media_player_t **mp;
   libvlc_media_t **song;
}callback_data;

and that's the main

int main(int argc,char *argv[]){
   libvlc_instance_t * inst;
   libvlc_event_manager_t *evmanager;
   libvlc_media_player_t *mp;
   libvlc_media_t *song;
   libvlc_callback_t callback = on_media_end;
   struct callback_data *cdata = (struct callback_data*) malloc( sizeof(callback_data) );


   /* Load the VLC engine */
   inst = libvlc_new (0, NULL);

   /* Create a new list */
   song=libvlc_media_new_path(inst,"16.mp3");

   /* Create a media player playing environement */
   mp = libvlc_media_player_new(inst);

   /**callback data **/
   cdata->mp = ∓
   cdata->song = &song;

   /* Event Manager */
   evmanager = libvlc_media_player_event_manager(mp);
   libvlc_event_attach(evmanager, libvlc_MediaPlayerEndReached ,callback , (void *)cdata);


   /* set what to play */
   libvlc_media_player_set_media(mp,song);

   /* play the media_player */
   libvlc_media_player_play(mp);

   printf("Volume: %d\n",libvlc_audio_get_volume(mp));
   while(1);

   /* Stop playing */
   libvlc_media_player_stop(mp);

   /* Free the media_player */
   libvlc_media_player_release(mp);
   libvlc_media_release(song);
   libvlc_release(inst);

   return 0;
}
Was it helpful?

Solution

You are not allowed to call back in to VLC from inside a VLC event handler. You have to do it in a different thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top