2509021502

播放器流程調整
歌曲ID查詢錯誤修正
同步畫面歌曲切換畫面閃爍修正
This commit is contained in:
jasonchenwork 2025-09-02 15:03:59 +08:00
parent e2a39fde2b
commit 58aa060a78
4 changed files with 28 additions and 27 deletions

View File

@ -524,7 +524,6 @@ namespace DualScreenDemo
InitializeSoundEffectButtons(); InitializeSoundEffectButtons();
InitializeSyncScreen(); InitializeSyncScreen();
InitializeButtonsForSongIDSearch();
InitializeOtherControls(); InitializeOtherControls();
pictureBox1.BringToFront(); pictureBox1.BringToFront();

View File

@ -16,8 +16,10 @@ namespace DualScreenDemo
private void InitializeButtonsForSongIDSearch() private void InitializeButtonsForSongIDSearch()
{ {
InitializeNumberSongIDButtons(pictureBoxSongIDSearch, NumberSongIDButton_Click);
InitializeInputBoxSongIDSearch(); InitializeInputBoxSongIDSearch();
InitializeNumberSongIDButtons(pictureBoxSongIDSearch,NumberSongIDButton_Click);
InitializeSongIDButton(); InitializeSongIDButton();
} }
@ -96,13 +98,13 @@ namespace DualScreenDemo
// 創建語音按鈕並設置其屬性 // 創建語音按鈕並設置其屬性
numberSongIDButtonsForSongs[index] = new Button numberSongIDButtonsForSongs[index] = new Button
{ {
Name = $"numberWordCountButton_{numberWordCountSymbols[index]}", // 按鈕名稱設為語音符號名稱 Name = $"numberSongIDButtonsForSongs_{numberWordCountSymbols[index]}", // 按鈕名稱設為語音符號名稱
}; };
ConfigureButton(numberSongIDButtonsForSongs[index], x, y, 72, 67, ConfigureButton(numberSongIDButtonsForSongs[index], x, y, 72, 67,
new Bitmap(Path.Combine(serverPath, data["NumberWordCountButtonImages"][$"button{index}_normal"])), new Bitmap(Path.Combine(serverPath, data["NumberSongIDButtonImages"][$"button{index}_normal"])),
new Bitmap(Path.Combine(serverPath, data["NumberWordCountButtonImages"][$"button{index}_mouseOver"])), new Bitmap(Path.Combine(serverPath, data["NumberSongIDButtonImages"][$"button{index}_mouseOver"])),
new Bitmap(Path.Combine(serverPath, data["NumberWordCountButtonImages"][$"button{index}_mouseDown"])), new Bitmap(Path.Combine(serverPath, data["NumberSongIDButtonImages"][$"button{index}_mouseDown"])),
handler); handler);
// 設置按鈕的 Tag 屬性為對應的語音符號 // 設置按鈕的 Tag 屬性為對應的語音符號
@ -139,11 +141,11 @@ namespace DualScreenDemo
Name = "inputBoxSongIDSearch", Name = "inputBoxSongIDSearch",
ForeColor = Color.Black, // 設定文字顏色 ForeColor = Color.Black, // 設定文字顏色
Font = new Font("Times New Roman", 26, FontStyle.Regular), // 設定字體樣式 Font = new Font("Times New Roman", 26, FontStyle.Regular), // 設定字體樣式
ScrollBars = RichTextBoxScrollBars.None // 不顯示滾動條 ScrollBars = RichTextBoxScrollBars.None, // 不顯示滾動條
}; };
// 調整和定位輸入框的位置及大小 // 調整和定位輸入框的位置及大小
ResizeAndPositionControl(inputBoxSongIDSearch,10, 55, 400, 60); ResizeAndPositionControl(inputBoxSongIDSearch, 10, 55, 400, 60);
// 將輸入框加入到窗體的控件集合中 // 將輸入框加入到窗體的控件集合中
pictureBoxSongIDSearch.Controls.Add(inputBoxSongIDSearch); pictureBoxSongIDSearch.Controls.Add(inputBoxSongIDSearch);
@ -224,6 +226,7 @@ namespace DualScreenDemo
if (inputBoxSongIDSearch.Visible) if (inputBoxSongIDSearch.Visible)
{ {
inputBoxSongIDSearch.Text += button.Tag.ToString(); inputBoxSongIDSearch.Text += button.Tag.ToString();
Console.WriteLine(inputBoxSongIDSearch.Text);
} }
} }
} }
@ -245,16 +248,7 @@ namespace DualScreenDemo
} }
private void CloseButtonClick(object sender, EventArgs e) private void CloseButtonClick(object sender, EventArgs e)
{ {
pictureBoxSongIDSearch.Visible = false; CloseUI(pictureBoxSongIDSearch);
modifyButtonSongIDSearch.Visible = false;
clearButtonSongIDSearch.Visible = false;
closeButtonSongIDSearch.Visible = false;
enterButtonSongIDSearch.Visible = false;
inputBoxSongIDSearch.Visible = false;
for (int i = 0; i <= 9; i++)
{
numberSongIDButtonsForSongs[i].Visible = false;
}
// 隱藏 SongID 歌手圖片框 // 隱藏 SongID 歌手圖片框
numberSearchSongButton.BackgroundImage = numberSearchSongNormalBackground; numberSearchSongButton.BackgroundImage = numberSearchSongNormalBackground;
// 隱藏與 SongID 歌手相關的所有按鈕 // 隱藏與 SongID 歌手相關的所有按鈕

View File

@ -10,12 +10,12 @@ namespace DualScreenDemo.Services
private MediaPlayer _mediaPlayer; private MediaPlayer _mediaPlayer;
private Media? _media; private Media? _media;
private bool _disposed; private bool _disposed;
public bool _zero;
public MediaService() public MediaService()
{ {
Core.Initialize(); Core.Initialize();
_libVLC = new LibVLC( _libVLC = new LibVLC(
// "--reset-plugins-cache", //產生libvlc plugins設定cache,加快初次啟動速度,生成快取後註解關閉此設定。 // "--reset-plugins-cache", //產生libvlc plugins設定cache,加快初次啟動速度,生成快取後註解關閉此設定。
"--verbose=-1", "--verbose=-1",
// enableDebugLogs: true, // enableDebugLogs: true,
"--audio-time-stretch", "--audio-time-stretch",
@ -80,14 +80,22 @@ namespace DualScreenDemo.Services
{ {
try try
{ {
_mediaPlayer.Stop(); _mediaPlayer.Pause();
_media?.Dispose(); _media?.Dispose();
_media = new Media(filePath, FromType.FromPath); _media = new Media(filePath, FromType.FromPath);
_mediaPlayer.Media = addMediaOption(_media, audioTrackIndex);
_mediaPlayer.Play(); _media.ParseAsync(_libVLC);
_media.ParsedChanged += (sender, args) =>
{
if (args.ParsedStatus != MediaParsedStatus.Failed)
{
_mediaPlayer.Media = addMediaOption(_media, audioTrackIndex);
_mediaPlayer.Play();
}
};
_mediaPlayer.Fullscreen = true; _mediaPlayer.Fullscreen = true;
_mediaPlayer.Mute = false; _mediaPlayer.Mute = false;
// _mediaPlayer.Stopped += (s, e) => Console.WriteLine("Player Stopped");
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -107,6 +115,7 @@ namespace DualScreenDemo.Services
// media.AddOption(":clock-jitter=0"); // media.AddOption(":clock-jitter=0");
// media.AddOption(":clock-synchro=0"); // media.AddOption(":clock-synchro=0");
media.AddOption($":audio-track={audioTrackIndex}"); media.AddOption($":audio-track={audioTrackIndex}");
if(_zero)media.AddOption(":no-audio");
return media; return media;
} }

View File

@ -126,6 +126,7 @@ namespace DualScreenDemo
this.Controls.Add(PrimaryForm.Instance.videoView1); this.Controls.Add(PrimaryForm.Instance.videoView1);
PrimaryForm.Instance.videoView1.MediaPlayer = _mediaService1.Player; PrimaryForm.Instance.videoView1.MediaPlayer = _mediaService1.Player;
PrimaryForm.Instance.videoView0.MediaPlayer = _mediaService0.Player; PrimaryForm.Instance.videoView0.MediaPlayer = _mediaService0.Player;
_mediaService0._zero = true;
PlayNextSong(); PlayNextSong();
} }
} }
@ -347,11 +348,9 @@ namespace DualScreenDemo
{ {
string pathToPlay = song.getFile(); string pathToPlay = song.getFile();
//同步畫面播放器載入media設置參數 //同步畫面播放器載入media設置參數
PrimaryForm.Instance.videoView0.Visible = false;
_mediaService0.LoadMedia(pathToPlay, 0); _mediaService0.LoadMedia(pathToPlay, 0);
_mediaService0.Player.Media.AddOption(":no-audio"); // _mediaService0.Player.Media.AddOption(":no-audio");
_mediaService0.Player.AspectRatio = "8:5"; _mediaService0.Player.AspectRatio = "8:5";
PrimaryForm.Instance.videoView0.Visible = true;
//影片畫面播放器載入media設置聲道 //影片畫面播放器載入media設置聲道
_mediaService1.LoadMedia(pathToPlay, song.isPublicSong ? 0 : 1); _mediaService1.LoadMedia(pathToPlay, song.isPublicSong ? 0 : 1);