Ejemplo n.º 1
0
        protected static void ProcessCommandLine()
        {
            var           args  = Environment.GetCommandLineArgs().Skip(1);
            List <string> files = new List <string>();

            foreach (string i in args)
            {
                if (!i.StartsWith("--") && (i == "-" || i.Contains("://") || File.Exists(i)))
                {
                    files.Add(i);
                    if (i.Contains("://"))
                    {
                        RegHelp.SetObject(App.RegPath, "LastURL", i);
                    }
                }
            }

            Load(files.ToArray(), App.ProcessInstance != "queue", Control.ModifierKeys.HasFlag(Keys.Control));

            if (files.Count == 0)
            {
                VideoSizeAutoResetEvent.Set();
                VideoSizeChanged?.Invoke();
            }

            foreach (string i in args)
            {
                if (i.StartsWith("--"))
                {
                    try
                    {
                        if (i.Contains("="))
                        {
                            string left  = i.Substring(2, i.IndexOf("=") - 2);
                            string right = i.Substring(left.Length + 3);
                            set_property_string(left, right, true);
                        }
                        else
                        {
                            set_property_string(i.Substring(2), "yes", true);
                        }
                    }
                    catch (Exception e)
                    {
                        Msg.ShowException(e);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void EventLoop()
        {
            while (true)
            {
                IntPtr    ptr = mpv_wait_event(Handle, -1);
                mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event));

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

                // Debug.WriteLine(evt.event_id.ToString());

                try
                {
                    switch (evt.event_id)
                    {
                    case mpv_event_id.MPV_EVENT_SHUTDOWN:
                        if (App.DebugMode)
                        {
                            Trace.WriteLine("before Shutdown.Invoke");
                        }
                        Shutdown?.Invoke();
                        if (App.DebugMode)
                        {
                            Trace.WriteLine("after Shutdown.Invoke");
                        }
                        WriteHistory(null);
                        ShutdownAutoResetEvent.Set();
                        return;

                    case mpv_event_id.MPV_EVENT_LOG_MESSAGE:
                        LogMessage?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_GET_PROPERTY_REPLY:
                        GetPropertyReply?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_SET_PROPERTY_REPLY:
                        SetPropertyReply?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_COMMAND_REPLY:
                        CommandReply?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_START_FILE:
                        StartFile?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_END_FILE:
                        var end_fileData        = (mpv_event_end_file)Marshal.PtrToStructure(evt.data, typeof(mpv_event_end_file));
                        EndFileEventMode reason = (EndFileEventMode)end_fileData.reason;
                        EndFile?.Invoke(reason);
                        break;

                    case mpv_event_id.MPV_EVENT_FILE_LOADED:
                        HideLogo();
                        FileLoaded?.Invoke();
                        WriteHistory(get_property_string("path"));
                        break;

                    case mpv_event_id.MPV_EVENT_TRACKS_CHANGED:
                        TracksChanged?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_TRACK_SWITCHED:
                        TrackSwitched?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_IDLE:
                        Idle?.Invoke();
                        if (get_property_int("playlist-count") == 0)
                        {
                            ShowLogo();
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_PAUSE:
                        Pause?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_UNPAUSE:
                        Unpause?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_TICK:
                        Tick?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_SCRIPT_INPUT_DISPATCH:
                        ScriptInputDispatch?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_CLIENT_MESSAGE:
                        var      client_messageData = (mpv_event_client_message)Marshal.PtrToStructure(evt.data, typeof(mpv_event_client_message));
                        string[] args = NativeUtf8StrArray2ManagedStrArray(client_messageData.args, client_messageData.num_args);
                        if (args.Length > 1 && args[0] == "mpv.net")
                        {
                            Command.Execute(args[1], args.Skip(2).ToArray());
                        }
                        else if (args.Length > 0)
                        {
                            ClientMessage?.Invoke(args);
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_VIDEO_RECONFIG:
                        VideoReconfig?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_AUDIO_RECONFIG:
                        AudioReconfig?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_METADATA_UPDATE:
                        MetadataUpdate?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_SEEK:
                        Seek?.Invoke();
                        break;

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

                        if (propData.format == mpv_format.MPV_FORMAT_FLAG)
                        {
                            foreach (var i in BoolPropChangeActions)
                            {
                                if (i.Key == propData.name)
                                {
                                    i.Value.Invoke(Marshal.PtrToStructure <int>(propData.data) == 1);
                                }
                            }
                        }

                        if (propData.format == mpv_format.MPV_FORMAT_STRING)
                        {
                            foreach (var i in StringPropChangeActions)
                            {
                                if (i.Key == propData.name)
                                {
                                    i.Value.Invoke(StringFromNativeUtf8(Marshal.PtrToStructure <IntPtr>(propData.data)));
                                }
                            }
                        }

                        if (propData.format == mpv_format.MPV_FORMAT_INT64)
                        {
                            foreach (var i in IntPropChangeActions)
                            {
                                if (i.Key == propData.name)
                                {
                                    i.Value.Invoke(Marshal.PtrToStructure <int>(propData.data));
                                }
                            }
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_PLAYBACK_RESTART:
                        PlaybackRestart?.Invoke();
                        string path = get_property_string("path");
                        if (LastPlaybackRestartFile != path)
                        {
                            Size vidSize = new Size(get_property_int("dwidth"), get_property_int("dheight"));
                            if (vidSize.Width == 0 || vidSize.Height == 0)
                            {
                                vidSize = new Size(1, 1);
                            }
                            if (VideoSize != vidSize)
                            {
                                VideoSize = vidSize;
                                VideoSizeChanged?.Invoke();
                            }
                            VideoSizeAutoResetEvent.Set();
                            Task.Run(new Action(() => ReadMetaData()));
                            LastPlaybackRestartFile = path;
                        }
                        break;

                    case mpv_event_id.MPV_EVENT_CHAPTER_CHANGE:
                        ChapterChange?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_QUEUE_OVERFLOW:
                        QueueOverflow?.Invoke();
                        break;

                    case mpv_event_id.MPV_EVENT_HOOK:
                        Hook?.Invoke();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Msg.ShowException(ex);
                }
            }
        }