gpt4 book ai didi

c - 当 vlclib event_manager 通知我时在 vlclib 中播放下一首歌曲

转载 作者:太空宇宙 更新时间:2023-11-04 03:47:37 25 4
gpt4 key购买 nike

我正在尝试让我的小程序播放歌曲,当后者到达结尾时从一首歌曲切换到另一首歌曲,以完成我正在使用 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。您必须在不同的线程中执行此操作。

关于c - 当 vlclib event_manager 通知我时在 vlclib 中播放下一首歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23067040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com