diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..a92057f --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/PrimaryFormParts/PrimaryForm.cs b/PrimaryFormParts/PrimaryForm.cs index c8e7b8a..ddf8e82 100644 --- a/PrimaryFormParts/PrimaryForm.cs +++ b/PrimaryFormParts/PrimaryForm.cs @@ -55,7 +55,7 @@ namespace DualScreenDemo private Button musicDownButton; private Button micUpButton; private Button micDownButton; - private Button originalSongButton; + public Button originalSongButton; private Button replayButton; public Button pauseButton; public Button playButton; @@ -210,7 +210,7 @@ namespace DualScreenDemo private Timer autoRefreshTimer; private Timer timerCountdown; string Rtime; - bool test = true; + bool test = false; //private Label pageNumberLabel; // 添加頁碼標籤 public PrimaryForm() { diff --git a/Program.cs b/Program.cs index 92b7809..c3f7575 100644 --- a/Program.cs +++ b/Program.cs @@ -14,7 +14,7 @@ namespace DualScreenDemo private static PrimaryForm primaryForm; // 儲存實例的參考 public static Room room = new Room(); - public static string verSion = "Server V2.9 202508221643"; + public static string verSion = "Server V2.10 202508270919"; [STAThread] static void Main() diff --git a/Services/MediaService.cs b/Services/MediaService.cs index 497a9bc..f313c14 100644 --- a/Services/MediaService.cs +++ b/Services/MediaService.cs @@ -1,29 +1,9 @@ using System.IO; -using LibVLCSharp.Shared; +using DirectShowLib; +using LibVLCSharp; namespace DualScreenDemo.Services { - public static class ControlExtensions - { - public static Task InvokeAsync(this Control control, Func func) - { - var tcs = new TaskCompletionSource(); - control.BeginInvoke(new Action(async () => - { - try - { - await func(); - tcs.SetResult(null); - } - catch (Exception ex) - { - tcs.SetException(ex); - } - })); - return tcs.Task; - } - } - public class MediaService : IDisposable { private LibVLC _libVLC; @@ -36,7 +16,7 @@ namespace DualScreenDemo.Services Core.Initialize(); _libVLC = new LibVLC( // "--verbose=-1", - enableDebugLogs: true, + // enableDebugLogs: true, "--audio-time-stretch", "--vout=automatic", "--h264-fps=30", @@ -46,10 +26,10 @@ namespace DualScreenDemo.Services "--audio-time-stretch" ); - _libVLC.Log += (sender, args) => - { - Console.WriteLine($"[{args.Level}] {args.Message}"); - }; + // _libVLC.Log += (sender, args) => + // { + // Console.WriteLine($"[{args.Level}] {args.Message}"); + // }; _mediaPlayer = new MediaPlayer(_libVLC); _mediaPlayer.AspectRatio = "16:9"; @@ -80,7 +60,7 @@ namespace DualScreenDemo.Services public bool IsAtEnd() { - if (_mediaPlayer.State == VLCState.Ended) + if (_mediaPlayer.State == VLCState.Stopped) { return true; } @@ -97,40 +77,17 @@ namespace DualScreenDemo.Services private bool _isTransitioning = false; - - public void LoadMedia(string filePath, int audioTrackIndex = 0) { try { - // _mediaPlayer.Stop(); + _mediaPlayer.Stop(); _media?.Dispose(); - _media = new Media(_libVLC, filePath, FromType.FromPath); + _media = new Media(filePath, FromType.FromPath); _mediaPlayer.Play(addMediaOption(_media, audioTrackIndex)); - _mediaPlayer.Stopped += (s, e) => Console.WriteLine("Player Stopped"); - - // _mediaPlayer.EndReached += async(s, e) => - // { - // if (_isTransitioning) return; - // _isTransitioning = true; - - // try - // { - // await VideoPlayerForm.Instance.InvokeAsync(async () => - // { - // await VideoPlayerForm.Instance.PlayNextSong(); - // await Task.Delay(2000); // Optional delay - // }); - // } - // catch (Exception ex) - // { - // Console.WriteLine($"Error during transition: {ex.Message}"); - // } - // finally - // { - // _isTransitioning = false; - // } - // }; + _mediaPlayer.Fullscreen=true; + _mediaPlayer.Mute = false; + // _mediaPlayer.Stopped += (s, e) => Console.WriteLine("Player Stopped"); } catch (Exception ex) { @@ -142,11 +99,13 @@ namespace DualScreenDemo.Services private Media addMediaOption(Media media, int audioTrackIndex) { media.AddOption(":avcodec-hw=dxva2"); - media.AddOption($":drop-late-frames"); + media.AddOption(":drop-late-frames"); media.AddOption(":audio-output=directsound"); media.AddOption(":network-caching=300"); media.AddOption(":live-caching=300"); media.AddOption(":file-caching=300"); + media.AddOption(":clock-jitter=0"); + media.AddOption(":clock-synchro=0"); media.AddOption($":audio-track={audioTrackIndex}"); return media; } @@ -164,20 +123,20 @@ namespace DualScreenDemo.Services if (media == null) return result; - if (!media.IsParsed) - media.Parse(MediaParseOptions.ParseLocal); + //if (!media.IsParsed) + // media.Parse(MediaParseOptions.ParseLocal); - var tracks = media.Tracks; - if (tracks == null) return result; + //var tracks = media.Tracks; + // if (tracks == null) return result; - foreach (var track in tracks.Where(t => t.TrackType == TrackType.Audio)) - { - result.Add(new TrackDescription - { - Id = track.Id, - Name = !string.IsNullOrEmpty(track.Language) ? track.Language : $"Audio Track {track.Id}" - }); - } + // foreach (var track in tracks.Where(t => t.TrackType == TrackType.Audio)) + // { + // result.Add(new TrackDescription + // { + // Id = track.Id, + // Name = !string.IsNullOrEmpty(track.Language) ? track.Language : $"Audio Track {track.Id}" + // }); + // } return result; } @@ -185,12 +144,12 @@ namespace DualScreenDemo.Services { var audioTracks = GetAudioTracks(); if (trackIndex < 0 || trackIndex >= audioTracks.Count) return; - _mediaPlayer.SetAudioTrack(audioTracks[trackIndex].Id); + //_mediaPlayer.SetAudioTrack(audioTracks[trackIndex].Id); } #endregion #region Volume - public void SetVolume(int volume) => _mediaPlayer.Volume = volume; + public void SetVolume(int volume) => _mediaPlayer.SetVolume(volume); public int GetVolume() => _mediaPlayer.Volume; public bool Mute(bool isMuted) { diff --git a/VideoPlayerForm.cs b/VideoPlayerForm.cs index 6c48d57..f488c4a 100644 --- a/VideoPlayerForm.cs +++ b/VideoPlayerForm.cs @@ -2,7 +2,8 @@ using System.Runtime.InteropServices; using DBObj; using OverlayFormObj; using DualScreenDemo.Services; -using LibVLCSharp.WinForms; +using LibVLCSharp; + namespace DualScreenDemo { public class VideoPlayerForm : Form @@ -348,12 +349,23 @@ namespace DualScreenDemo { string pathToPlay = song.getFile(); _mediaService0.LoadMedia(pathToPlay, 0); + _mediaService0.Player.Media.AddOption(":no-audio"); + _mediaService0.Player.AspectRatio = "8:5"; + // _mediaService0.Player.Scale = 1.5f; _mediaService1.LoadMedia(pathToPlay, song.isPublicSong ? 0 : 1); - // Play(); - // Thread.Sleep(100); - // isVocalRemoved = true; - Mute(isMuted); + if (song.isPublicSong) + { + PrimaryForm.Instance.originalSongButton.Click -= PrimaryForm.Instance.OriginalSongButton_Click; + } + else + { + PrimaryForm.Instance.originalSongButton.Click -= PrimaryForm.Instance.OriginalSongButton_Click; + PrimaryForm.Instance.originalSongButton.Click += PrimaryForm.Instance.OriginalSongButton_Click; + } + isVocalRemoved = true; + if (isMuted) { Mute(true); } + // 音量處理 SetVolume(100 + song.getBasic().getDbChange()); Task.Run(() => Thread.Sleep(100)); @@ -361,17 +373,10 @@ namespace DualScreenDemo if (isSyncToPrimaryMonitor) SyncToPrimaryMonitor(); return Task.CompletedTask; } - catch (Exception ex) + catch (Exception ex) { Console.WriteLine(ex.Message); Program.WriteLog(ex.ToString()); - Stop(); - _mediaService0.Dispose(); - _mediaService1.Dispose(); - _mediaService0 = new MediaService(); - _mediaService1 = new MediaService(); - this.Invoke(VideoPlayerForm_Shown); - InitializeAndPlayMedia(song); return Task.CompletedTask; } @@ -493,12 +498,13 @@ namespace DualScreenDemo { if (isMuted) { - _mediaService0.Mute(true); + // _mediaService0.Mute(true); _mediaService1.Mute(true); } else { - _ToggleVocalRemoval(isVocalRemoved); + // _ToggleVocalRemoval(isVocalRemoved); + _mediaService1.Mute(false); } return isMuted; } @@ -512,19 +518,27 @@ namespace DualScreenDemo { return _mediaService1.GetVolume(); } + private bool isVocalRemoved = true; public void ToggleVocalRemoval() { - isVocalRemoved = _ToggleVocalRemoval(!isVocalRemoved); + if (isVocalRemoved) + { + + _mediaService1.Player.Select(TrackType.Audio, "audio/2"); + + isVocalRemoved = false; + } + else + { + _mediaService1.Player.Select(TrackType.Audio, "audio/1,audio/3"); + // _mediaService1.Player.Select(TrackType.Audio, "audio/3"); + isVocalRemoved = true; + } + // isVocalRemoved = _ToggleVocalRemoval(!isVocalRemoved); OverlayForm.MainForm.ShowTopRightLabelTime(isVocalRemoved ? "無人聲" : "有人聲"); } - private bool _ToggleVocalRemoval(bool isVocal) - { - - _mediaService0.Mute(isVocal); - _mediaService1.Mute(!isVocal); - return isVocal; - } + } } diff --git a/superstar.csproj b/superstar.csproj index 9aaf71c..fce19fc 100644 --- a/superstar.csproj +++ b/superstar.csproj @@ -13,15 +13,16 @@ app.manifest true CS8618,CS8602,CS8622,CS8625,CS8600,CS8603,CS8601,CS8604,CS4014 + AnyCPU - - + + - + diff --git a/superstar.csproj.user b/superstar.csproj.user new file mode 100644 index 0000000..31e6716 --- /dev/null +++ b/superstar.csproj.user @@ -0,0 +1,216 @@ + + + + + + Component + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Form + + + Component + + + Form + + + \ No newline at end of file