I have incorporated ActiveX VLC pligin to WPF application. VLC 插件工作正常。
AxVLCPlugin vlc = new AxVLCPlugin();
vlc.MediaPlayerEncounteredError += vlc_MediaPlayerEncounteredError;
vlc.MediaPlayerOpening += vlc_MediaPlayerOpening;
vlc.MediaPlayerBuffering += vlc_MediaPlayerBuffering;
vlc.MediaPlayerEndReached += vlc_MediaPlayerEndReached;
//
// Other code
// like windowsFormsHost1.Child = vlc; and etc
vlc.addTarget(videoURL, null, AXVLC.VLCPlaylistMode.VLCPlayListReplace, 1);
vlc.play();
但是有些 VLC 的所有事件根本无法正常工作。
我指的是这些事件:
vlc.MediaPlayerEncounteredError += vlc_MediaPlayerEncounteredError;
vlc.MediaPlayerOpening += vlc_MediaPlayerOpening;
vlc.MediaPlayerBuffering += vlc_MediaPlayerBuffering;
vlc.MediaPlayerEndReached += vlc_MediaPlayerEndReached;
void vlc_MediaPlayerEndReached(object sender, EventArgs e)
{
Debug.WriteLine("[P] - StreamingVideo - END REACHED + " + DateTime.Now);
}
void vlc_MediaPlayerBuffering(object sender, DVLCEvents_MediaPlayerBufferingEvent e)
{
Debug.WriteLine("[P] - StreamingVideo - BUFFERING + " + DateTime.Now);
}
void vlc_MediaPlayerOpening(object sender, EventArgs e)
{
Debug.WriteLine("[P] - StreamingVideo - OPENING + " + DateTime.Now);
}
void vlc_MediaPlayerEncounteredError(object sender, EventArgs e)
{
Debug.WriteLine("[P] - StreamingVideo - ERROR + " + DateTime.Now);
}
他们没有开火。 (当然,我在这些方法中放置了断点。)
我真正需要的是捕获流式传输错误并再次应用 videoURL。所以我正在试验事件,看看我可以使用哪些事件来实现该目标。
有什么线索吗?
附言此链接也没有帮助 VLC player event catch
最佳答案
我不认为你做错了什么。它似乎;由于某些原因(即使在最新版本的 activeX 中),这些事件未实现(或未实现)。我有 read在某些浏览器插件版本中,这些事件要么错误太多,要么根本不触发。
但是,它仍然有 3 个有用且有效的事件,您可以信赖。
触发事件:playEvent
、pauseEvent
和stopEvent
未触发的事件:所有以 MediaPlayer
开头的事件...
无论如何,下面的代码适用于我提到的事件:
AxVLCPlugin vlc;
public MainWindow()
{
InitializeComponent();
vlc = new AxVLCPlugin();
windowsFormsHost1.Child = vlc;
vlc.pauseEvent += new EventHandler(vlc_pauseEvent);
vlc.playEvent += new EventHandler(vlc_playEvent);
vlc.stopEvent += new EventHandler(vlc_stopEvent);
}
void vlc_playEvent(object sender, EventArgs e)
{
Debug.WriteLine("playEvent fired!");
}
void vlc_pauseEvent(object sender, EventArgs e)
{
Debug.WriteLine("pauseEvent fired!");
}
void vlc_stopEvent(object sender, EventArgs e)
{
Debug.WriteLine("stopEvent fired!");
}
private void button1_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
if (ofd.FileName != "")
{
Debug.WriteLine(ofd.FileName);
vlc.addTarget("file:///" + ofd.FileName, null, AXVLC.VLCPlaylistMode.VLCPlayListReplaceAndGo, 0);
vlc.play();
}
}
不过,这些事件不会通知您任何流媒体错误。 IMO,你唯一能做的就是; try-catch 执行 vlc.addTarget(...)
和 vlc.play()
。事先检查 URL 是否有效(也不要忘记使用最新版本的插件在文件路径前面包含 "file:///"
)。并且仅当捕获的错误与不存在的文件或无效路径等无关时才重新应用视频 URL(如您所愿)。
或者您可以尝试一些其他包装器/自定义库:
关于c# - ActiveX VLC 播放器事件不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14586257/