ActiveX VLC Player events are not working
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 read that those events are either too buggy or not firing at all in some browser plugin versions too.
However, it still has 3 useful and working events you can count on.
Events Firing: playEvent
, pauseEvent
and stopEvent
Events Not Firing: all events starting with 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.
OR you could try some other wrappers/custom libs:
- VLC DotNet for WinForm & WPF
- More at this page