コード例 #1
0
        public new void Load(string path)
        {
            if (_player == null)
            {
                var    assembly = Assembly.GetEntryAssembly();
                string appDir   = System.IO.Path.GetDirectoryName(assembly.Location);
                string dllPath  = $@"{appDir}\lib\mpv-1.dll";

                //单元测试
                _player = new Mpv.NET.Player.MpvPlayer(Handle, dllPath)
                {
                    Loop   = true,
                    Volume = 0
                };
                //防止视频黑边
                _player.API.SetPropertyString("panscan", "1.0");
                _player.AutoPlay = true;
                Load(_lastPath);
            }

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            _lastPath = path;

            _player?.Pause();
            _player?.Load(path);
            _player?.Resume();
        }
コード例 #2
0
 public void DiposePlayer()
 {
     Invoke(new Action(() =>
     {
         _player?.Dispose();
         _player = null;
     }));
 }
コード例 #3
0
 public void Dispose()
 {
     if (_player != null)
     {
         _player.PositionChanged -= _player_PositionChanged;
         _player.Stop();
         _player.Dispose();
         _player = null;
     }
 }
コード例 #4
0
        public new void Load(string path)
        {
            if (_player == null)
            {
                var    assembly = Assembly.GetEntryAssembly();
                string appDir   = System.IO.Path.GetDirectoryName(assembly.Location);
                string dllPath  = $@"{appDir}\lib\mpv-1.dll";
                if (IntPtr.Size == 4)
                {
                    // 32-bit
                }
                else if (IntPtr.Size == 8)
                {
                    // 64-bit
                    dllPath = $@"{appDir}\lib\mpv-1-x64.dll";
                }
                this.InvokeIfRequired(() =>
                {
                    //单元测试
                    _player = new Mpv.NET.Player.MpvPlayer(Handle, dllPath)
                    {
                        Loop   = true,
                        Volume = 0
                    };
                    //防止视频黑边
                    _player.API.SetPropertyString("panscan", "1.0");
                    _player.AutoPlay = true;
                    _player.Volume   = _volume;
                    //Load(_lastPath);
                });
            }

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            try
            {
                System.Diagnostics.Debug.WriteLine("load video 0");
                //_lastPath = path;
                // 设置解码模式为自动,如果条件允许,MPV会启动硬件解码
                _player?.API.SetPropertyString("hwdec", "auto");
                //_player.API.SetProperty("hwdec",Encoding.Default.GetBytes("auto"));
                _player?.Pause();
                _player?.Load(path);
                _player?.Resume();
            }
            catch (Exception ex)
            {
            }
            finally
            {
                System.Diagnostics.Debug.WriteLine("load video 1");
            }
        }
コード例 #5
0
 private void MpvPlayer_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         _player                  = new NET.Player.MpvPlayer(Display.DisplayHandle);
         _player.AutoPlay         = false;
         _player.PositionChanged += _player_PositionChanged;
     }
     catch (NET.Player.MpvPlayerException)
     {
         _player = null;
     }
 }
コード例 #6
0
 private void MpvPlayer_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         _player                  = new NET.Player.MpvPlayer(Display.DisplayHandle);
         _player.AutoPlay         = true;
         _player.PositionChanged += _player_PositionChanged;
         _player.MediaUnloaded   += WhenUnloaded;
         cont.ebool               = true;
     }
     catch (NET.Player.MpvPlayerException)
     {
         _player = null;
     }
 }
コード例 #7
0
ファイル: MpvControl.cs プロジェクト: csuffyy/LiveWallpaper
        public void Play(string path)
        {
            if (_player == null)
            {
                var    assembly = Assembly.GetEntryAssembly();
                string appDir   = System.IO.Path.GetDirectoryName(assembly.Location);
                string dllPath  = $@"{appDir}\lib\mpv-1.dll";
                if (IntPtr.Size == 4)
                {
                    // 32-bit
                }
                else if (IntPtr.Size == 8)
                {
                    // 64-bit
                    dllPath = $@"{appDir}\lib\mpv-1-x64.dll";
                }
                Util.InvokeIfRequired(() =>
                {
                    _player = new Mpv.NET.Player.MpvPlayer(Handle, dllPath)
                    {
                        Loop   = true,
                        Volume = 0
                    };

                    _player.AutoPlay = true;
                    //Play(_lastPath);
                });
            }

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            //_lastPath = path;

            //防止视频黑边
            _player.API.SetPropertyString("panscan", "1.0");
            // 设置解码模式为自动,如果条件允许,MPV会启动硬件解码
            _player?.API.SetPropertyString("hwdec", "auto");
            //允许休眠
            _player?.API.SetPropertyString("stop-screensaver", "no");
            _player.Volume = _volume;

            //_player?.Pause();
            _player?.Load(path);
            //_player?.Resume();
        }
コード例 #8
0
        public new void Load(string path)
        {
            if (_player == null)
            {
                var    assembly = Assembly.GetEntryAssembly();
                string appDir   = System.IO.Path.GetDirectoryName(assembly.Location);
                string dllPath  = $@"{appDir}\lib\mpv-1.dll";
                if (IntPtr.Size == 4)
                {
                    // 32-bit
                }
                else if (IntPtr.Size == 8)
                {
                    // 64-bit
                    dllPath = $@"{appDir}\lib\mpv-1-x64.dll";
                }
                this.InvokeIfRequired(() =>
                {
                    //单元测试
                    _player = new Mpv.NET.Player.MpvPlayer(Handle, dllPath)
                    {
                        Loop   = true,
                        Volume = 0
                    };
                    //防止视频黑边
                    _player.API.SetPropertyString("panscan", "1.0");
                    _player.AutoPlay = true;
                    _player.Volume   = _volume;
                    Load(_lastPath);
                });
            }

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            _lastPath = path;

            _player?.Pause();
            _player?.Load(path);
            _player?.Resume();
        }
コード例 #9
0
        private void InitPlayer()
        {
            BeginInvoke(new Action(() =>
            {
                var assembly   = Assembly.GetEntryAssembly();
                string appDir  = System.IO.Path.GetDirectoryName(assembly.Location);
                string dllPath = $@"{appDir}\lib\mpv-1.dll";

                //单元测试
                _player = new Mpv.NET.Player.MpvPlayer(Handle, dllPath)
                {
                    Loop   = true,
                    Volume = 0
                };
                //防止视频黑边
                _player.API.SetPropertyString("panscan", "1.0");
                _player.AutoPlay = true;
                LoadFile(_lastPath);
            }));
        }
コード例 #10
0
 private void RenderForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     FormClosing -= RenderForm_FormClosing;
     _player?.Dispose();
     _player = null;
 }
コード例 #11
0
 public void DisposeRender()
 {
     // 不能释放,否则重新开启视频会崩溃
     //_player?.Dispose();
     _player = null;
 }
コード例 #12
0
ファイル: MpvControl.cs プロジェクト: qin-dadie/LiveWallpaper
 public void DisposePlayer()
 {
     _player?.Dispose();
     _player = null;
 }