libvlc - 无法从回调调用函数

libvlc - 无法从回调调用函数

问题描述:

我正在编写一个GTK/VLC程序。作为普通媒体播放器,我的程序应该采取行动如下:libvlc - 无法从回调调用函数

  1. playlist(使用GtkTreeView实现)双击使player播放所选的媒体(使用libvlc_media_player实现)。
  2. 达到媒体结束时,player引发事件。此事件被用来调用一个例程:
    • playlist
    • 搜索下一个媒体g_signal_emit功能是用来模拟在播放列表中双击事件,以选择下一个媒体。

的问题是,player的功能“玩”不能由player本身回调的同一个线程调用。

我该如何摆脱这个混乱?

**添加** vlc信号似乎是异步的,而gtk的信号不同步。有没有办法异步发射gtk的事件?

你必须启动另一个线程(或发送消息到另一个线程)并在那里运行命令。这是libvlc中回调的众所周知的问题。

这就是我做的:

void player::libvlc_event(const struct libvlc_event_t* event) 
{ 
    //come from another thread 
    if(libvlc_MediaPlayerEndReached == event->type || 
     libvlc_MediaPlayerEncounteredError == event->type) 
    { 
     if(mode_single != get_playback_mode()) { 
      //to avoid deadlock we should execute commands on another thread 
      std::thread th(&player::next, this); 
      th.detach(); 
     } 
    } 
}