Compare commits
11 Commits
3d255da675
...
107639f4c9
Author | SHA1 | Date | |
---|---|---|---|
107639f4c9 | |||
dd2a0f3d7b | |||
5db51dda99 | |||
7eb8f395a0 | |||
eafd322a0d | |||
f07129c18f | |||
5d2ea02263 | |||
4a76e14102 | |||
4d09ed914a | |||
39c2a39fd8 | |||
f2d633e688 |
@ -26,10 +26,9 @@ namespace DualScreenDemo
|
||||
/// 遙控器接收資料
|
||||
/// </summary>
|
||||
public async Task ProcessData(string indata)
|
||||
{
|
||||
AddToHistory(indata);
|
||||
{ AddToHistory(indata);
|
||||
// 遙控器測試
|
||||
Console.WriteLine("遙控器: " + indata);
|
||||
// Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 遙控器: {indata}");
|
||||
switch (indata)
|
||||
{
|
||||
case "A261A4": // 輸入
|
||||
@ -70,12 +69,12 @@ namespace DualScreenDemo
|
||||
// 原唱
|
||||
case "A26CA4":
|
||||
Console.WriteLine("ToggleVocalRemoval Invoked");
|
||||
InvokeAction(() => VideoPlayerForm.Instance.ToggleVocalRemoval());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowOriginalSongLabel());
|
||||
SafeInvokeAction("A26CA4",() => VideoPlayerForm.Instance.ToggleVocalRemoval());
|
||||
SafeInvokeAction("A26CA4",() => OverlayForm.MainForm.ShowOriginalSongLabel());
|
||||
break;
|
||||
// 導唱
|
||||
case "A26EA4":
|
||||
InvokeAction(() => VideoPlayerForm.Instance.ToggleVocalRemoval());
|
||||
SafeInvokeAction("A26EA4",() => VideoPlayerForm.Instance.ToggleVocalRemoval());
|
||||
break;
|
||||
case "A26DA4":
|
||||
PauseOrResumeSong();
|
||||
@ -88,98 +87,98 @@ namespace DualScreenDemo
|
||||
HandleArtistAnnouncements();
|
||||
break;
|
||||
case "A2B3A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowVolumeUpLabel());
|
||||
SafeInvokeAction("A2B3A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2B3A4",() => OverlayForm.MainForm.ShowVolumeUpLabel());
|
||||
break;
|
||||
case "A2B4A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowVolumeDownLabel());
|
||||
SafeInvokeAction("A2B4A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2B4A4",() => OverlayForm.MainForm.ShowVolumeDownLabel());
|
||||
break;
|
||||
case "A2B5A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowMicUpLabel());
|
||||
SafeInvokeAction("A2B5A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2B5A4",() => OverlayForm.MainForm.ShowMicUpLabel());
|
||||
break;
|
||||
case "A2B6A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowMicDownLabel());
|
||||
SafeInvokeAction("A2B6A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2B6A4",() => OverlayForm.MainForm.ShowMicDownLabel());
|
||||
break;
|
||||
case "A2C2A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HidemicLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowStandardLabel());
|
||||
SafeInvokeAction("A2C2A4",() => OverlayForm.MainForm.HidemicLabels());
|
||||
SafeInvokeAction("A2C2A4",() => OverlayForm.MainForm.ShowStandardLabel());
|
||||
break;
|
||||
case "A2C3A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HidemicLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowProfessionalLabel());
|
||||
SafeInvokeAction("A2C3A4",() => OverlayForm.MainForm.HidemicLabels());
|
||||
SafeInvokeAction("A2C3A4",() => OverlayForm.MainForm.ShowProfessionalLabel());
|
||||
break;
|
||||
case "A2C4A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HidemicLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowSquareLabel());
|
||||
SafeInvokeAction("A2C4A4",() => OverlayForm.MainForm.HidemicLabels());
|
||||
SafeInvokeAction("A2C4A4",() => OverlayForm.MainForm.ShowSquareLabel());
|
||||
break;
|
||||
case "A2C1A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HidemicLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowSingDownLabel());
|
||||
SafeInvokeAction("A2C1A4",() => OverlayForm.MainForm.HidemicLabels());
|
||||
SafeInvokeAction("A2C1A4",() => OverlayForm.MainForm.ShowSingDownLabel());
|
||||
break;
|
||||
case "A2D5A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowBrightLabel());
|
||||
SafeInvokeAction("A2D5A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2D5A4",() => OverlayForm.MainForm.ShowBrightLabel());
|
||||
break;
|
||||
case "A2D7A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowRomanticLabel());
|
||||
SafeInvokeAction("A2D7A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2D7A4",() => OverlayForm.MainForm.ShowRomanticLabel());
|
||||
break;
|
||||
/* case "A27CA4":
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowMaleKeyLabel());
|
||||
break;
|
||||
case "A282A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowFemaleKeyLabel());
|
||||
break;*/
|
||||
/* case "A27CA4":
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowMaleKeyLabel());
|
||||
break;
|
||||
case "A282A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowFemaleKeyLabel());
|
||||
break;*/
|
||||
case "A2D6A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowSoftLabel());
|
||||
SafeInvokeAction("A2D6A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2D6A4",() => OverlayForm.MainForm.ShowSoftLabel());
|
||||
break;
|
||||
case "A2D8A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowDynamicLabel());
|
||||
SafeInvokeAction("A2D8A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A2D8A4",() => OverlayForm.MainForm.ShowDynamicLabel());
|
||||
break;
|
||||
case "A275A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowTintLabel());
|
||||
SafeInvokeAction("A275A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A275A4",() => OverlayForm.MainForm.ShowTintLabel());
|
||||
break;
|
||||
case "A283A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyUpLabel("↑升4調"));
|
||||
break;
|
||||
SafeInvokeAction("A283A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A283A4",() => OverlayForm.MainForm.ShowKeyUpLabel("↑升4調"));
|
||||
break;
|
||||
case "A282A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyUpLabel("↑升3調"));
|
||||
SafeInvokeAction("A282A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A282A4",() => OverlayForm.MainForm.ShowKeyUpLabel("↑升3調"));
|
||||
break;
|
||||
case "A281A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyUpLabel("↑升2調"));
|
||||
SafeInvokeAction("A281A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A281A4",() => OverlayForm.MainForm.ShowKeyUpLabel("↑升2調"));
|
||||
break;
|
||||
case "A280A4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyUpLabel("↑升1調"));
|
||||
SafeInvokeAction("A280A4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A280A4",() => OverlayForm.MainForm.ShowKeyUpLabel("↑升1調"));
|
||||
break;
|
||||
case "A27FA4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowStandardKeyLabel());
|
||||
SafeInvokeAction("A27FA4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A27FA4",() => OverlayForm.MainForm.ShowStandardKeyLabel());
|
||||
break;
|
||||
case "A27EA4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyDownLabel("↓降1調"));
|
||||
SafeInvokeAction("A27EA4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A27EA4",() => OverlayForm.MainForm.ShowKeyDownLabel("↓降1調"));
|
||||
break;
|
||||
case "A27DA4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyDownLabel("↓降2調"));
|
||||
SafeInvokeAction("A27EA4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A27EA4",() => OverlayForm.MainForm.ShowKeyDownLabel("↓降2調"));
|
||||
break;
|
||||
case "A27CA4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyDownLabel("↓降3調"));
|
||||
SafeInvokeAction("A27CA4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A27CA4",() => OverlayForm.MainForm.ShowKeyDownLabel("↓降3調"));
|
||||
break;
|
||||
case "A27BA4":
|
||||
InvokeAction(() => OverlayForm.MainForm.HideAllLabels());
|
||||
InvokeAction(() => OverlayForm.MainForm.ShowKeyDownLabel("↓降4調"));
|
||||
SafeInvokeAction("A27BA4",() => OverlayForm.MainForm.HideAllLabels());
|
||||
SafeInvokeAction("A27BA4",() => OverlayForm.MainForm.ShowKeyDownLabel("↓降4調"));
|
||||
break;
|
||||
default:
|
||||
if (Regex.IsMatch(indata, @"^A23\d+A4$"))
|
||||
@ -188,6 +187,31 @@ namespace DualScreenDemo
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
private Dictionary<string, DateTime> _recentCommands = new();
|
||||
private readonly TimeSpan _debounceInterval = TimeSpan.FromMilliseconds(300); // 最短觸發間隔
|
||||
private void SafeInvokeAction(string commandKey, Action action)
|
||||
{
|
||||
/*var now = DateTime.Now;
|
||||
|
||||
if (_recentCommands.TryGetValue(commandKey, out DateTime lastTime))
|
||||
{
|
||||
if (now - lastTime < _debounceInterval)
|
||||
return; // 忽略短時間內的重複指令
|
||||
}
|
||||
|
||||
_recentCommands[commandKey] = now;
|
||||
*/
|
||||
// 真正執行 UI 操作
|
||||
if (OverlayForm.MainForm.InvokeRequired)
|
||||
{
|
||||
OverlayForm.MainForm.BeginInvoke(action);
|
||||
}
|
||||
else
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
|
||||
private void AddToHistory(string indata)
|
||||
|
140
DataCheck.cs
Normal file
140
DataCheck.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System.IO;
|
||||
namespace DataCheck
|
||||
{
|
||||
public class dataCheck
|
||||
{
|
||||
public dataCheck()
|
||||
{
|
||||
menu_check();
|
||||
news_check();
|
||||
}
|
||||
private void menu_check()
|
||||
{
|
||||
string menuPath = @"\\JLDKTV\foods";
|
||||
string menuPath_local = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foods");
|
||||
|
||||
if (!Directory.Exists(menuPath_local))
|
||||
{
|
||||
Directory.CreateDirectory(menuPath_local);
|
||||
}
|
||||
var serverFiles = Directory.GetFiles(menuPath, "*.jpg")
|
||||
.Select(f => new FileInfo(f))
|
||||
.ToDictionary(f => f.Name, f => f);
|
||||
|
||||
var localFiles = Directory.GetFiles(menuPath_local, "*.jpg")
|
||||
.Select(f => new FileInfo(f))
|
||||
.ToDictionary(f => f.Name, f => f);
|
||||
foreach (var serverFile in serverFiles)
|
||||
{
|
||||
bool needsCopy = false;
|
||||
string localFilePath = Path.Combine(menuPath_local, serverFile.Key);
|
||||
if (!localFiles.ContainsKey(serverFile.Key))
|
||||
{
|
||||
needsCopy = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var localFile = localFiles[serverFile.Key];
|
||||
if (serverFile.Value.LastWriteTime > localFile.LastWriteTime)
|
||||
{
|
||||
needsCopy = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needsCopy)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(serverFile.Value.FullName, localFilePath, true);
|
||||
Console.WriteLine($"更新菜單: {serverFile.Key}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"複製菜單失敗 {serverFile.Key}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3-2. 清除本地有但伺服器已經沒有的檔案
|
||||
foreach (var localFile in localFiles)
|
||||
{
|
||||
if (!serverFiles.ContainsKey(localFile.Key))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(localFile.Value.FullName);
|
||||
Console.WriteLine($"刪除本地多餘菜單: {localFile.Key}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"刪除菜單失敗 {localFile.Key}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void news_check()
|
||||
{
|
||||
string newsPath = @"\\JLDKTV\news";
|
||||
string newsPath_local = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "news");
|
||||
|
||||
if (!Directory.Exists(newsPath_local))
|
||||
{
|
||||
Directory.CreateDirectory(newsPath_local);
|
||||
}
|
||||
var serverFiles = Directory.GetFiles(newsPath, "*.jpg")
|
||||
.Select(f => new FileInfo(f))
|
||||
.ToDictionary(f => f.Name, f => f);
|
||||
|
||||
var localFiles = Directory.GetFiles(newsPath_local, "*.jpg")
|
||||
.Select(f => new FileInfo(f))
|
||||
.ToDictionary(f => f.Name, f => f);
|
||||
foreach (var serverFile in serverFiles)
|
||||
{
|
||||
bool needsCopy = false;
|
||||
string localFilePath = Path.Combine(newsPath_local, serverFile.Key);
|
||||
if (!localFiles.ContainsKey(serverFile.Key))
|
||||
{
|
||||
needsCopy = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var localFile = localFiles[serverFile.Key];
|
||||
if (serverFile.Value.LastWriteTime > localFile.LastWriteTime)
|
||||
{
|
||||
needsCopy = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (needsCopy)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(serverFile.Value.FullName, localFilePath, true);
|
||||
Console.WriteLine($"更新新聞: {serverFile.Key}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"複製新聞失敗 {serverFile.Key}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3-2. 清除本地有但伺服器已經沒有的檔案
|
||||
foreach (var localFile in localFiles)
|
||||
{
|
||||
if (!serverFiles.ContainsKey(localFile.Key))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(localFile.Value.FullName);
|
||||
Console.WriteLine($"刪除本地多餘新聞: {localFile.Key}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"刪除新聞失敗 {localFile.Key}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
10
DualScreenDemo.Shared.cs
Normal file
10
DualScreenDemo.Shared.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace DualScreenDemo.Shared
|
||||
{
|
||||
public class VideoStatus
|
||||
{
|
||||
public bool IsGraphOk { get; set; }
|
||||
public string LastError { get; set; }
|
||||
public double PositionSeconds { get; set; }
|
||||
public string PlayState { get; set; }
|
||||
}
|
||||
}
|
@ -168,7 +168,10 @@ namespace HeartbeatSender
|
||||
private float GetTotalMemoryInMB()
|
||||
{
|
||||
var computerInfo = new ComputerInfo();
|
||||
return computerInfo.TotalPhysicalMemory / (1024f * 1024f); // 轉 MB
|
||||
var totalMB = computerInfo.TotalPhysicalMemory / (1024f);
|
||||
var availableMB = computerInfo.AvailablePhysicalMemory / (1024f);
|
||||
var usedMB = totalMB - availableMB;
|
||||
return usedMB; // 轉 MB
|
||||
}
|
||||
private float GetDiskTotalSizeInGB(string driveLetter = "C")
|
||||
{
|
||||
|
@ -40,9 +40,10 @@ namespace DualScreenDemo
|
||||
string randomFolderName = CreateRandomFolderAndRedirectHTML(baseDirectory);
|
||||
randomFolderPath = randomFolderName;
|
||||
|
||||
// 安裝包更新
|
||||
string localAddress = GetLocalIPAddress();
|
||||
string externalAddress = File.Exists(@"\\svr01\txt\ip.txt")
|
||||
? File.ReadAllText(@"\\svr01\txt\ip.txt").Trim()
|
||||
string externalAddress = File.Exists(@"\\JLDKTV\txt\ip.txt")
|
||||
? File.ReadAllText(@"\\JLDKTV\txt\ip.txt").Trim()
|
||||
: "";
|
||||
|
||||
_listener = new HttpListener();
|
||||
@ -427,36 +428,50 @@ namespace DualScreenDemo
|
||||
switch (data.Command)
|
||||
{
|
||||
case "pause":
|
||||
// 执行暂停操作
|
||||
// 执行暂停操作
|
||||
if (VideoPlayerForm.Instance.isPaused)
|
||||
{
|
||||
PrimaryForm.Instance.videoPlayerForm.Play();
|
||||
PrimaryForm.Instance.pauseButton.Visible = true;
|
||||
PrimaryForm.Instance.playButton.Visible = false;
|
||||
PrimaryForm.Instance.syncPauseButton.Visible = true;
|
||||
PrimaryForm.Instance.syncPlayButton.Visible = false;
|
||||
PrimaryForm.Instance.Invoke(new System.Action(() =>
|
||||
{
|
||||
PrimaryForm.Instance.videoPlayerForm.Play();
|
||||
PrimaryForm.Instance.pauseButton.Visible = true;
|
||||
PrimaryForm.Instance.playButton.Visible = false;
|
||||
PrimaryForm.Instance.syncPauseButton.Visible = true;
|
||||
PrimaryForm.Instance.syncPlayButton.Visible = false;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
PrimaryForm.Instance.videoPlayerForm.Pause();
|
||||
PrimaryForm.Instance.pauseButton.Visible = false;
|
||||
PrimaryForm.Instance.playButton.Visible = true;
|
||||
PrimaryForm.Instance.syncPauseButton.Visible = false;
|
||||
PrimaryForm.Instance.syncPlayButton.Visible = true;
|
||||
PrimaryForm.Instance.Invoke(new System.Action(() =>
|
||||
{
|
||||
PrimaryForm.Instance.videoPlayerForm.Pause();
|
||||
PrimaryForm.Instance.pauseButton.Visible = false;
|
||||
PrimaryForm.Instance.playButton.Visible = true;
|
||||
PrimaryForm.Instance.syncPauseButton.Visible = false;
|
||||
PrimaryForm.Instance.syncPlayButton.Visible = true;
|
||||
}));
|
||||
}
|
||||
break;
|
||||
case "volume_up":
|
||||
// 执行音量增大操作
|
||||
PrimaryForm.SendCommandThroughSerialPort("a2 b3 a4");
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() => {
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() =>
|
||||
{
|
||||
OverlayForm.MainForm.ShowVolumeUpLabel();
|
||||
PrimaryForm.Instance.volumeUpTimer.Start();
|
||||
OverlayForm.MainForm.HideAllLabels();
|
||||
PrimaryForm.Instance.volumeUpTimer.Stop();
|
||||
}));
|
||||
break;
|
||||
case "mic_up":
|
||||
// 执行麦克风增大操作
|
||||
PrimaryForm.SendCommandThroughSerialPort("a2 b5 a4");
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() => {
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() =>
|
||||
{
|
||||
OverlayForm.MainForm.ShowMicUpLabel();
|
||||
PrimaryForm.Instance.micControlTimer.Start();
|
||||
OverlayForm.MainForm.HideAllLabels();
|
||||
PrimaryForm.Instance.micControlTimer.Stop();
|
||||
}));
|
||||
break;
|
||||
case "mute":
|
||||
@ -485,15 +500,23 @@ namespace DualScreenDemo
|
||||
case "volume_down":
|
||||
// 执行音量减小操作
|
||||
PrimaryForm.SendCommandThroughSerialPort("a2 b4 a4");
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() => {
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() =>
|
||||
{
|
||||
OverlayForm.MainForm.ShowVolumeDownLabel();
|
||||
PrimaryForm.Instance.volumeDownTimer.Start();
|
||||
OverlayForm.MainForm.HideAllLabels();
|
||||
PrimaryForm.Instance.volumeDownTimer.Stop();
|
||||
}));
|
||||
break;
|
||||
case "mic_down":
|
||||
// 执行麦克风减小操作
|
||||
PrimaryForm.SendCommandThroughSerialPort("a2 b6 a4");
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() => {
|
||||
OverlayForm.MainForm.Invoke(new System.Action(() =>
|
||||
{
|
||||
OverlayForm.MainForm.ShowMicDownLabel();
|
||||
PrimaryForm.Instance.micControlTimer.Start();
|
||||
OverlayForm.MainForm.HideAllLabels();
|
||||
PrimaryForm.Instance.micControlTimer.Stop();
|
||||
}));
|
||||
break;
|
||||
case "original_song":
|
||||
|
@ -450,13 +450,13 @@ private static void SongDisplayTimer_Elapsed(object sender, EventArgs e)
|
||||
// 如果目前不在 UI 執行緒上,必須透過 Invoke 安全執行 UI 更新邏輯
|
||||
Console.WriteLine("SongDisplayTimer_Tick invoked on UI thread.");
|
||||
|
||||
MainForm.Invoke(new System.Action(() =>
|
||||
MainForm.BeginInvoke(new Action(() =>
|
||||
{
|
||||
// 清除目前歌曲的顯示標籤文字
|
||||
MainForm.songDisplayLabel.Text = "";
|
||||
if (MainForm.songDisplayLabel != null)
|
||||
MainForm.songDisplayLabel.Text = "";
|
||||
|
||||
// 顯示下一首歌的標籤
|
||||
MainForm.nextSongLabel.Visible = true;
|
||||
if (MainForm.nextSongLabel != null)
|
||||
MainForm.nextSongLabel.Visible = true;
|
||||
}));
|
||||
}
|
||||
else
|
||||
|
@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using NAudio.Wave;
|
||||
using WMPLib;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DualScreenDemo
|
||||
{
|
||||
@ -21,6 +25,28 @@ namespace DualScreenDemo
|
||||
{
|
||||
mediaPlayer = new WindowsMediaPlayer();
|
||||
}
|
||||
private void ConfigureImageButton(Button button, int posX, int posY, int width, int height,
|
||||
string imagePath, EventHandler clickEventHandler)
|
||||
{
|
||||
Bitmap image = new Bitmap(imagePath);
|
||||
button.SetBounds(posX, posY, image.Width, image.Height);
|
||||
|
||||
// 載入圖片
|
||||
button.BackgroundImage = image;
|
||||
button.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
|
||||
// 按鈕樣式設定
|
||||
button.FlatStyle = FlatStyle.Flat;
|
||||
button.FlatAppearance.BorderSize = 0;
|
||||
button.FlatAppearance.MouseDownBackColor = Color.Transparent;
|
||||
button.FlatAppearance.MouseOverBackColor = Color.Transparent;
|
||||
|
||||
// 點擊事件
|
||||
if (clickEventHandler != null)
|
||||
button.Click += clickEventHandler;
|
||||
|
||||
this.Controls.Add(button);
|
||||
}
|
||||
|
||||
private void InitializeSoundEffectButtons()
|
||||
{
|
||||
@ -29,9 +55,9 @@ namespace DualScreenDemo
|
||||
{
|
||||
Name = "constructionButton",
|
||||
};
|
||||
ConfigureButton(constructionButton, 876, 494, 148, 64,
|
||||
resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects,
|
||||
ConstructionButton_Click);
|
||||
string path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_工地.png");
|
||||
ConfigureImageButton(constructionButton, 1183, 634, 148, 64,
|
||||
path, ConstructionButton_Click);
|
||||
this.Controls.Add(constructionButton);
|
||||
|
||||
|
||||
@ -39,9 +65,9 @@ namespace DualScreenDemo
|
||||
{
|
||||
Name = "marketButton",
|
||||
};
|
||||
ConfigureButton(marketButton, 1037, 495, 148, 63,
|
||||
resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects,
|
||||
MarketButton_Click);
|
||||
path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_市場.png");
|
||||
ConfigureImageButton(marketButton, 1394, 634, 148, 63,
|
||||
path, MarketButton_Click);
|
||||
this.Controls.Add(marketButton);
|
||||
|
||||
|
||||
@ -49,9 +75,9 @@ namespace DualScreenDemo
|
||||
{
|
||||
Name = "drivingButton",
|
||||
};
|
||||
ConfigureButton(drivingButton, 876, 570, 148, 63,
|
||||
resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects,
|
||||
DrivingButton_Click);
|
||||
path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_開車.png");
|
||||
ConfigureImageButton(drivingButton, 1183, 720, 148, 63,
|
||||
path, DrivingButton_Click);
|
||||
this.Controls.Add(drivingButton);
|
||||
|
||||
|
||||
@ -59,9 +85,9 @@ namespace DualScreenDemo
|
||||
{
|
||||
Name = "airportButton",
|
||||
};
|
||||
ConfigureButton(airportButton, 1037, 570, 148, 63,
|
||||
resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects,
|
||||
AirportButton_Click);
|
||||
path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_機場.png");
|
||||
ConfigureImageButton(airportButton, 1394, 720, 148, 63,
|
||||
path, AirportButton_Click);
|
||||
this.Controls.Add(airportButton);
|
||||
|
||||
|
||||
@ -69,9 +95,9 @@ namespace DualScreenDemo
|
||||
{
|
||||
Name = "officeButton",
|
||||
};
|
||||
ConfigureButton(officeButton, 876, 646, 148, 64,
|
||||
resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects,
|
||||
OfficeButton_Click);
|
||||
path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_辦公室.png");
|
||||
ConfigureImageButton(officeButton, 1183, 806, 148, 64,
|
||||
path, OfficeButton_Click);
|
||||
this.Controls.Add(officeButton);
|
||||
|
||||
|
||||
@ -79,10 +105,9 @@ namespace DualScreenDemo
|
||||
{
|
||||
Name = "closeButton",
|
||||
};
|
||||
|
||||
ConfigureButton(closeButton, 1036, 646, 150, 63,
|
||||
resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects, resizedNormalStateImageForSceneSoundEffects,
|
||||
CloseButton_Click);
|
||||
path = Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效_關閉.png");
|
||||
ConfigureImageButton(closeButton, 1394, 806, 150, 63,
|
||||
path, CloseButton_Click);
|
||||
this.Controls.Add(closeButton);
|
||||
}
|
||||
|
||||
@ -96,7 +121,7 @@ namespace DualScreenDemo
|
||||
|
||||
if (!pictureBoxSceneSoundEffects.Visible)
|
||||
{
|
||||
ShowImageOnPictureBoxSceneSoundEffects(Path.Combine(Application.StartupPath, @"themes\superstar\555022.jpg"));
|
||||
ShowImageOnPictureBoxSceneSoundEffects(Path.Combine(Application.StartupPath, @"themes\superstar\場景音效\場景音效.png"));
|
||||
SetPictureBoxSceneSoundEffectsAndButtonsVisibility(true);
|
||||
}
|
||||
else
|
||||
@ -131,28 +156,30 @@ namespace DualScreenDemo
|
||||
|
||||
public void PlayApplauseSound()
|
||||
{
|
||||
mediaPlayer.URL = Path.Combine(Application.StartupPath, "sounds", "zs.m4a");
|
||||
mediaPlayer.URL = Path.Combine(Application.StartupPath,"sounds" ,"zs.m4a");
|
||||
mediaPlayer.controls.play();
|
||||
}
|
||||
|
||||
// 按鈕位置需要更改,底圖需要更改
|
||||
private void ShowImageOnPictureBoxSceneSoundEffects(string imagePath)
|
||||
{
|
||||
|
||||
Bitmap originalImage = new Bitmap(imagePath);
|
||||
if (File.Exists(imagePath))
|
||||
{
|
||||
// 直接載入完整圖
|
||||
Bitmap image = new Bitmap(imagePath);
|
||||
|
||||
// 顯示在 PictureBox 上
|
||||
pictureBoxSceneSoundEffects.Image = image;
|
||||
|
||||
Rectangle cropArea = new Rectangle(859, 427, 342, 295);
|
||||
// 設定 PictureBox 的大小與位置(依你的需要調整)
|
||||
ResizeAndPositionPictureBox(pictureBoxSceneSoundEffects, 850, 450, image.Width , image.Height);
|
||||
|
||||
|
||||
Bitmap croppedImage = CropImage(originalImage, cropArea);
|
||||
|
||||
|
||||
pictureBoxSceneSoundEffects.Image = croppedImage;
|
||||
|
||||
|
||||
ResizeAndPositionPictureBox(pictureBoxSceneSoundEffects, cropArea.X, cropArea.Y, cropArea.Width, cropArea.Height);
|
||||
|
||||
pictureBoxSceneSoundEffects.Visible = true;
|
||||
pictureBoxSceneSoundEffects.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("圖片檔案不存在:" + imagePath);
|
||||
}
|
||||
}
|
||||
|
||||
private void TogglePictureBoxSceneSoundEffectsButtonsVisibility()
|
||||
|
@ -116,18 +116,19 @@ namespace DualScreenDemo
|
||||
}
|
||||
|
||||
|
||||
private void VodButton_Click(object sender, EventArgs e)
|
||||
private async void VodButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
OverlayForm.MainForm.AddSongToPlaylist(currentSelectedSong);
|
||||
SetVodScreenPictureBoxAndButtonsVisibility(false);
|
||||
await Task.Delay(1000);
|
||||
OverlayForm.MainForm.AddSongToPlaylist(currentSelectedSong);
|
||||
|
||||
}
|
||||
|
||||
private void InsertButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
OverlayForm.MainForm.InsertSongToPlaylist(currentSelectedSong);
|
||||
SetVodScreenPictureBoxAndButtonsVisibility(false);
|
||||
OverlayForm.MainForm.InsertSongToPlaylist(currentSelectedSong);
|
||||
|
||||
}
|
||||
|
||||
private void AlbumButton_Click(object sender, EventArgs e)
|
||||
|
@ -242,6 +242,23 @@ namespace DualScreenDemo
|
||||
LoadConnectionStringFromFile("test.env");
|
||||
|
||||
}
|
||||
public bool IsAppResponsive()
|
||||
{
|
||||
try
|
||||
{
|
||||
var form = this;
|
||||
if (form != null)
|
||||
{
|
||||
bool dummy = form.InvokeRequired; // 如果 Invoke 卡死,會丟錯
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 添加 DPI 感知支持
|
||||
[DllImport("user32.dll")]
|
||||
@ -940,12 +957,12 @@ namespace DualScreenDemo
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Failed to send command: " + ex.Message);
|
||||
Console.WriteLine("Failed to send command: " + ex.Message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Serial port is not open.");
|
||||
Console.WriteLine("Serial port is not open.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1560,7 +1577,7 @@ namespace DualScreenDemo
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 比較本地和服務器文件夾
|
||||
// 2. 確認本地文件夾是否存在(不存在則創立)
|
||||
if (!Directory.Exists(localVideoPath))
|
||||
{
|
||||
Directory.CreateDirectory(localVideoPath);
|
||||
@ -1575,7 +1592,7 @@ namespace DualScreenDemo
|
||||
.Select(f => new FileInfo(f))
|
||||
.ToDictionary(f => f.Name, f => f);
|
||||
|
||||
// 3. 檢查並更新文件
|
||||
// 3-1. 檢查並更新文件
|
||||
foreach (var serverFile in serverFiles)
|
||||
{
|
||||
bool needsCopy = false;
|
||||
@ -1607,7 +1624,22 @@ namespace DualScreenDemo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3-2. 清除本地有但伺服器已經沒有的檔案
|
||||
foreach (var localFile in localFiles)
|
||||
{
|
||||
if (!serverFiles.ContainsKey(localFile.Key))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(localFile.Value.FullName);
|
||||
Console.WriteLine($"刪除本地多餘影片: {localFile.Key}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"刪除影片失敗 {localFile.Key}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 4. 載入更新後的本地文件
|
||||
LoadLocalVideoFiles();
|
||||
}
|
||||
@ -2061,14 +2093,14 @@ namespace DualScreenDemo
|
||||
videoPlayerForm.ReplayCurrentSong();
|
||||
}
|
||||
|
||||
private void PauseButton_Click(object sender, EventArgs e)
|
||||
public void PauseButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
videoPlayerForm.Pause();
|
||||
pauseButton.Visible = false;
|
||||
playButton.Visible = true;
|
||||
}
|
||||
|
||||
private void PlayButton_Click(object sender, EventArgs e)
|
||||
public void PlayButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
videoPlayerForm.Play();
|
||||
playButton.Visible = false;
|
||||
|
46
Program.cs
46
Program.cs
@ -2,7 +2,7 @@ using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using System.Diagnostics;
|
||||
using DBObj;
|
||||
using HeartbeatSender;
|
||||
using DataCheck;
|
||||
|
||||
namespace DualScreenDemo
|
||||
{
|
||||
@ -17,15 +17,27 @@ namespace DualScreenDemo
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
|
||||
|
||||
Console.WriteLine("隱藏滑鼠游標");
|
||||
// Cursor.Hide();
|
||||
Cursor.Hide();
|
||||
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
|
||||
{
|
||||
Cursor.Show();
|
||||
};
|
||||
Console.WriteLine("正在喚醒SVR裝置(每3分鐘呼叫一次)...");
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
_ = Directory.Exists(@"\\svr01\video");
|
||||
_ = Directory.Exists(@"\\svr02\video");
|
||||
await Task.Delay(180000); // 每3min送一次
|
||||
}
|
||||
});
|
||||
|
||||
Console.WriteLine("正在與中控取得聯繫");
|
||||
/*var sender = new HeartbeatSender.heartbeatSender();
|
||||
// Console.WriteLine("正在與中控取得聯繫...");
|
||||
var sender = new HeartbeatSender.heartbeatSender();
|
||||
|
||||
// 同步呼叫非同步登入取得 token
|
||||
bool loginSuccess = sender.LoginAndGetTokenAsync().GetAwaiter().GetResult();
|
||||
@ -35,21 +47,26 @@ namespace DualScreenDemo
|
||||
// 先送一次心跳 (同步呼叫)
|
||||
sender.SendHeartbeatAsync().GetAwaiter().GetResult();
|
||||
|
||||
// 背景持續每3秒送心跳
|
||||
// 背景持續每5分鐘送心跳
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
await sender.SendHeartbeatAsync();
|
||||
await Task.Delay(300000); // 每3秒送一次
|
||||
await Task.Delay(300000); // 每5min送一次
|
||||
}
|
||||
});
|
||||
Console.WriteLine("正在發送心跳中...");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("登入失敗,無法送出心跳");
|
||||
}
|
||||
*/
|
||||
//之後需要做添加同步菜單+酒單+背景圖(若圖規格有做正規化)
|
||||
// DataCheck.cs 有預寫好相關流程函式
|
||||
Console.WriteLine("更新菜單和酒單...");
|
||||
dataCheck Checkprocess = new dataCheck();
|
||||
|
||||
try
|
||||
{
|
||||
// COM 初始化
|
||||
@ -62,7 +79,7 @@ namespace DualScreenDemo
|
||||
// 初始化管理器
|
||||
|
||||
songListManager = new SongListManager(); // 使用单例
|
||||
//artistManager = new ArtistManager();
|
||||
//artistManager = new ArtistManager();
|
||||
|
||||
var commandHandler = new CommandHandler(songListManager);
|
||||
serialPortManager = new SerialPortManager(commandHandler);
|
||||
@ -106,9 +123,22 @@ namespace DualScreenDemo
|
||||
primaryForm.ShowSendOffScreen();
|
||||
};
|
||||
}
|
||||
WatchDog _watchDog = new WatchDog(
|
||||
() => VideoPlayerForm.Instance.GetCurrentVideoStatus(),
|
||||
() => primaryForm.IsAppResponsive()
|
||||
);
|
||||
_watchDog.Start();
|
||||
Console.WriteLine("啟動WatchDog進行監聽");
|
||||
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
|
||||
{
|
||||
_watchDog.Stop();
|
||||
};
|
||||
|
||||
|
||||
primaryForm.Show();
|
||||
Application.Run(primaryForm);
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.IO.Ports;
|
||||
using System.Text;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace DualScreenDemo
|
||||
{
|
||||
@ -48,19 +49,27 @@ namespace DualScreenDemo
|
||||
|
||||
// 綁定資料接收事件
|
||||
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
|
||||
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
|
||||
{
|
||||
cts.Cancel();
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
mySerialPort.Open();
|
||||
Console.WriteLine($"{selectedPort} 串列埠已成功開啟。");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"開啟 {selectedPort} 串列埠時發生錯誤: {ex.Message}");
|
||||
}
|
||||
{
|
||||
mySerialPort.Open();
|
||||
Console.WriteLine($"{selectedPort} 串列埠已成功開啟。");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"開啟 {selectedPort} 串列埠時發生錯誤: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private readonly ConcurrentQueue<string> commandQueue = new();
|
||||
public readonly CancellationTokenSource cts = new();
|
||||
private bool isProcessing = false;
|
||||
|
||||
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
|
||||
{
|
||||
try
|
||||
@ -68,19 +77,14 @@ namespace DualScreenDemo
|
||||
SerialPort sp = (SerialPort)sender;
|
||||
|
||||
if (!sp.IsOpen)
|
||||
{
|
||||
// Console.WriteLine("串列埠未開啟,無法接收資料。");
|
||||
return;
|
||||
}
|
||||
|
||||
int bytesToRead = sp.BytesToRead;
|
||||
if (bytesToRead > 0)
|
||||
{
|
||||
|
||||
byte[] buffer = new byte[bytesToRead];
|
||||
int bytesRead = sp.Read(buffer, 0, bytesToRead);
|
||||
|
||||
|
||||
StringBuilder hexData = new StringBuilder(bytesRead * 2);
|
||||
for (int i = 0; i < bytesRead; i++)
|
||||
{
|
||||
@ -88,31 +92,46 @@ namespace DualScreenDemo
|
||||
}
|
||||
|
||||
string indata = hexData.ToString();
|
||||
// Console.WriteLine($"接收到的資料 (Hex): {indata}");
|
||||
|
||||
Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] 遙控器: {indata}");
|
||||
|
||||
Task.Run(() =>
|
||||
// 將資料放入佇列
|
||||
commandQueue.Enqueue(indata);
|
||||
|
||||
// 如果尚未啟動處理迴圈,則啟動
|
||||
if (!isProcessing)
|
||||
{
|
||||
try
|
||||
{
|
||||
commandHandler.ProcessData(indata);
|
||||
}
|
||||
catch (Exception processEx)
|
||||
{
|
||||
Console.WriteLine($"處理資料時發生錯誤: {processEx.Message}");
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Console.WriteLine("未接收到任何資料。");
|
||||
isProcessing = true;
|
||||
Task.Run(ProcessQueueAsync);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"接收資料時發生錯誤: {ex.Message}");
|
||||
Console.WriteLine($"接收資料時發生錯誤: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private async Task ProcessQueueAsync()
|
||||
{
|
||||
while (!cts.Token.IsCancellationRequested)
|
||||
{
|
||||
while (commandQueue.TryDequeue(out var cmd))
|
||||
{
|
||||
try
|
||||
{
|
||||
commandHandler.ProcessData(cmd);
|
||||
}
|
||||
catch (Exception processEx)
|
||||
{
|
||||
Console.WriteLine($"處理資料時發生錯誤: {processEx.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(10); // 避免 CPU 空轉
|
||||
}
|
||||
cts.Cancel();
|
||||
isProcessing = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -3,6 +3,8 @@ using System.Runtime.InteropServices;
|
||||
using DirectShowLib;
|
||||
using DBObj;
|
||||
using OverlayFormObj;
|
||||
using DualScreenDemo.Shared;
|
||||
|
||||
namespace DualScreenDemo
|
||||
{
|
||||
public class VideoPlayerForm : Form
|
||||
@ -394,7 +396,7 @@ namespace DualScreenDemo
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Exception in AddFilterByClsid: {ex.Message}");
|
||||
Console.WriteLine($"Exception in AddFilterByClsid: {ex.Message}");
|
||||
throw; // Rethrow the exception to handle it further up the call stack
|
||||
}
|
||||
}
|
||||
@ -456,10 +458,12 @@ namespace DualScreenDemo
|
||||
int newHeight = (int)(designHeight * scale);
|
||||
|
||||
// trash location with trash flexible of screen size.
|
||||
if (actualWidth == 1024){
|
||||
if (actualWidth == 1024)
|
||||
{
|
||||
newWidth = (int)(newWidth * 0.84f);
|
||||
}
|
||||
else if (actualWidth == 1440){
|
||||
else if (actualWidth == 1440)
|
||||
{
|
||||
newWidth = (int)(newWidth * 0.9f);
|
||||
}
|
||||
videoWindowPrimary = (IVideoWindow)videoRendererPrimary;
|
||||
@ -479,7 +483,7 @@ namespace DualScreenDemo
|
||||
MessageBox.Show(String.Format("Error syncing to primary monitor: {0}", ex.Message));
|
||||
}
|
||||
}
|
||||
public void ClosePrimaryScreenPanel()
|
||||
public void ClosePrimaryScreenPanel()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -609,7 +613,7 @@ namespace DualScreenDemo
|
||||
if (File.Exists(welcomePath))
|
||||
{
|
||||
publicPlaylist.Add(new SongData(
|
||||
"0", "歡迎光臨", "", "","", welcomePath,
|
||||
"0", "歡迎光臨", "", "", "", welcomePath,
|
||||
"", "", "", "", 1
|
||||
));
|
||||
}
|
||||
@ -622,7 +626,7 @@ namespace DualScreenDemo
|
||||
{
|
||||
publicPlaylist.Add(new SongData(
|
||||
i.ToString(), $"背景音樂{i:D2}",
|
||||
"", "", "",bgmPath, "", "", "", "", 1
|
||||
"", "", "", bgmPath, "", "", "", "", 1
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -678,7 +682,8 @@ namespace DualScreenDemo
|
||||
|
||||
if (overlayForm.InvokeRequired)
|
||||
{
|
||||
overlayForm.Invoke(new MethodInvoker(() => {
|
||||
overlayForm.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
overlayForm.UpdateMarqueeText(nextSongText, OverlayForm.MarqueeStartPosition.Middle, Color.White);
|
||||
}));
|
||||
}
|
||||
@ -691,7 +696,8 @@ namespace DualScreenDemo
|
||||
// 重置跑马灯文本
|
||||
if (overlayForm.InvokeRequired)
|
||||
{
|
||||
overlayForm.Invoke(new MethodInvoker(() => {
|
||||
overlayForm.Invoke(new MethodInvoker(() =>
|
||||
{
|
||||
overlayForm.ResetMarqueeTextToWelcomeMessage();
|
||||
}));
|
||||
}
|
||||
@ -760,30 +766,30 @@ namespace DualScreenDemo
|
||||
}
|
||||
|
||||
|
||||
// 可以取得 燈控/聲控 的位置
|
||||
var songToPlay = currentPlaylist[currentSongIndex];
|
||||
// 可以取得 燈控/聲控 的位置
|
||||
var songToPlay = currentPlaylist[currentSongIndex];
|
||||
|
||||
// pathToPlay 需要調整
|
||||
var pathToPlay = File.Exists(songToPlay.SongFilePathHost1) ? songToPlay.SongFilePathHost1 : songToPlay.SongFilePathHost2;
|
||||
// pathToPlay 需要調整
|
||||
var pathToPlay = File.Exists(songToPlay.SongFilePathHost1) ? songToPlay.SongFilePathHost1 : songToPlay.SongFilePathHost2;
|
||||
|
||||
// 若兩個 host 上都找不到檔案就直接結束
|
||||
if (!File.Exists(pathToPlay))
|
||||
{
|
||||
Console.WriteLine($"文件不存在:{pathToPlay}");
|
||||
return;
|
||||
}
|
||||
// 若兩個 host 上都找不到檔案就直接結束
|
||||
if (!File.Exists(pathToPlay))
|
||||
{
|
||||
Console.WriteLine($"文件不存在:{pathToPlay}");
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新目前正在播放的歌曲
|
||||
currentPlayingSong = songToPlay;
|
||||
// 更新目前正在播放的歌曲
|
||||
currentPlayingSong = songToPlay;
|
||||
|
||||
// 更新畫面上顯示的下一首歌資訊
|
||||
UpdateNextSongFromPlaylist();
|
||||
// 更新畫面上顯示的下一首歌資訊
|
||||
UpdateNextSongFromPlaylist();
|
||||
|
||||
// 顯示 QRCode(可能是點歌頁用)
|
||||
overlayForm.DisplayQRCodeOnOverlay(HttpServer.randomFolderPath);
|
||||
// 顯示 QRCode(可能是點歌頁用)
|
||||
overlayForm.DisplayQRCodeOnOverlay(HttpServer.randomFolderPath);
|
||||
|
||||
// 隱藏「暫停中」標籤
|
||||
overlayForm.HidePauseLabel();
|
||||
// 隱藏「暫停中」標籤
|
||||
overlayForm.HidePauseLabel();
|
||||
|
||||
|
||||
try
|
||||
@ -931,8 +937,9 @@ namespace DualScreenDemo
|
||||
/*如果當前為公播,不可以+1*/
|
||||
bool isPlayingPublicList = PrimaryForm.userRequestedSongs.Count == 0 ||
|
||||
(PrimaryForm.currentSongIndexInHistory >= PrimaryForm.userRequestedSongs.Count - 1 && PrimaryForm.Instance.videoPlayerForm.IsPlayingPublicSong);
|
||||
if(!isPlayingPublicList){
|
||||
PrimaryForm.currentSongIndexInHistory+=1;
|
||||
if (!isPlayingPublicList)
|
||||
{
|
||||
PrimaryForm.currentSongIndexInHistory += 1;
|
||||
}
|
||||
Console.WriteLine("currentSongIndexInHistory : " + PrimaryForm.currentSongIndexInHistory);
|
||||
}
|
||||
@ -1533,7 +1540,7 @@ namespace DualScreenDemo
|
||||
return -10000;
|
||||
}
|
||||
private bool isVocalRemoved = false;
|
||||
public async void ToggleVocalRemoval()
|
||||
public async void ToggleVocalRemoval()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -1602,7 +1609,7 @@ namespace DualScreenDemo
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine( ex.Message);
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1649,7 +1656,7 @@ namespace DualScreenDemo
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine( ex.Message);
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1817,5 +1824,67 @@ namespace DualScreenDemo
|
||||
Console.WriteLine("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public VideoStatus GetCurrentVideoStatus()
|
||||
{
|
||||
var status = new VideoStatus();
|
||||
try
|
||||
{
|
||||
IMediaSeeking mediaSeekingSecondary = graphBuilderSecondary as IMediaSeeking;
|
||||
if (mediaSeekingSecondary != null)
|
||||
{
|
||||
long position;
|
||||
if (mediaSeekingSecondary.GetCurrentPosition(out position) >= 0)
|
||||
{
|
||||
status.PositionSeconds = position / 10000000.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
status.LastError = "無法取得影片播放位置";
|
||||
status.PositionSeconds = -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status.LastError = "mediaSeekingSecondary 物件為 null";
|
||||
status.PositionSeconds = -1;
|
||||
}
|
||||
|
||||
if (mediaControlSecondary != null)
|
||||
{
|
||||
FilterState stateCode;
|
||||
int hr = mediaControlSecondary.GetState(100, out stateCode);
|
||||
if (hr >= 0)
|
||||
{
|
||||
var state = (FilterState)stateCode;
|
||||
status.PlayState = state.ToString();
|
||||
status.IsGraphOk = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
status.PlayState = "無法取得播放狀態";
|
||||
status.IsGraphOk = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status.PlayState = "mediaControlSecondary 物件為 null";
|
||||
status.IsGraphOk = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
status.LastError = "取得影片狀態時發生例外:" + ex.Message;
|
||||
status.PositionSeconds = -1;
|
||||
status.PlayState = "Error";
|
||||
status.IsGraphOk = false;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
84
WatchDog.cs
Normal file
84
WatchDog.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DualScreenDemo.Shared;
|
||||
public class WatchDog
|
||||
{
|
||||
|
||||
private Func<VideoStatus> getVideoStatus;
|
||||
private Func<bool> isApplicationResponsive;
|
||||
private Thread watchdogThread;
|
||||
private bool running = false;
|
||||
private double lastPosition = -1;
|
||||
private int freezeCounter = 0;
|
||||
|
||||
public WatchDog(Func<VideoStatus> getVideoPositionFunc, Func<bool> isAppResponsiveFunc)
|
||||
{
|
||||
getVideoStatus = getVideoPositionFunc;
|
||||
isApplicationResponsive = isAppResponsiveFunc;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
running = true;
|
||||
watchdogThread = new Thread(Run);
|
||||
watchdogThread.IsBackground = true;
|
||||
watchdogThread.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
running = false;
|
||||
watchdogThread?.Join();
|
||||
}
|
||||
|
||||
private void Run()
|
||||
{
|
||||
while (running)
|
||||
{
|
||||
var status = getVideoStatus(); // 改用 getVideoStatus 取得完整狀態
|
||||
bool responsive = isApplicationResponsive();
|
||||
|
||||
if (!status.IsGraphOk)
|
||||
{
|
||||
Log($"影片圖表異常: {status.LastError}");
|
||||
}
|
||||
else if(status.PlayState != "Paused")
|
||||
{
|
||||
double currentPosition = status.PositionSeconds;
|
||||
|
||||
if (Math.Abs(currentPosition - lastPosition) < 0.001)
|
||||
{
|
||||
freezeCounter++;
|
||||
if (freezeCounter >= 3)
|
||||
{
|
||||
Log($"影片疑似卡死(3次位置沒變):位置={currentPosition:F2}秒,播放狀態={status.PlayState}");
|
||||
freezeCounter = 0; // 記得 reset
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
freezeCounter = 0;
|
||||
}
|
||||
|
||||
lastPosition = currentPosition;
|
||||
}
|
||||
|
||||
if (!responsive)
|
||||
{
|
||||
Log("UI 疑似卡死(Invoke 失敗)");
|
||||
}
|
||||
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Log(string message)
|
||||
{
|
||||
string logFilePath = Path.Combine("txt", "watchdog_log.txt");
|
||||
File.AppendAllText(logFilePath, $"{DateTime.Now}: {message}{Environment.NewLine}");
|
||||
}
|
||||
}
|
@ -350,15 +350,15 @@
|
||||
const row = document.createElement('tr');
|
||||
const songNameCell = document.createElement('td');
|
||||
const singerCell = document.createElement('td');
|
||||
const languageCell = document.createElement('td');
|
||||
// const languageCell = document.createElement('td');
|
||||
|
||||
songNameCell.textContent = song.Song;
|
||||
singerCell.textContent = song.ArtistA;
|
||||
languageCell.textContent = song.Category;
|
||||
// languageCell.textContent = song.Category;
|
||||
|
||||
row.appendChild(songNameCell);
|
||||
row.appendChild(singerCell);
|
||||
row.appendChild(languageCell);
|
||||
// row.appendChild(languageCell);
|
||||
|
||||
row.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
@ -369,7 +369,7 @@
|
||||
document.getElementById('detail-song-name').textContent = song.Song;
|
||||
document.getElementById('detail-song-number').textContent = song.SongNumber;
|
||||
document.getElementById('detail-singer').textContent = song.ArtistA;
|
||||
document.getElementById('detail-language').textContent = song.Category;
|
||||
// document.getElementById('detail-language').textContent = song.Category;
|
||||
|
||||
document.getElementById('song-details').style.display = 'block';
|
||||
});
|
||||
|
@ -80,26 +80,20 @@
|
||||
}
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr); /* 固定3欄 */
|
||||
gap: 5px; /* 移除格子之間的空隙 */
|
||||
margin: 0; /* 沒有外邊距 */
|
||||
padding: 0; /* 沒有內邊距 */
|
||||
width: 36.5vw; /* 滿版寬度 */
|
||||
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
|
||||
gap: 5px;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.content {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr); /* 固定3欄 */
|
||||
gap: 5px; /* 移除格子之間的空隙 */
|
||||
margin: 0; /* 沒有外邊距 */
|
||||
padding: 0; /* 沒有內邊距 */
|
||||
width: 78vw; /* 滿版寬度 */
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 5px;
|
||||
}
|
||||
}
|
||||
.card {
|
||||
background: linear-gradient(135deg, #FF4081, #FF4081);
|
||||
color: white;
|
||||
width: 130px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
Loading…
x
Reference in New Issue
Block a user