diff --git a/OverlayFormObj/OverlayForm.cs b/OverlayFormObj/OverlayForm.cs index f3ac602..45946e5 100644 --- a/OverlayFormObj/OverlayForm.cs +++ b/OverlayFormObj/OverlayForm.cs @@ -1,6 +1,5 @@ using System.IO; using System.Timers; -using System.Diagnostics; using DBObj; using DualScreenDemo; namespace OverlayFormObj @@ -1516,14 +1515,11 @@ private void DisplayArtists(List artists, int page)//歌星點進去後 /* 秒數偵測BUG 測試 */ public void AddSongToPlaylist(SongData songData) { - Stopwatch stopwatch = new Stopwatch(); try { - stopwatch.Start(); var filePath1 = songData.SongFilePathHost1; var filePath2 = songData.SongFilePathHost2; - stopwatch.Stop(); - Console.WriteLine($"[1] 檢查路徑花費: {stopwatch.ElapsedMilliseconds} ms"); + if (!File.Exists(filePath1) && !File.Exists(filePath2)) { @@ -1532,44 +1528,26 @@ private void DisplayArtists(List artists, int page)//歌星點進去後 } else { - stopwatch.Restart(); var pathToPlay = File.Exists(filePath1) ? filePath1 : filePath2; - stopwatch.Stop(); - Console.WriteLine($"[2] 確定播放路徑花費: {stopwatch.ElapsedMilliseconds} ms"); bool wasEmpty = PrimaryForm.userRequestedSongs.Count == 0; - stopwatch.Restart(); PrimaryForm.userRequestedSongs.Add(songData); PrimaryForm.playedSongsHistory.Add(songData); PrimaryForm.playStates.Add(wasEmpty ? PlayState.Playing : PlayState.NotPlayed); - stopwatch.Stop(); - Console.WriteLine($"[3] 加入播放清單花費: {stopwatch.ElapsedMilliseconds} ms"); // 刷新頁面 - stopwatch.Restart(); if(PrimaryForm.Instance.multiPagePanel.get_currentSongList() == PrimaryForm.playedSongsHistory) PrimaryForm.Instance.multiPagePanel.LoadSongs(PrimaryForm.Instance.currentSongList); - stopwatch.Stop(); - Console.WriteLine($"[4] 更新歌曲面板花費: {stopwatch.ElapsedMilliseconds} ms"); if (wasEmpty) { - stopwatch.Restart(); VideoPlayerForm.Instance.SetPlayingSongList(PrimaryForm.userRequestedSongs); - PrimaryForm.currentSongIndexInHistory += 1; - stopwatch.Stop(); - Console.WriteLine($"[5] 設定播放列表花費: {stopwatch.ElapsedMilliseconds} ms"); + PrimaryForm.currentSongIndexInHistory += 1; } - stopwatch.Restart(); VideoPlayerForm.Instance.UpdateNextSongFromPlaylist(); PrimaryForm.PrintPlayingSongList(); - stopwatch.Stop(); - Console.WriteLine($"[6] 更新下一首與印出列表花費: {stopwatch.ElapsedMilliseconds} ms"); // 點播次數+1 - stopwatch.Restart(); PrimaryForm.Instance.AddSongCount(songData.SongNumber); - stopwatch.Stop(); - Console.WriteLine($"[7] 新增點播次數花費: {stopwatch.ElapsedMilliseconds} ms"); } } catch (Exception ex) diff --git a/VideoPlayerForm.cs b/VideoPlayerForm.cs index 0f1dd95..175ed16 100644 --- a/VideoPlayerForm.cs +++ b/VideoPlayerForm.cs @@ -1,7 +1,6 @@ using System.IO; // For StreamWriter using System.Runtime.InteropServices; using DirectShowLib; -using System.Diagnostics; using DBObj; using OverlayFormObj; namespace DualScreenDemo @@ -544,48 +543,33 @@ namespace DualScreenDemo { // [1] 輸出 debug 訊息,方便開發時追蹤是否有呼叫此方法 Console.WriteLine("SetPlayingSongList called"); - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); + // [2] 停止當前播放,釋放資源(例如關閉影片播放器、清除緩衝) StopAndReleaseResources(); - stopwatch.Stop(); - Console.WriteLine($"[5-2]停止當前播放,釋放資源,耗時{stopwatch.ElapsedMilliseconds}ms"); + // [3] 將新的播放清單指派給 `playingSongList` - stopwatch.Restart(); playingSongList = songList; - stopwatch.Stop(); - Console.WriteLine($"[5-3]將新的播放清單指派,耗時{stopwatch.ElapsedMilliseconds}ms"); + // [4] 根據是否有歌,設定旗標為是否播放使用者點播清單 - stopwatch.Restart(); isUserPlaylistPlaying = playingSongList != null && playingSongList.Any(); - stopwatch.Stop(); - Console.WriteLine($"[5-4]根據是否有歌,設定旗標為是否播放使用者點播清單,耗時{stopwatch.ElapsedMilliseconds}ms"); + // [5] 強制關閉公播狀態(意即現在進入點歌模式) - stopwatch.Restart(); IsPlayingPublicSong = false; - stopwatch.Stop(); - Console.WriteLine($"[5-5]強制關閉公播狀態,耗時{stopwatch.ElapsedMilliseconds}ms"); + // [6] 若使用者點播清單有歌,就開始播放 if (isUserPlaylistPlaying) { - stopwatch.Restart(); // [6.1] 設定當前歌曲索引為 -1(意味著即將播放第一首,從 `PlayNextSong` 開始) currentSongIndex = -1; // [6.2] 播放下一首歌(實際會遞增 index 為 0,並播放該首歌) await PlayNextSong(); - stopwatch.Stop(); - Console.WriteLine($"[5-6]播放下一首歌,耗時{stopwatch.ElapsedMilliseconds}ms"); } else { - stopwatch.Restart(); - // [7] 如果清單為空,回退播放預設的公播清單(通常是背景播放用) await InitializeAndPlayPublicPlaylist(); - stopwatch.Stop(); - Console.WriteLine($"[5-7]如果清單為空,回退播放預設的公播清單,耗時{stopwatch.ElapsedMilliseconds}ms"); } }