wpf ActiveX VLC 播放器事件不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14586257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ActiveX VLC Player events are not working
提问by Developer
I have incorporated ActiveX VLC pligin to WPF application.And VLC Plugin is working fine.
我已将ActiveX VLC pligin 合并到 WPF 应用程序中。并且 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();
But some how all events of VLC are not working at all.
但是有些 VLC 的所有事件根本不起作用。
I mean these events:
我的意思是这些事件:
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);
}
They are not firing. (Sure, I put breakpoints in those methods.)
他们没有开火。(当然,我在这些方法中放置了断点。)
What I really need is catch the streaming errors and re-apply videoURLanother time. So I am experimenting with events to see which of them I can use to reach that goal.
我真正需要的是捕捉流媒体错误并再次应用videoURL。所以我正在试验事件,看看我可以使用哪些事件来实现那个目标。
Any clue why is it?
任何线索为什么会这样?
P.S. This link doesn't help also VLC player event catch
PS 此链接也无助于VLC 播放器事件捕获
采纳答案by Onur Y?ld?r?m
I don't think you are doing anything wrong. It seems; those events are not implemented (or unimplemented) for some reason (even in the latest version of the activeX). I've readthat those events are either too buggy or not firing at all in some browser plugin versions too.
我不认为你做错了什么。它似乎; 由于某种原因(即使在最新版本的 activeX 中),这些事件没有实现(或未实现)。我已经读到这些事件在某些浏览器插件版本中要么太错误要么根本不触发。
However, it still has 3 useful and working events you can count on.
Events Firing:playEvent, pauseEventand stopEvent
Events Not Firing:all events starting with MediaPlayer...
但是,它仍然有 3 个您可以信赖的有用且有效的事件。
事件触发:playEvent,pauseEvent和stopEvent
事件不点火:所有事件开始MediaPlayer...
Anyway, code below works with the events I mentioned:
无论如何,下面的代码适用于我提到的事件:
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();
}
}
Still, these events will not inform you about any streaming errors. IMO, only thing you can do is; try-catch where you execute vlc.addTarget(...)and vlc.play(). Check whether the URL is valid beforehand (also don't forget to include "file:///"infront of the file path with the recent versions of the plugin). And re-apply the videoURL (as you like) only if the caught error is not about non-existing file or invalid path, etc.
尽管如此,这些事件不会通知您任何流媒体错误。IMO,你唯一能做的就是;try-catch 在哪里执行vlc.addTarget(...)和vlc.play(). 事先检查 URL 是否有效(也不要忘记"file:///"在文件路径的前面包含最新版本的插件)。仅当捕获的错误与不存在的文件或无效路径等有关时,才重新应用 videoURL(如您所愿)。
ORyou could try some other wrappers/custom libs:
或者您可以尝试一些其他包装器/自定义库:
回答by TBDK231
回答by John Willemse
Shouldn't it be something like this:
不应该是这样的:
vlc.MediaPlayerEncounteredError += new MediaPlayerEncounteredErrorEventHandler(vlc_MediaPlayerEncounteredError);


