我正在尝试让我的小程序播放歌曲,当后者到达结尾时从一首歌曲切换到另一首歌曲,以完成我正在使用 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");
}
这是我传递给回调函数的结构
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;
}
您不能从 VLC 事件处理程序内部回调 VLC。您必须在不同的线程中执行此操作。
我是一名优秀的程序员,十分优秀!