點歌卡頓移出delay
This commit is contained in:
parent
d49a99822e
commit
6970933aee
@ -1,5 +1,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
using System.Diagnostics;
|
||||||
using DBObj;
|
using DBObj;
|
||||||
using DualScreenDemo;
|
using DualScreenDemo;
|
||||||
namespace OverlayFormObj
|
namespace OverlayFormObj
|
||||||
@ -1512,14 +1513,18 @@ private void DisplayArtists(List<Artist> artists, int page)//歌星點進去後
|
|||||||
ClearDisplay();
|
ClearDisplay();
|
||||||
DisplaySongs(currentPage);
|
DisplaySongs(currentPage);
|
||||||
}
|
}
|
||||||
|
/* 秒數偵測BUG 測試 */
|
||||||
public void AddSongToPlaylist(SongData songData)
|
public void AddSongToPlaylist(SongData songData)
|
||||||
{
|
{
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
stopwatch.Start();
|
||||||
var filePath1 = songData.SongFilePathHost1;
|
var filePath1 = songData.SongFilePathHost1;
|
||||||
var filePath2 = songData.SongFilePathHost2;
|
var filePath2 = songData.SongFilePathHost2;
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[1] 檢查路徑花費: {stopwatch.ElapsedMilliseconds} ms");
|
||||||
|
|
||||||
if (!File.Exists(filePath1) && !File.Exists(filePath2))
|
if (!File.Exists(filePath1) && !File.Exists(filePath2))
|
||||||
{
|
{
|
||||||
// 點播失敗時,寫LOG至logfile.txt
|
// 點播失敗時,寫LOG至logfile.txt
|
||||||
@ -1527,24 +1532,38 @@ private void DisplayArtists(List<Artist> artists, int page)//歌星點進去後
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
stopwatch.Restart();
|
||||||
var pathToPlay = File.Exists(filePath1) ? filePath1 : filePath2;
|
var pathToPlay = File.Exists(filePath1) ? filePath1 : filePath2;
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[2] 確定播放路徑花費: {stopwatch.ElapsedMilliseconds} ms");
|
||||||
bool wasEmpty = PrimaryForm.userRequestedSongs.Count == 0;
|
bool wasEmpty = PrimaryForm.userRequestedSongs.Count == 0;
|
||||||
|
|
||||||
|
stopwatch.Restart();
|
||||||
PrimaryForm.userRequestedSongs.Add(songData);
|
PrimaryForm.userRequestedSongs.Add(songData);
|
||||||
PrimaryForm.playedSongsHistory.Add(songData);
|
PrimaryForm.playedSongsHistory.Add(songData);
|
||||||
PrimaryForm.playStates.Add(wasEmpty ? PlayState.Playing : PlayState.NotPlayed);
|
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)
|
if(PrimaryForm.Instance.multiPagePanel.get_currentSongList() == PrimaryForm.playedSongsHistory)
|
||||||
PrimaryForm.Instance.multiPagePanel.LoadSongs(PrimaryForm.Instance.currentSongList);
|
PrimaryForm.Instance.multiPagePanel.LoadSongs(PrimaryForm.Instance.currentSongList);
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[4] 更新歌曲面板花費: {stopwatch.ElapsedMilliseconds} ms");
|
||||||
if (wasEmpty)
|
if (wasEmpty)
|
||||||
{
|
{
|
||||||
|
stopwatch.Restart();
|
||||||
VideoPlayerForm.Instance.SetPlayingSongList(PrimaryForm.userRequestedSongs);
|
VideoPlayerForm.Instance.SetPlayingSongList(PrimaryForm.userRequestedSongs);
|
||||||
PrimaryForm.currentSongIndexInHistory += 1;
|
PrimaryForm.currentSongIndexInHistory += 1;
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[5] 設定播放列表花費: {stopwatch.ElapsedMilliseconds} ms");
|
||||||
}
|
}
|
||||||
|
stopwatch.Restart();
|
||||||
VideoPlayerForm.Instance.UpdateNextSongFromPlaylist();
|
VideoPlayerForm.Instance.UpdateNextSongFromPlaylist();
|
||||||
PrimaryForm.PrintPlayingSongList();
|
PrimaryForm.PrintPlayingSongList();
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[6] 更新下一首與印出列表花費: {stopwatch.ElapsedMilliseconds} ms");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System.IO; // For StreamWriter
|
using System.IO; // For StreamWriter
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using DirectShowLib;
|
using DirectShowLib;
|
||||||
|
using System.Diagnostics;
|
||||||
using DBObj;
|
using DBObj;
|
||||||
using OverlayFormObj;
|
using OverlayFormObj;
|
||||||
namespace DualScreenDemo
|
namespace DualScreenDemo
|
||||||
@ -519,32 +520,48 @@ namespace DualScreenDemo
|
|||||||
{
|
{
|
||||||
// [1] 輸出 debug 訊息,方便開發時追蹤是否有呼叫此方法
|
// [1] 輸出 debug 訊息,方便開發時追蹤是否有呼叫此方法
|
||||||
Console.WriteLine("SetPlayingSongList called");
|
Console.WriteLine("SetPlayingSongList called");
|
||||||
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
stopwatch.Start();
|
||||||
// [2] 停止當前播放,釋放資源(例如關閉影片播放器、清除緩衝)
|
// [2] 停止當前播放,釋放資源(例如關閉影片播放器、清除緩衝)
|
||||||
StopAndReleaseResources();
|
StopAndReleaseResources();
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[5-2]停止當前播放,釋放資源,耗時{stopwatch.ElapsedMilliseconds}ms");
|
||||||
|
|
||||||
// [3] 將新的播放清單指派給 `playingSongList`
|
// [3] 將新的播放清單指派給 `playingSongList`
|
||||||
|
stopwatch.Restart();
|
||||||
playingSongList = songList;
|
playingSongList = songList;
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[5-3]將新的播放清單指派,耗時{stopwatch.ElapsedMilliseconds}ms");
|
||||||
|
|
||||||
// [4] 根據是否有歌,設定旗標為是否播放使用者點播清單
|
// [4] 根據是否有歌,設定旗標為是否播放使用者點播清單
|
||||||
|
stopwatch.Restart();
|
||||||
isUserPlaylistPlaying = playingSongList != null && playingSongList.Any();
|
isUserPlaylistPlaying = playingSongList != null && playingSongList.Any();
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[5-4]根據是否有歌,設定旗標為是否播放使用者點播清單,耗時{stopwatch.ElapsedMilliseconds}ms");
|
||||||
|
|
||||||
// [5] 強制關閉公播狀態(意即現在進入點歌模式)
|
// [5] 強制關閉公播狀態(意即現在進入點歌模式)
|
||||||
|
stopwatch.Restart();
|
||||||
IsPlayingPublicSong = false;
|
IsPlayingPublicSong = false;
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[5-5]強制關閉公播狀態,耗時{stopwatch.ElapsedMilliseconds}ms");
|
||||||
// [6] 若使用者點播清單有歌,就開始播放
|
// [6] 若使用者點播清單有歌,就開始播放
|
||||||
if (isUserPlaylistPlaying)
|
if (isUserPlaylistPlaying)
|
||||||
{
|
{
|
||||||
|
stopwatch.Restart();
|
||||||
// [6.1] 設定當前歌曲索引為 -1(意味著即將播放第一首,從 `PlayNextSong` 開始)
|
// [6.1] 設定當前歌曲索引為 -1(意味著即將播放第一首,從 `PlayNextSong` 開始)
|
||||||
currentSongIndex = -1;
|
currentSongIndex = -1;
|
||||||
|
|
||||||
// [6.2] 播放下一首歌(實際會遞增 index 為 0,並播放該首歌)
|
// [6.2] 播放下一首歌(實際會遞增 index 為 0,並播放該首歌)
|
||||||
await PlayNextSong();
|
await PlayNextSong();
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[5-6]播放下一首歌,耗時{stopwatch.ElapsedMilliseconds}ms");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
stopwatch.Restart();
|
||||||
// [7] 如果清單為空,回退播放預設的公播清單(通常是背景播放用)
|
// [7] 如果清單為空,回退播放預設的公播清單(通常是背景播放用)
|
||||||
await InitializeAndPlayPublicPlaylist();
|
await InitializeAndPlayPublicPlaylist();
|
||||||
|
stopwatch.Stop();
|
||||||
|
Console.WriteLine($"[5-7]如果清單為空,回退播放預設的公播清單,耗時{stopwatch.ElapsedMilliseconds}ms");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -710,10 +727,11 @@ namespace DualScreenDemo
|
|||||||
|
|
||||||
// 根據目前播放模式(點歌 or 公播)決定要播放的清單
|
// 根據目前播放模式(點歌 or 公播)決定要播放的清單
|
||||||
List<SongData> currentPlaylist = isUserPlaylistPlaying ? playingSongList : publicPlaylist;
|
List<SongData> currentPlaylist = isUserPlaylistPlaying ? playingSongList : publicPlaylist;
|
||||||
|
|
||||||
// 若播放清單是空的,直接返回(不執行播放)
|
// 若播放清單是空的,直接返回(不執行播放)
|
||||||
if (!currentPlaylist.Any()) return;
|
if (!currentPlaylist.Any()) return;
|
||||||
|
|
||||||
|
|
||||||
if (!isUserPlaylistPlaying)
|
if (!isUserPlaylistPlaying)
|
||||||
{
|
{
|
||||||
// 公播模式下,正常循環播放(用 % 保證不會超出陣列界限)
|
// 公播模式下,正常循環播放(用 % 保證不會超出陣列界限)
|
||||||
@ -800,6 +818,7 @@ namespace DualScreenDemo
|
|||||||
|
|
||||||
private async Task InitializeAndPlayMedia(string pathToPlay)
|
private async Task InitializeAndPlayMedia(string pathToPlay)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (videoWindowPrimary != null)
|
if (videoWindowPrimary != null)
|
||||||
{
|
{
|
||||||
videoWindowPrimary.put_Visible(OABool.False);
|
videoWindowPrimary.put_Visible(OABool.False);
|
||||||
@ -819,7 +838,6 @@ namespace DualScreenDemo
|
|||||||
// 渲染媒體文件
|
// 渲染媒體文件
|
||||||
RenderMediaFilePrimary(pathToPlay);
|
RenderMediaFilePrimary(pathToPlay);
|
||||||
RenderMediaFileSecondary(pathToPlay);
|
RenderMediaFileSecondary(pathToPlay);
|
||||||
|
|
||||||
// 綁定視頻窗口到副屏幕
|
// 綁定視頻窗口到副屏幕
|
||||||
videoWindowSecondary = (IVideoWindow)videoRendererSecondary;
|
videoWindowSecondary = (IVideoWindow)videoRendererSecondary;
|
||||||
if (videoWindowSecondary != null)
|
if (videoWindowSecondary != null)
|
||||||
@ -830,13 +848,11 @@ namespace DualScreenDemo
|
|||||||
await Task.Delay(100); // 給予視窗一些時間進行設置
|
await Task.Delay(100); // 給予視窗一些時間進行設置
|
||||||
videoWindowSecondary.put_Visible(OABool.True);
|
videoWindowSecondary.put_Visible(OABool.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 音量處理
|
// 音量處理
|
||||||
if (isMuted)
|
if (isMuted)
|
||||||
{
|
{
|
||||||
SetVolume(-10000);
|
SetVolume(-10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 開始播放
|
// 開始播放
|
||||||
if (mediaControlPrimary != null) mediaControlPrimary.Run();
|
if (mediaControlPrimary != null) mediaControlPrimary.Run();
|
||||||
if (mediaControlSecondary != null) mediaControlSecondary.Run();
|
if (mediaControlSecondary != null) mediaControlSecondary.Run();
|
||||||
@ -845,7 +861,7 @@ namespace DualScreenDemo
|
|||||||
{
|
{
|
||||||
SyncToPrimaryMonitor();
|
SyncToPrimaryMonitor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 跳至下一首歌曲的方法,會根據目前播放清單(使用者清單或公播清單)做切換與播放邏輯控制。
|
/// 跳至下一首歌曲的方法,會根據目前播放清單(使用者清單或公播清單)做切換與播放邏輯控制。
|
||||||
@ -1119,7 +1135,7 @@ namespace DualScreenDemo
|
|||||||
videoWindowPrimary.put_Owner(PrimaryForm.Instance.primaryScreenPanel.Handle); // 设置为 primaryScreenPanel 的句柄
|
videoWindowPrimary.put_Owner(PrimaryForm.Instance.primaryScreenPanel.Handle); // 设置为 primaryScreenPanel 的句柄
|
||||||
videoWindowPrimary.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
|
videoWindowPrimary.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
|
||||||
videoWindowPrimary.SetWindowPosition(0, 0, 1500, 1000); // 调整视频窗口大小以填满黑色区域
|
videoWindowPrimary.SetWindowPosition(0, 0, 1500, 1000); // 调整视频窗口大小以填满黑色区域
|
||||||
Task.Delay(100).Wait();
|
//Task.Delay(100).Wait();
|
||||||
videoWindowPrimary.put_Visible(OABool.True);
|
videoWindowPrimary.put_Visible(OABool.True);
|
||||||
SaveGraphFile(graphBuilderPrimary, "primary_graph.grf");
|
SaveGraphFile(graphBuilderPrimary, "primary_graph.grf");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user