調整 公播歌單 邏輯調整 20250710
This commit is contained in:
parent
9292b42d51
commit
7b5fed4332
@ -616,7 +616,7 @@ namespace DualScreenDemo
|
||||
int completedCount = PrimaryForm.currentSongIndexInHistory;
|
||||
// 判斷是否正在播放公播歌單 (若用戶點播歌單為空,則播放公播歌單)
|
||||
bool isPlayingPublicList = PrimaryForm.userRequestedSongs.Count == 0 ||
|
||||
(PrimaryForm.currentSongIndexInHistory >= PrimaryForm.userRequestedSongs.Count - 1 && PrimaryForm.Instance.videoPlayerForm.IsPlayingPublicSong);
|
||||
(PrimaryForm.currentSongIndexInHistory >= PrimaryForm.userRequestedSongs.Count - 1 );
|
||||
if (isPlayingPublicList)
|
||||
{
|
||||
for (int i = startIndex; i < endIndex; i++)
|
||||
|
@ -601,11 +601,10 @@ namespace OverlayFormObj
|
||||
|
||||
|
||||
|
||||
public void UpdateNextSongLabelFromPlaylist(bool isUserPlaylistPlaying, SongData currentPlayingSong)
|
||||
public void UpdateNextSongLabelFromPlaylist( SongData currentPlayingSong)
|
||||
{
|
||||
// 获取播放列表
|
||||
List<SongData> currentPlaylist = isUserPlaylistPlaying ?
|
||||
VideoPlayerForm.playingSongList : VideoPlayerForm.publicPlaylist;
|
||||
List<SongData> currentPlaylist = VideoPlayerForm.playingSongList ;
|
||||
|
||||
if (currentPlaylist == null || currentPlaylist.Count == 0)
|
||||
{
|
||||
|
@ -387,7 +387,7 @@ namespace DualScreenDemo
|
||||
{
|
||||
// 判斷是否正在播放公播歌單 (若用戶點播歌單為空,則播放公播歌單)
|
||||
bool isPlayingPublicList = userRequestedSongs.Count == 0 ||
|
||||
(currentSongIndexInHistory >= userRequestedSongs.Count - 1 && PrimaryForm.Instance.videoPlayerForm.IsPlayingPublicSong);
|
||||
(currentSongIndexInHistory >= userRequestedSongs.Count - 1 );
|
||||
if (isPlayingPublicList)
|
||||
{
|
||||
// 若播放公播歌單,代表已點歌曲皆已播放完畢
|
||||
|
@ -150,7 +150,7 @@ namespace DualScreenDemo
|
||||
primaryForm.videoPlayerForm.Show();
|
||||
|
||||
// 初始化公共播放列表
|
||||
primaryForm.videoPlayerForm.InitializePublicPlaylist(cherker.GetSongs());
|
||||
primaryForm.videoPlayerForm.PlayPublicPlaylist();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ namespace DualScreenDemo
|
||||
{
|
||||
primaryForm.videoPlayerForm = new VideoPlayerForm();
|
||||
// primaryForm.primaryMediaPlayerForm = new PrimaryMediaPlayerForm(primaryForm, primaryForm.secondaryMediaPlayerForm);
|
||||
primaryForm.videoPlayerForm.InitializePublicPlaylist(cherker.GetSongs());
|
||||
primaryForm.videoPlayerForm.PlayPublicPlaylist();
|
||||
primaryForm.videoPlayerForm.Show();
|
||||
}
|
||||
}
|
||||
|
@ -139,7 +139,6 @@ namespace DualScreenDemo
|
||||
if (File.Exists(closePath))
|
||||
{
|
||||
SongData closeSong = new SongData("0", "結束播放",closePath, 1,true);
|
||||
VideoPlayerForm.publicPlaylist = new List<SongData>();
|
||||
VideoPlayerForm.playingSongList = new List<SongData>();
|
||||
PrimaryForm.playedSongsHistory = new List<SongData>();
|
||||
if (VideoPlayerForm.Instance.currentPlayingSong != null)
|
||||
@ -148,7 +147,6 @@ namespace DualScreenDemo
|
||||
}
|
||||
|
||||
VideoPlayerForm.playingSongList.Add(closeSong);
|
||||
VideoPlayerForm.publicPlaylist.Add(closeSong);
|
||||
|
||||
PrimaryForm.userRequestedSongs = new List<SongData>();
|
||||
|
||||
@ -189,7 +187,6 @@ namespace DualScreenDemo
|
||||
{
|
||||
// 開台時跳至首頁
|
||||
|
||||
VideoPlayerForm.publicPlaylist = new List<SongData>();
|
||||
VideoPlayerForm.playingSongList = new List<SongData>();
|
||||
VideoPlayerForm.Instance.PlayPublicPlaylist();
|
||||
PrimaryForm.currentSongIndexInHistory = -1;
|
||||
|
@ -10,7 +10,6 @@ namespace DualScreenDemo
|
||||
{
|
||||
#region 防止閃屏
|
||||
public SongData currentPlayingSong;
|
||||
public bool IsPlayingPublicSong { get; private set; } = false;
|
||||
protected override CreateParams CreateParams
|
||||
{
|
||||
get
|
||||
@ -93,9 +92,7 @@ namespace DualScreenDemo
|
||||
|
||||
public static OverlayForm overlayForm;
|
||||
public static List<SongData> playingSongList;
|
||||
public static List<SongData> publicPlaylist;
|
||||
public static int currentSongIndex = 0;
|
||||
private static bool isUserPlaylistPlaying = false;
|
||||
public bool isMuted = false;
|
||||
public int previousVolume = -1000;
|
||||
public bool isPaused = false;
|
||||
@ -536,12 +533,6 @@ namespace DualScreenDemo
|
||||
}
|
||||
}
|
||||
|
||||
public async void InitializePublicPlaylist(List<SongData> initialPlaylist)
|
||||
{
|
||||
publicPlaylist = initialPlaylist;
|
||||
await PlayPublicPlaylist(); // 开始播放公播歌单
|
||||
}
|
||||
|
||||
public async Task SetPlayingSongList(List<SongData> songList)
|
||||
{
|
||||
// [1] 輸出 debug 訊息,方便開發時追蹤是否有呼叫此方法
|
||||
@ -554,27 +545,12 @@ namespace DualScreenDemo
|
||||
// [3] 將新的播放清單指派給 `playingSongList`
|
||||
playingSongList = songList;
|
||||
|
||||
|
||||
// [4] 根據是否有歌,設定旗標為是否播放使用者點播清單
|
||||
isUserPlaylistPlaying = playingSongList != null && playingSongList.Any();
|
||||
|
||||
|
||||
// [5] 強制關閉公播狀態(意即現在進入點歌模式)
|
||||
IsPlayingPublicSong = false;
|
||||
|
||||
// [6] 若使用者點播清單有歌,就開始播放
|
||||
if (isUserPlaylistPlaying)
|
||||
{
|
||||
// [6.1] 設定當前歌曲索引為 -1(意味著即將播放第一首,從 `PlayNextSong` 開始)
|
||||
currentSongIndex = -1;
|
||||
// [6.2] 播放下一首歌(實際會遞增 index 為 0,並播放該首歌)
|
||||
await PlayNextSong();
|
||||
}
|
||||
else
|
||||
{
|
||||
await InitializeAndPlayPublicPlaylist();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task PlayPublicPlaylist()
|
||||
@ -597,60 +573,10 @@ namespace DualScreenDemo
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
isUserPlaylistPlaying = false;
|
||||
IsPlayingPublicSong = true; // 设置为正在播放公播
|
||||
currentSongIndex = -1;
|
||||
|
||||
try
|
||||
{
|
||||
// 重新整理公播清單
|
||||
publicPlaylist = new List<SongData>();
|
||||
|
||||
// 首先添加 welcome.mpg
|
||||
string welcomePath = @"D:\video\welcome.mpg";
|
||||
if (File.Exists(welcomePath))
|
||||
{
|
||||
publicPlaylist.Add(new SongData(
|
||||
"0", "歡迎光臨", welcomePath, 1,true
|
||||
));
|
||||
}
|
||||
|
||||
// 添加 BGM 序列
|
||||
for (int i = 1; i <= 99; i++)
|
||||
{
|
||||
string bgmPath = $@"D:\video\BGM{i:D2}.mpg";
|
||||
if (File.Exists(bgmPath))
|
||||
{
|
||||
publicPlaylist.Add(new SongData(
|
||||
i.ToString(), $"背景音樂{i:D2}", bgmPath, 1,true
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// 如果公播清單為空,使用原有的歌曲
|
||||
if (publicPlaylist.Count == 0)
|
||||
{
|
||||
string videoDirectory = @"D:\video\";
|
||||
string[] videoFiles = Directory.GetFiles(videoDirectory, "*.mpg");
|
||||
foreach (var songPath in videoFiles)
|
||||
{
|
||||
string fileName = Path.GetFileNameWithoutExtension(songPath);
|
||||
publicPlaylist.Add(new SongData("0", fileName,songPath,1,true));
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(100); // 添加短暂延迟
|
||||
await PlayNextSong();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"播放公播清單時發生錯誤: {ex.Message}");
|
||||
// 可以在这里添加重试逻辑
|
||||
await Task.Delay(1000);
|
||||
await PlayNextSong();
|
||||
}
|
||||
}
|
||||
|
||||
// private static async Task UpdateMarqueeTextForCurrentSong(SongData song)
|
||||
// {
|
||||
@ -701,11 +627,11 @@ namespace DualScreenDemo
|
||||
}
|
||||
public void UpdateNextSongFromPlaylist()
|
||||
{
|
||||
List<SongData> currentPlaylist = isUserPlaylistPlaying ? playingSongList : publicPlaylist;
|
||||
List<SongData> currentPlaylist = playingSongList ;
|
||||
|
||||
if (currentPlaylist == null || currentPlaylist.Count == 0)
|
||||
{
|
||||
overlayForm?.UpdateNextSongLabelFromPlaylist(isUserPlaylistPlaying, null);
|
||||
overlayForm?.UpdateNextSongLabelFromPlaylist( null);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -713,12 +639,12 @@ namespace DualScreenDemo
|
||||
|
||||
if (currentSongIndex == -1 || currentSongIndex + 1 >= currentPlaylist.Count)
|
||||
{
|
||||
overlayForm?.UpdateNextSongLabelFromPlaylist(isUserPlaylistPlaying, null);
|
||||
overlayForm?.UpdateNextSongLabelFromPlaylist( null);
|
||||
}
|
||||
else
|
||||
{
|
||||
SongData nextSong = currentPlaylist[currentSongIndex + 1];
|
||||
overlayForm?.UpdateNextSongLabelFromPlaylist(isUserPlaylistPlaying, currentPlayingSong);
|
||||
overlayForm?.UpdateNextSongLabelFromPlaylist( currentPlayingSong);
|
||||
}
|
||||
}
|
||||
|
||||
@ -733,20 +659,11 @@ namespace DualScreenDemo
|
||||
Console.WriteLine("開始播放下一首歌曲...");
|
||||
|
||||
// 根據目前播放模式(點歌 or 公播)決定要播放的清單
|
||||
List<SongData> currentPlaylist = isUserPlaylistPlaying ? playingSongList : publicPlaylist;
|
||||
List<SongData> currentPlaylist = playingSongList ;
|
||||
|
||||
// 若播放清單是空的,直接返回(不執行播放)
|
||||
if (!currentPlaylist.Any()) return;
|
||||
|
||||
|
||||
if (!isUserPlaylistPlaying)
|
||||
{
|
||||
// 公播模式下,正常循環播放(用 % 保證不會超出陣列界限)
|
||||
currentSongIndex = (currentSongIndex + 1) % currentPlaylist.Count;
|
||||
Console.WriteLine($"順序播放: currentSongIndex = {currentSongIndex}, currentPlaylist.Count = {currentPlaylist.Count}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 若是使用者點播模式,先送出升Key的串口指令
|
||||
if (SerialPortManager.mySerialPort != null && SerialPortManager.mySerialPort.IsOpen)
|
||||
{
|
||||
@ -756,7 +673,7 @@ namespace DualScreenDemo
|
||||
|
||||
// 同樣遞增 index 來播放下一首
|
||||
currentSongIndex = (currentSongIndex + 1) % currentPlaylist.Count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 可以取得 燈控/聲控 的位置
|
||||
@ -887,34 +804,18 @@ namespace DualScreenDemo
|
||||
await Task.Delay(100);
|
||||
|
||||
// 如果目前正在播放使用者點播清單,且清單還有歌曲
|
||||
if (isUserPlaylistPlaying && playingSongList != null && playingSongList.Count > 0)
|
||||
if ( playingSongList != null && playingSongList.Count > 0)
|
||||
{
|
||||
// 移除目前播放的第一首歌(已經播放過的)
|
||||
playingSongList.RemoveAt(0);
|
||||
|
||||
if (playingSongList.Count == 0)
|
||||
if (playingSongList.Count <= 0)
|
||||
{
|
||||
// 使用者點播清單播完了,切換回公播清單
|
||||
Console.WriteLine("用戶播放列表已清空,切換至公播清單");
|
||||
isUserPlaylistPlaying = false;
|
||||
lastPlayedIndex = -1;
|
||||
currentSongIndex = -1;
|
||||
|
||||
// 初始化並開始播放公播清單
|
||||
await InitializeAndPlayPublicPlaylist();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 還有歌曲可播,繼續播放下一首使用者歌曲
|
||||
}
|
||||
currentSongIndex = -1;
|
||||
await PlayNextSong();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果不是在播放使用者清單(或清單為空),直接初始化並播放公播清單
|
||||
await InitializeAndPlayPublicPlaylist();
|
||||
}
|
||||
|
||||
// 如果目前歌曲在播放歷史列表的索引是合法的(防呆)
|
||||
if (PrimaryForm.currentSongIndexInHistory >= 0 && PrimaryForm.currentSongIndexInHistory < PrimaryForm.playedSongsHistory.Count)
|
||||
@ -929,7 +830,7 @@ namespace DualScreenDemo
|
||||
}
|
||||
/*如果當前為公播,不可以+1*/
|
||||
bool isPlayingPublicList = PrimaryForm.userRequestedSongs.Count == 0 ||
|
||||
(PrimaryForm.currentSongIndexInHistory >= PrimaryForm.userRequestedSongs.Count - 1 && PrimaryForm.Instance.videoPlayerForm.IsPlayingPublicSong);
|
||||
(PrimaryForm.currentSongIndexInHistory >= PrimaryForm.userRequestedSongs.Count - 1 );
|
||||
if (!isPlayingPublicList)
|
||||
{
|
||||
PrimaryForm.currentSongIndexInHistory += 1;
|
||||
@ -940,53 +841,15 @@ namespace DualScreenDemo
|
||||
{
|
||||
// 若有例外錯誤,列印錯誤訊息並切回公播模式
|
||||
Console.WriteLine($"切換歌曲時發生錯誤: {ex.Message}");
|
||||
await InitializeAndPlayPublicPlaylist();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 新增一个方法来处理公播列表的初始化和播放
|
||||
private async Task InitializeAndPlayPublicPlaylist()
|
||||
{
|
||||
try
|
||||
{
|
||||
isUserPlaylistPlaying = false;
|
||||
currentSongIndex = -1;
|
||||
|
||||
// 重新初始化公播列表
|
||||
publicPlaylist = new List<SongData>();
|
||||
|
||||
// 添加 welcome.mpg
|
||||
string welcomePath = @"D:\video\welcome.mpg";
|
||||
if (File.Exists(welcomePath))
|
||||
{
|
||||
publicPlaylist.Add(new SongData("0", "歡迎光臨", welcomePath, 1,true));
|
||||
}
|
||||
|
||||
// 添加 BGM 序列
|
||||
for (int i = 1; i <= 99; i++)
|
||||
{
|
||||
string bgmPath = $@"D:\video\BGM{i:D2}.mpg";
|
||||
if (File.Exists(bgmPath))
|
||||
{
|
||||
publicPlaylist.Add(new SongData(i.ToString(), $"背景音樂{i:D2}", bgmPath, 1,true));
|
||||
}
|
||||
}
|
||||
|
||||
if (publicPlaylist.Count > 0)
|
||||
{
|
||||
await PlayNextSong();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"初始化公播清單時發生錯誤: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void ReplayCurrentSong()
|
||||
{
|
||||
List<SongData> currentPlaylist = isUserPlaylistPlaying ? playingSongList : publicPlaylist;
|
||||
List<SongData> currentPlaylist = playingSongList ;
|
||||
if (!currentPlaylist.Any()) return;
|
||||
var songToPlay = currentPlaylist[currentSongIndex];
|
||||
var pathToPlay = songToPlay.getFile();
|
||||
@ -1302,7 +1165,7 @@ namespace DualScreenDemo
|
||||
StopAndReleaseResources();
|
||||
await Task.Delay(100); // 给予足够的时间释放资源
|
||||
|
||||
if (isUserPlaylistPlaying && playingSongList != null)
|
||||
if ( playingSongList != null)
|
||||
{
|
||||
if (playingSongList.Count > 0)
|
||||
{
|
||||
@ -1351,7 +1214,6 @@ namespace DualScreenDemo
|
||||
}
|
||||
|
||||
// 重置播放状态但保留历史记录
|
||||
isUserPlaylistPlaying = false;
|
||||
currentSongIndex = -1;
|
||||
|
||||
// 确保所有未播放的歌曲状态被清除
|
||||
@ -1366,7 +1228,9 @@ namespace DualScreenDemo
|
||||
|
||||
// 添加延迟以确保状态更新完成
|
||||
await Task.Delay(200);
|
||||
await InitializeAndPlayPublicPlaylist();
|
||||
currentSongIndex = -1;
|
||||
|
||||
await PlayNextSong();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1378,25 +1242,20 @@ namespace DualScreenDemo
|
||||
{
|
||||
Console.WriteLine($"處理播放列表時發生錯誤: {ex.Message}");
|
||||
lastPlayedIndex = -1;
|
||||
isUserPlaylistPlaying = false;
|
||||
currentSongIndex = -1;
|
||||
await InitializeAndPlayPublicPlaylist();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!isUserPlaylistPlaying && publicPlaylist != null)
|
||||
{
|
||||
|
||||
await PlayNextSong();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"切換歌曲時發生錯誤: {ex.Message}");
|
||||
// 发生错误时重置状态并切换到公播
|
||||
lastPlayedIndex = -1;
|
||||
isUserPlaylistPlaying = false;
|
||||
currentSongIndex = -1;
|
||||
await InitializeAndPlayPublicPlaylist();
|
||||
await PlayNextSong();
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -1413,13 +1272,6 @@ namespace DualScreenDemo
|
||||
Console.WriteLine($"監控媒體事件時發生錯誤: {ex.Message}");
|
||||
isPlayingNext = false;
|
||||
|
||||
// 添加重试机制
|
||||
if (!isUserPlaylistPlaying && publicPlaylist != null)
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
await PlayNextSong();
|
||||
}
|
||||
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<ApplicationIcon>Images/superstar.ico</ApplicationIcon>
|
||||
<RootNamespace>superstar</RootNamespace>
|
||||
<RootNamespace>superstar_1.2</RootNamespace>
|
||||
<AssemblyName>superstar</AssemblyName>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
Loading…
x
Reference in New Issue
Block a user