From cd25b63116265e54c9b18659ad4208c2bd0d60c0 Mon Sep 17 00:00:00 2001 From: jasonchenwork Date: Tue, 19 Aug 2025 09:34:10 +0800 Subject: [PATCH] 2508190933 --- Services/MediaService.cs | 88 +++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 8a31625..11f84ea 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -13,11 +13,14 @@ namespace DualScreenDemo.Services { Core.Initialize(); _libVLC = new LibVLC( + + "--vout=automatic", + "--h264-fps=25", "--aout=directsound", - "--network-caching=300", - "--file-caching=300", + "--network-caching=250", + "--file-caching=250", "--audio-time-stretch" - + ); _mediaPlayer = new MediaPlayer(_libVLC); @@ -26,9 +29,17 @@ namespace DualScreenDemo.Services #region Player Setup public void SetVideoOutput(nint handle, int width, int height) { - _mediaPlayer.Hwnd = handle; - _mediaPlayer.AspectRatio = $"{width}:{height}"; - _mediaPlayer.Scale = 0; + try + { + _mediaPlayer.Hwnd = handle; + _mediaPlayer.AspectRatio = $"{width}:{height}"; + _mediaPlayer.Scale = 0; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } #endregion @@ -38,20 +49,67 @@ namespace DualScreenDemo.Services public bool IsAtEnd() { - var duration = _mediaPlayer.Media?.Duration ?? 0; - var time = _mediaPlayer.Time; - return duration > 0 && Math.Abs(duration - time) < 1000; + try + { + var duration = _mediaPlayer.Media?.Duration ?? 0; + var time = _mediaPlayer.Time; + return duration > 0 && Math.Abs(duration - time) < 1000; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return true; + } } + // public void LoadMedia(string filePath, int audioTrackIndex = 0) + // { + // try + // { + // Console.WriteLine($"LoadMedia. in"); + // _media?.ParseStop(); + // Console.WriteLine($"LoadMedia. ParseStop"); + // _mediaPlayer.Stop(); + // Console.WriteLine($"LoadMedia. Stop"); + // _media?.Dispose(); + // Console.WriteLine($"LoadMedia. Dispose"); + + // _media = new Media(_libVLC, filePath, FromType.FromPath); + // _media.AddOption(":audio-output=directsound"); + // _media.AddOption($":audio-track={audioTrackIndex}"); + // _mediaPlayer.Play(_media); + + // } + // catch (Exception ex) + // { + // Console.WriteLine(ex.Message); + // } + + // } + public void LoadMedia(string filePath, int audioTrackIndex = 0) { - _mediaPlayer.Stop(); - _media?.Dispose(); + try + { + Console.WriteLine($"LoadMedia. in"); + _mediaPlayer.Stop(); + _mediaPlayer.Media = null; + Console.WriteLine($"LoadMedia. Stop"); + _media?.Dispose(); + _media= null; + Console.WriteLine($"LoadMedia. Dispose"); + + _media = new Media(_libVLC, filePath, FromType.FromPath); + _media.AddOption(":audio-output=directsound"); + _media.AddOption($":audio-track={audioTrackIndex}"); + _mediaPlayer.Play(_media); + + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } - _media = new Media(_libVLC, filePath, FromType.FromPath); - _media.AddOption(":audio-output=directsound"); - _media.AddOption($":audio-track={audioTrackIndex}"); - _mediaPlayer.Play(_media); } public void Play() => _mediaPlayer.Play();