調整 多餘資料 20250721

This commit is contained in:
jasonchenwork 2025-07-21 18:36:09 +08:00
parent e1d7653a1a
commit 36ab52bac1
17 changed files with 98 additions and 300 deletions

View File

@ -1,12 +0,0 @@
namespace DualScreenDemo
{
public enum ClickSequenceState
{
Initial,
FirstClicked,
SecondClicked,
ThirdClicked,
Completed
}
}

View File

@ -540,8 +540,9 @@ namespace DualScreenDemo
ClearDisplay(); ClearDisplay();
// 設定歌曲總數為已播放歌曲的數量 // 設定歌曲總數為已播放歌曲的數量
List<SongData> historySongs = SongList.GetHistory(); List<SongData> history= SongList.GetHistory();
OverlayForm.MainForm.totalSongs = historySongs.Count; List<SongData> historySongs = new List<SongData>();
OverlayForm.MainForm.totalSongs = SongList.GetHistory().Count;
// 若無任何播放紀錄,直接顯示訊息並返回,不執行後續動作 // 若無任何播放紀錄,直接顯示訊息並返回,不執行後續動作
if (OverlayForm.MainForm.totalSongs == 0) if (OverlayForm.MainForm.totalSongs == 0)
@ -558,6 +559,9 @@ namespace DualScreenDemo
int endIndex = Math.Min(startIndex + OverlayForm.MainForm.songsPerPage, OverlayForm.MainForm.totalSongs); int endIndex = Math.Min(startIndex + OverlayForm.MainForm.songsPerPage, OverlayForm.MainForm.totalSongs);
// 準備要傳給 UpdateHistoryLabel 的兩個清單:歌曲資料與播放狀態 // 準備要傳給 UpdateHistoryLabel 的兩個清單:歌曲資料與播放狀態
for (int i = startIndex; i < endIndex; i++) {
historySongs.Add(history[i]);
}
// 錨點 遙控器 // 錨點 遙控器

59
DBObj/MyDB.cs Normal file
View File

@ -0,0 +1,59 @@
using System;
using System.Data;
using MySqlConnector;
namespace DBObj
{
public class MyDB : IDisposable
{
private readonly string connectionString = Utils.Env.GetDBConnection();
private MySqlConnection conn;
public MyDB()
{
conn = new MySqlConnection(connectionString);
conn.Open();
Console.WriteLine("MyDB 連線成功!");
}
public void Dispose()
{
if (conn != null)
{
conn.Close();
Console.WriteLine("MyDB 連線已關閉!");
}
}
// SELECT 方法
public DataTable Select(string query, MySqlParameter[] parameters)
{
using (var cmd = new MySqlCommand(query, conn))
{
if (parameters != null)
{
cmd.Parameters.AddRange(parameters);
}
using (var adapter = new MySqlDataAdapter(cmd))
{
DataTable result = new DataTable();
adapter.Fill(result);
return result;
}
}
}
// INSERT / UPDATE / DELETE 方法
public int ExecuteNonQuery(string query, MySqlParameter[] parameters)
{
using (var cmd = new MySqlCommand(query, conn))
{
if (parameters != null)
{
cmd.Parameters.AddRange(parameters);
}
return cmd.ExecuteNonQuery();
}
}
}
}

View File

@ -1,9 +1,11 @@
using System.Data;
using DualScreenDemo; using DualScreenDemo;
namespace DBObj namespace DBObj
{ {
public class SongListManager public class SongListManager
{ {
public List<SongData> FavoriteSongs { get; private set; } private MyDB db = new MyDB();
public List<SongData> FavoriteSongs { get; private set; }
//public bool IsUserLoggedIn { get; set; } //public bool IsUserLoggedIn { get; set; }
//public string UserPhoneNumber { get; set; } //public string UserPhoneNumber { get; set; }
public SongListManager() public SongListManager()
@ -76,6 +78,32 @@ namespace DBObj
var searchResults =PrimaryForm.Instance.SearchSongs_Mysql(query); var searchResults =PrimaryForm.Instance.SearchSongs_Mysql(query);
return searchResults.FirstOrDefault(); return searchResults.FirstOrDefault();
} }
private List<SongData> select_Mysql(string query)
{
List<SongData> searchResults = new List<SongData>();
Console.WriteLine(query);
using (db)
{
DataTable result = db.Select(query, null);
foreach (DataRow row in result.Rows)
{
searchResults.Add(new SongData(
row["song_id"].ToString(),
row["song_name"].ToString(),
row["artistA"].ToString(),
row["artistB"].ToString(),
row["song_filename"].ToString(),
row["artistA_simplified"].ToString(),
row["artistB_simplified"].ToString(),
row["song_simplified"].ToString(),
Convert.ToInt32(row["vocal"])
));
}
Console.WriteLine($"查詢到 {searchResults.Count} 筆資料。");
}
return searchResults;
}
} }
} }

View File

@ -1,10 +0,0 @@
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; }
}
}

View File

@ -1,52 +0,0 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using DirectShowLib;
namespace DualScreenDemo
{
public class FilterEnumerator
{
private static readonly Guid IID_IPropertyBag = new Guid("55272A00-42CB-11CE-8135-00AA004BB851");
public void EnumerateFilters()
{
ICreateDevEnum createDevEnum = (ICreateDevEnum)new CreateDevEnum();
IEnumMoniker enumMoniker;
int hr = createDevEnum.CreateClassEnumerator(FilterCategory.LegacyAmFilterCategory, out enumMoniker, 0);
if (hr != 0 || enumMoniker == null)
{
Console.WriteLine("No filters found.");
return;
}
IMoniker[] monikers = new IMoniker[1];
IntPtr fetched = Marshal.AllocHGlobal(sizeof(int));
while (enumMoniker.Next(1, monikers, fetched) == 0)
{
int fetchedCount = Marshal.ReadInt32(fetched);
if (fetchedCount > 0)
{
object objPropBag;
Guid tempGuid = IID_IPropertyBag;
monikers[0].BindToStorage(null, null, ref tempGuid, out objPropBag);
IPropertyBag propBag = objPropBag as IPropertyBag;
object filterName = null;
if (propBag != null)
{
propBag.Read("FriendlyName", out filterName, null);
}
if (filterName != null)
{
Console.WriteLine("Filter: " + filterName.ToString());
}
Marshal.ReleaseComObject(monikers[0]);
}
}
Marshal.ReleaseComObject(enumMoniker);
Marshal.FreeHGlobal(fetched);
}
}
}

View File

@ -1,8 +0,0 @@
namespace DualScreenDemo
{
public static class FormatTypes
{
public static readonly Guid VideoInfo = new Guid("05589F80-C356-11CE-BF01-00AA0055595A");
public static readonly Guid WaveEx = new Guid("05589f81-c356-11ce-bf01-00aa0055595a");
}
}

View File

@ -1,5 +0,0 @@
public static class MediaSubTypes
{
public static readonly Guid YUY2 = new Guid("32595559-0000-0010-8000-00AA00389B71");
public static readonly Guid IEEE_FLOAT = new Guid("00000003-0000-0010-8000-00AA00389B71");
}

View File

@ -1,8 +0,0 @@
namespace DualScreenDemo
{
public static class MediaTypes
{
public static readonly Guid Video = new Guid("73646976-0000-0010-8000-00AA00389B71");
public static readonly Guid Audio = new Guid("73647561-0000-0010-8000-00AA00389B71");
}
}

View File

@ -7,7 +7,7 @@ namespace OverlayFormObj
public partial class OverlayForm public partial class OverlayForm
{ {
public Label displayLabel; public Label displayLabel;
public Label songDisplayLabel; //public Label songDisplayLabel;
private List<Label> displayLabels; private List<Label> displayLabels;
public Label pauseLabel; public Label pauseLabel;
public Label muteLabel; // New mute label public Label muteLabel; // New mute label

View File

@ -17,7 +17,7 @@ namespace DualScreenDemo
[STAThread] [STAThread]
static void Main() static void Main()
{ {
Console.WriteLine("Server V.1.2.3 202507211300"); Console.WriteLine("Server V.1.2.3 202507211828");
if (Utils.Env.GetBool("IsCursor", true)) Cursor.Hide(); if (Utils.Env.GetBool("IsCursor", true)) Cursor.Hide();
AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show(); AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show();
//Console.WriteLine("正在與中控取得聯繫..."); //Console.WriteLine("正在與中控取得聯繫...");
@ -49,7 +49,7 @@ namespace DualScreenDemo
} }
// 啟動服務器 // 啟動服務器
var TCP = new TCPServer();
Task.Run(() => HttpServerManager.StartServer()); Task.Run(() => HttpServerManager.StartServer());
// 註冊事件 // 註冊事件
@ -88,8 +88,6 @@ namespace DualScreenDemo
} }
primaryForm.Show(); primaryForm.Show();
Application.Run(primaryForm); Application.Run(primaryForm);
var TCP = new TCPServer();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -1,12 +0,0 @@
namespace DualScreenDemo
{
public enum RemoteCommand
{
NextPage,
PreviousPage,
Play,
Pause,
Stop
}
}

View File

@ -1,7 +0,0 @@
namespace DualScreenDemo
{
public class RemoteControlEventArgs : EventArgs
{
public RemoteCommand Command { get; set; }
}
}

View File

@ -1,8 +0,0 @@
namespace DualScreenDemo
{
public class RequestData
{
public string buttonId { get; set; }
public string text { get; set; }
}
}

View File

@ -1,26 +0,0 @@
using DirectShowLib;
namespace DualScreenDemo
{
public class SampleGrabberCallback : ISampleGrabberCB
{
private VideoPlayerForm form;
public SampleGrabberCallback(VideoPlayerForm form)
{
this.form = form;
}
public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
return 0;
}
public int SampleCB(double SampleTime, IMediaSample pSample)
{
return 0;
}
}
}

View File

@ -3,7 +3,6 @@ using System.Runtime.InteropServices;
using DirectShowLib; using DirectShowLib;
using DBObj; using DBObj;
using OverlayFormObj; using OverlayFormObj;
using DualScreenDemo.Shared;
namespace DualScreenDemo namespace DualScreenDemo
{ {
public class VideoPlayerForm : Form public class VideoPlayerForm : Form
@ -131,26 +130,7 @@ namespace DualScreenDemo
} }
CheckMonitor(); CheckMonitor();
} }
/*
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
try
{
if (secondMonitor != null)
{
SetWindowPos(this.Handle, IntPtr.Zero, secondMonitor.Bounds.X, secondMonitor.Bounds.Y,
secondMonitor.Bounds.Width, secondMonitor.Bounds.Height, 0);
}
IntPtr exStyle = GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, (IntPtr)(exStyle.ToInt32()));
}
catch (Exception ex)
{
Console.WriteLine("An error occurred in OnShown: " + ex.Message);
}
}
*/
private void VideoPlayerForm_Shown(object sender, EventArgs e) private void VideoPlayerForm_Shown(object sender, EventArgs e)
{ {
int hr = CoInitializeEx(IntPtr.Zero, COINIT.APARTMENTTHREADED); int hr = CoInitializeEx(IntPtr.Zero, COINIT.APARTMENTTHREADED);
@ -284,23 +264,6 @@ namespace DualScreenDemo
} }
} }
/*private void ConfigureSampleGrabber(IBaseFilter sampleGrabberFilter)
{
ISampleGrabber sampleGrabber = (ISampleGrabber)sampleGrabberFilter;
AMMediaType mediaType = new AMMediaType
{
majorType = MediaType.Video,
subType = MediaSubType.RGB24,
formatType = FormatType.VideoInfo
};
sampleGrabber.SetMediaType(mediaType);
DsUtils.FreeAMMediaType(mediaType);
sampleGrabber.SetBufferSamples(false);
sampleGrabber.SetOneShot(false);
sampleGrabber.SetCallback(new SampleGrabberCallback(this), 1);
}*/
private int ConnectFilters(IGraphBuilder graphBuilder, IBaseFilter sourceFilter, string sourcePinName, IBaseFilter destFilter, string destPinName) private int ConnectFilters(IGraphBuilder graphBuilder, IBaseFilter sourceFilter, string sourcePinName, IBaseFilter destFilter, string destPinName)
{ {
IPin outPin = FindPin(sourceFilter, sourcePinName); IPin outPin = FindPin(sourceFilter, sourcePinName);
@ -517,38 +480,6 @@ namespace DualScreenDemo
overlayForm.DisplayBarrage(text); overlayForm.DisplayBarrage(text);
} }
/*
public static async Task UpdateMarqueeTextForNextSong(SongData song)
{
string nextSongText = String.Format("下一首3{0}", song.Name);
if (overlayForm.InvokeRequired)
{
overlayForm.Invoke(new MethodInvoker(() =>
{
overlayForm.UpdateMarqueeText(nextSongText, OverlayForm.MarqueeStartPosition.Middle, Color.White);
}));
}
else
{
overlayForm.UpdateMarqueeText(nextSongText, OverlayForm.MarqueeStartPosition.Middle, Color.White);
}
await Task.Delay(5000);
// 重置跑马灯文本
if (overlayForm.InvokeRequired)
{
overlayForm.Invoke(new MethodInvoker(() =>
{
overlayForm.ResetMarqueeTextToWelcomeMessage();
}));
}
else
{
overlayForm.ResetMarqueeTextToWelcomeMessage();
}
}
*/
public async Task PlayNextSong() public async Task PlayNextSong()
{ {
// 等待初始化完成(例如播放器、串口等資源尚未就緒時) // 等待初始化完成(例如播放器、串口等資源尚未就緒時)
@ -1158,72 +1089,6 @@ namespace DualScreenDemo
} }
} }
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.LastError = state.ToString();
status.IsGraphOk = true;
}
else
{
status.PlayState = "無法取得播放狀態";
status.LastError = "無法取得播放狀態";
status.IsGraphOk = false;
}
}
else
{
status.PlayState = "mediaControlSecondary 物件為 null";
status.LastError = "mediaControlSecondary 物件為 null";
status.IsGraphOk = false;
}
}
catch (Exception ex)
{
status.LastError = "取得影片狀態時發生例外:" + ex.Message;
status.PositionSeconds = -1;
status.PlayState = "Error";
status.IsGraphOk = false;
}
return status;
}
} }
} }

View File

@ -1,8 +0,0 @@
namespace DualScreenDemo
{
public static class WindowStyles
{
public const int WS_CHILD = 0x40000000;
public const int WS_CLIPSIBLINGS = 0x04000000;
}
}