ActiveX VLC Player events are not working

老子叫甜甜 提交于 2019-12-05 02:56:52
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 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:

Shouldn't it be something like this:

vlc.MediaPlayerEncounteredError += new MediaPlayerEncounteredErrorEventHandler(vlc_MediaPlayerEncounteredError);
TBDK231

Right Click on VLC from Design → Properties → Event (Thunder Icon) → Select axVLCPlugin21_MediaPlayerend at MediaPlayerEndReached.

See an image for more details:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!