Esempio n. 1
0
        public static void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(MpvHandle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
                Debug.WriteLine(evt.event_id);

                if (MpvWindowHandle == IntPtr.Zero)
                {
                    MpvWindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
                }

                switch (evt.event_id)
                {
                case mpv_event_id.MPV_EVENT_SHUTDOWN:
                    Shutdown?.Invoke();
                    AfterShutdown?.Invoke();
                    return;

                case mpv_event_id.MPV_EVENT_FILE_LOADED:
                    FileLoaded?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                    PlaybackRestart?.Invoke();
                    var s = new Size(GetIntProp("dwidth"), GetIntProp("dheight"));

                    if (VideoSize != s)
                    {
                        VideoSize = s;
                        VideoSizeChanged?.Invoke();
                    }

                    break;

                case mpv_event_id.MPV_EVENT_CLIENT_MESSAGE:
                    if (ClientMessage != null)
                    {
                        var client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
                        ClientMessage?.Invoke(NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args));
                    }

                    break;

                case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
                    var eventData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));

                    if (eventData.format == mpv_format.MPV_FORMAT_FLAG)
                    {
                        foreach (var action in BoolPropChangeActions)
                        {
                            action.Invoke(Marshal.PtrToStructure <int>(eventData.data) == 1);
                        }
                    }

                    break;
                }
            }
        }
Esempio n. 2
0
        public void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(MpvHandle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
                Debug.WriteLine(evt.event_id);

                switch (evt.event_id)
                {
                case mpv_event_id.MPV_EVENT_SHUTDOWN:
                    Shutdown?.Invoke();
                    AfterShutdown?.Invoke();
                    return;

                case mpv_event_id.MPV_EVENT_FILE_LOADED:
                    FileLoaded?.Invoke();
                    break;

                case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                    PlaybackRestart?.Invoke();
                    var s = new Size(GetIntProp("dwidth"), GetIntProp("dheight"));


                    break;

                case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
                    var eventData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));

                    if (eventData.format == mpv_format.MPV_FORMAT_FLAG)
                    {
                        foreach (var action in BoolPropChangeActions)
                        {
                            action.Invoke(Marshal.PtrToStructure <int>(eventData.data) == 1);
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 3
0
        public static void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(MpvHandle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));
                Debug.WriteLine(evt.event_id);

                if (MpvWindowHandle == IntPtr.Zero)
                {
                    MpvWindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null);
                }

                switch (evt.event_id)
                {
                case mpv_event_id.MPV_EVENT_SHUTDOWN:
                    Shutdown?.Invoke();
                    AfterShutdown?.Invoke();
                    return;

                case mpv_event_id.MPV_EVENT_FILE_LOADED:
                    LoadFolder();
                    break;

                case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                    PlaybackRestart?.Invoke();

                    Size s = new Size(GetIntProp("dwidth", false), GetIntProp("dheight", false));

                    if (VideoSize != s && s != Size.Empty)
                    {
                        VideoSize = s;
                        VideoSizeChanged?.Invoke();
                    }

                    break;

                case mpv_event_id.MPV_EVENT_CLIENT_MESSAGE:
                    if (ClientMessage != null)
                    {
                        var client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
                        var args = NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args);

                        if (args != null && args.Length > 1 && args[0] == "mpv.net")
                        {
                            foreach (var i in mpvnet.Command.Commands)
                            {
                                if (args[1] == i.Name)
                                {
                                    try
                                    {
                                        i.Action(args.Skip(2).ToArray());
                                    }
                                    catch (Exception ex)
                                    {
                                        MsgError(ex.GetType().Name, ex.ToString());
                                    }
                                }
                            }
                        }

                        ClientMessage?.Invoke(args);
                    }

                    break;

                case mpv_event_id.MPV_EVENT_PROPERTY_CHANGE:
                    var eventData = (mpv_event_property)Marshal.PtrToStructure(evt.data, typeof(mpv_event_property));

                    if (eventData.format == mpv_format.MPV_FORMAT_FLAG)
                    {
                        foreach (var action in BoolPropChangeActions)
                        {
                            action.Invoke(Marshal.PtrToStructure <int>(eventData.data) == 1);
                        }
                    }
                    break;
                }
            }
        }