Exemplo n.º 1
0
        public void Initialize()
        {
            if (_mpvHandle != IntPtr.Zero)
            {
                _mpvTerminateDestroy(_mpvHandle);
            }

            string   fullexepath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            FileInfo fi          = new FileInfo(fullexepath);

            fullexepath           = Path.Combine(fi.Directory.FullName, Environment.Is64BitProcess ? "x64" : "x86", "mpv-1.dll");
            _libMpvDll            = LoadLibraryEx(fullexepath, IntPtr.Zero, 0);
            _mpvCreate            = (MpvCreate)GetDllType(typeof(MpvCreate), "mpv_create");
            _mpvInitialize        = (MpvInitialize)GetDllType(typeof(MpvInitialize), "mpv_initialize");
            _mpvTerminateDestroy  = (MpvTerminateDestroy)GetDllType(typeof(MpvTerminateDestroy), "mpv_terminate_destroy");
            _mpvCommand           = (MpvCommand)GetDllType(typeof(MpvCommand), "mpv_command");
            _mpvSetOption         = (MpvSetOption)GetDllType(typeof(MpvSetOption), "mpv_set_option");
            _mpvSetOptionString   = (MpvSetOptionString)GetDllType(typeof(MpvSetOptionString), "mpv_set_option_string");
            _mpvGetPropertyString = (MpvGetPropertystring)GetDllType(typeof(MpvGetPropertystring), "mpv_get_property");
            _mpvSetProperty       = (MpvSetProperty)GetDllType(typeof(MpvSetProperty), "mpv_set_property");
            _mpvFree = (MpvFree)GetDllType(typeof(MpvFree), "mpv_free");

            if (_libMpvDll == IntPtr.Zero)
            {
                return;
            }

            _mpvHandle = _mpvCreate.Invoke();
            if (_mpvHandle == IntPtr.Zero)
            {
                return;
            }

            _mpvInitialize.Invoke(_mpvHandle);
        }
Exemplo n.º 2
0
Arquivo: Form1.cs Projeto: niksedk/mpv
        private void buttonPlay_Click(object sender, EventArgs e)
        {
            if (_mpvHandle != IntPtr.Zero)
            {
                _mpvTerminateDestroy(_mpvHandle);
            }

            LoadMpvDynamic();
            if (_libMpvDll == IntPtr.Zero)
            {
                return;
            }

            _mpvHandle = _mpvCreate.Invoke();
            if (_mpvHandle == IntPtr.Zero)
            {
                return;
            }

            _mpvInitialize.Invoke(_mpvHandle);
            _mpvSetOptionString(_mpvHandle, Encoding.UTF8.GetBytes("vo\0"), Encoding.UTF8.GetBytes("direct3d\0"));
            _mpvSetOptionString(_mpvHandle, Encoding.UTF8.GetBytes("keep-open\0"), Encoding.UTF8.GetBytes("always\0"));
            int  mpvFormatInt64 = 4;
            uint windowId       = (uint)pictureBox1.Handle.ToInt64();

            _mpvSetOption(_mpvHandle, Encoding.UTF8.GetBytes("wid\0"), mpvFormatInt64, ref windowId);
            _mpvCommand(_mpvHandle, new[] { "loadfile", textBoxVideoSampleFileName.Text, null });
        }
Exemplo n.º 3
0
        private void buttonPlay_Click(object sender, EventArgs e)
        {
            if (_mpvHandle != IntPtr.Zero)
            {
                _mpvTerminateDestroy(_mpvHandle);
            }

            LoadMpvDynamic();
            if (_libMpvDll == IntPtr.Zero)
            {
                return;
            }

            _mpvHandle = _mpvCreate.Invoke();
            if (_mpvHandle == IntPtr.Zero)
            {
                return;
            }

            _mpvInitialize.Invoke(_mpvHandle);
            _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("keep-open"), GetUtf8Bytes("always"));
            int mpvFormatInt64 = 4;
            var windowId       = pictureBox1.Handle.ToInt64();

            _mpvSetOption(_mpvHandle, GetUtf8Bytes("wid"), mpvFormatInt64, ref windowId);
            DoMpvCommand("loadfile", textBoxVideoSampleFileName.Text);
        }
Exemplo n.º 4
0
        public override void Initialize(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded)
        {
            string dllFile = GetMpvPath("mpv-1.dll");

            if (File.Exists(dllFile))
            {
                if (_libMpvDll == IntPtr.Zero)
                {
                    _libMpvDll = NativeMethods.LoadLibrary(dllFile);
                }
                LoadLibVlcDynamic();
                if (!IsAllMethodsLoaded())
                {
                    throw new Exception("MPV - not all needed methods found in dll file");
                }
                _mpvHandle = _mpvCreate.Invoke();

#if DEBUG
                var logFileName = Path.Combine(Configuration.DataDirectory, "mpv-log-" + Guid.NewGuid() + ".txt");
                _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("log-file"), GetUtf8Bytes(logFileName));
#endif
            }
            else if (!Directory.Exists(videoFileName))
            {
                return;
            }

            OnVideoLoaded = onVideoLoaded;
            OnVideoEnded  = onVideoEnded;

            if (!string.IsNullOrEmpty(videoFileName))
            {
                _mpvInitialize.Invoke(_mpvHandle);
                SetVideoOwner(ownerControl);

                string videoOutput = "direct3d";
                if (!string.IsNullOrWhiteSpace(Configuration.Settings.General.MpvVideoOutput))
                {
                    videoOutput = Configuration.Settings.General.MpvVideoOutput;
                }
                _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("vo"), GetUtf8Bytes(videoOutput));     // use "direct3d" or "opengl"
                _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("keep-open"), GetUtf8Bytes("always")); // don't auto close video
                _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("no-sub"), GetUtf8Bytes(""));          // don't load subtitles
                if (videoFileName.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
                    videoFileName.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
                {
                    _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("ytdl"), GetUtf8Bytes("yes"));
                }
                DoMpvCommand("loadfile", videoFileName);

                _videoLoadedTimer = new Timer {
                    Interval = 50
                };
                _videoLoadedTimer.Tick += VideoLoadedTimer_Tick;
                _videoLoadedTimer.Start();

                SetVideoOwner(ownerControl);
            }
        }
Exemplo n.º 5
0
        public override void Initialize(Control ownerControl, string videoFileName, EventHandler onVideoLoaded, EventHandler onVideoEnded)
        {
            string dllFile = GetMpvPath("mpv-1.dll");

            if (File.Exists(dllFile))
            {
                var path = Path.GetDirectoryName(dllFile);
                if (path != null)
                {
                    Directory.SetCurrentDirectory(path);
                }
                _libMpvDll = NativeMethods.LoadLibrary(dllFile);
                LoadLibVlcDynamic();
                if (!IsAllMethodsLoaded())
                {
                    throw new Exception("MPV - not all needed methods found in dll file");
                }
                _mpvHandle = _mpvCreate.Invoke();
            }
            else if (!Directory.Exists(videoFileName))
            {
                return;
            }

            OnVideoLoaded = onVideoLoaded;
            OnVideoEnded  = onVideoEnded;

            if (!string.IsNullOrEmpty(videoFileName))
            {
                _mpvInitialize.Invoke(_mpvHandle);

                string videoOutput = "direct3d";
                if (!string.IsNullOrWhiteSpace(Configuration.Settings.General.MpvVideoOutput))
                {
                    videoOutput = Configuration.Settings.General.MpvVideoOutput;
                }
                _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("vo"), GetUtf8Bytes(videoOutput));     // use "direct3d" or "opengl"

                _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("keep-open"), GetUtf8Bytes("always")); // don't auto close video
                _mpvSetOptionString(_mpvHandle, GetUtf8Bytes("no-sub"), GetUtf8Bytes(""));          // don't load subtitles
                if (ownerControl != null)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        Application.DoEvents();
                        int mpvFormatInt64 = 4;
                        var windowId       = ownerControl.Handle.ToInt64();
                        _mpvSetOption(_mpvHandle, GetUtf8Bytes("wid"), mpvFormatInt64, ref windowId);
                    }
                }
                DoMpvCommand("loadfile", videoFileName);

                _videoLoadedTimer = new Timer {
                    Interval = 50
                };
                _videoLoadedTimer.Tick += VideoLoadedTimer_Tick;
                _videoLoadedTimer.Start();
            }
        }
Exemplo n.º 6
0
        internal void Initialize(Visual visual)
        {
            if (_mpvHandle != IntPtr.Zero)
            {
                _mpvTerminateDestroy(_mpvHandle);
            }

            string   fullexepath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            FileInfo fi          = new FileInfo(fullexepath);

            // ReSharper disable once PossibleNullReferenceException
            fullexepath           = Path.Combine(fi.Directory.FullName, Environment.Is64BitProcess ? "x64" : "x86", "mpv-1.dll");
            _libMpvDll            = LoadLibraryEx(fullexepath, IntPtr.Zero, 0);
            _mpvCreate            = (MpvCreate)GetDllType(typeof(MpvCreate), "mpv_create");
            _mpvInitialize        = (MpvInitialize)GetDllType(typeof(MpvInitialize), "mpv_initialize");
            _mpvTerminateDestroy  = (MpvTerminateDestroy)GetDllType(typeof(MpvTerminateDestroy), "mpv_terminate_destroy");
            _mpvCommand           = (MpvCommand)GetDllType(typeof(MpvCommand), "mpv_command");
            _mpvSetOption         = (MpvSetOption)GetDllType(typeof(MpvSetOption), "mpv_set_option");
            _mpvSetOptionString   = (MpvSetOptionString)GetDllType(typeof(MpvSetOptionString), "mpv_set_option_string");
            _mpvGetPropertyString = (MpvGetPropertystring)GetDllType(typeof(MpvGetPropertystring), "mpv_get_property");
            _mpvSetProperty       = (MpvSetProperty)GetDllType(typeof(MpvSetProperty), "mpv_set_property");
            _mpvFree = (MpvFree)GetDllType(typeof(MpvFree), "mpv_free");

            /*
             * _mpvLoadConfigFile = (MpvLoadConfigFile)GetDllType(typeof(MpvLoadConfigFile), "mpv_load_config_file");
             * _mpvRequestLogMessages = (MpvRequestLogMessages) GetDllType(typeof(MpvRequestLogMessages), "mpv_request_log_messages");
             * _mpvRequestEvent = (MpvRequestEvent)GetDllType(typeof(MpvRequestEvent), "mpv_request_event");
             * _mpvWaitEvent = (MpvWaitEvent)GetDllType(typeof(MpvWaitEvent), "mpv_wait_event");
             */
            if (_libMpvDll == IntPtr.Zero)
            {
                return;
            }

            _mpvHandle = _mpvCreate.Invoke();
            if (_mpvHandle == IntPtr.Zero)
            {
                return;
            }

            _mpvInitialize.Invoke(_mpvHandle);
            SetWindowsHandle(visual);
        }