当vlclib_event_manager通知我时,在vlclib中播放下一首歌

时间:2014-04-14 18:04:35

标签: c libvlc

我正在尝试制作我的小程序,播放从一首歌到另一首歌的歌曲,当后者到达终点时,为了完成整个我正在使用的vlclib,问题是,它似乎卡在了media_player_set_media (),任何建议??

提前致谢。

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");
}

这是结构Im传递给回调函数

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

那是主要的

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;
}

1 个答案:

答案 0 :(得分:1)

您不能从VLC事件处理程序内部回调到VLC。你必须在另一个线程中完成它。