2508221645

撥放器流程與參數調整
跑馬燈調整屬性參數減少閃爍
This commit is contained in:
jasonchenwork 2025-08-22 16:54:20 +08:00
parent 3d9e2ac2cd
commit c263c6e93e
4 changed files with 65 additions and 60 deletions

View File

@ -69,13 +69,17 @@ namespace OverlayFormObj
public OverlayForm()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
MainForm = this;
Instance = this;
MainForm = this;
Instance = this;
InitializeFormSettings();
ConfigureTimers();
InitializeLabels();
ConfigureSegmentTimer();
imageYPos = (screenHeight / 3) - 1024 / 6;
SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer, true);
UpdateStyles();
}
private void ConfigureSegmentTimer()
{

View File

@ -14,13 +14,13 @@ namespace DualScreenDemo
private static PrimaryForm primaryForm; // 儲存實例的參考
public static Room room = new Room();
public static string verSion = "Server V2.9 202508151059";
public static string verSion = "Server V2.9 202508221643";
[STAThread]
static void Main()
{
Console.WriteLine(verSion);
CheckScreens();
// CheckScreens();
if (Utils.Env.GetBool("IsCursor", true)) Cursor.Hide();
AppDomain.CurrentDomain.ProcessExit += (s, e) => Cursor.Show();
//Console.WriteLine("正在與中控取得聯繫...");
@ -149,7 +149,7 @@ namespace DualScreenDemo
}
}
static void WriteLog(string message)
public static void WriteLog(string message)
{
// 指定日志文件的路径
string logFilePath = Path.Combine(Application.StartupPath, "txt", "mainlog.txt");

View File

@ -1,3 +1,4 @@
using System.IO;
using LibVLCSharp.Shared;
namespace DualScreenDemo.Services
@ -13,17 +14,18 @@ namespace DualScreenDemo.Services
{
Core.Initialize();
_libVLC = new LibVLC(
// "--verbose=2",
"--verbose=-1",
"--audio-time-stretch",
// "--vout=automatic",
"--vout=automatic",
"--h264-fps=30",
"--aout=directsound",
"--network-caching=250",
"--file-caching=250",
"--network-caching=300",
"--file-caching=300",
"--audio-time-stretch"
);
_mediaPlayer = new MediaPlayer(_libVLC);
_mediaPlayer.EnableHardwareDecoding = true;
}
#region Player Setup
@ -36,10 +38,10 @@ namespace DualScreenDemo.Services
_mediaPlayer.Scale = 0;
}
catch (Exception ex)
{
{
Console.WriteLine(ex.Message);
Program.WriteLog(ex.ToString());
}
}
#endregion
@ -47,22 +49,6 @@ namespace DualScreenDemo.Services
public MediaPlayer Player => _mediaPlayer;
public bool IsPlaying => _mediaPlayer.IsPlaying;
// public bool IsAtEnd()
// {
// try
// {
// _mediaPlayer.EndReached += (sender, args) => { };
// var duration = _mediaPlayer.Media?.Duration ?? 0;
// var time = _mediaPlayer.Time;
// return duration > 0 && Math.Abs(duration - time) < 1000;
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// return true;
// }
// }
public bool IsAtEnd()
{
@ -73,35 +59,35 @@ namespace DualScreenDemo.Services
return false;
}
public void LoadMedia(string filePath, int audioTrackIndex = 0)
public void LoadMedia(string filePath,int audioTrackIndex = 0)
{
try
{
// Console.WriteLine($"LoadMedia. in");
// _media?.ParseStop();
// Console.WriteLine($"LoadMedia. ParseStop");
_mediaPlayer.Stop();
// Console.WriteLine($"LoadMedia. Stop");
_media?.Dispose();
// Console.WriteLine($"LoadMedia. Dispose");
_media = new Media(_libVLC, filePath, FromType.FromPath);
_media.AddOption(":avcodec-hw=dxva2");
_media.AddOption(":vout=gl");
_media.AddOption(":audio-output=directsound");
_media.AddOption($":audio-track={audioTrackIndex}");
// _media.AddOption(":start-time=0.5");
addMediaOption(_media, audioTrackIndex);
_mediaPlayer.Media = _media;
_mediaPlayer.Play(_media);
// _mediaPlayer.Play(_media);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Program.WriteLog(ex.ToString());
}
}
private void addMediaOption(Media media, int audioTrackIndex)
{
media.AddOption(":avcodec-hw=dxva2");
media.AddOption($":drop-late-frames");
media.AddOption(":audio-output=directsound");
media.AddOption($":audio-track={audioTrackIndex}");
// media.AddOption(":start-time=1");
// media.AddOption(":rate=30");
}
public void Play() => _mediaPlayer.Play();
public void Pause() => _mediaPlayer.Pause();
public void Stop() => _mediaPlayer.Stop();
@ -143,7 +129,14 @@ namespace DualScreenDemo.Services
#region Volume
public void SetVolume(int volume) => _mediaPlayer.Volume = volume;
public int GetVolume() => _mediaPlayer.Volume;
public bool Mute(bool isMuted) => _mediaPlayer.Mute = isMuted;
public bool Mute(bool isMuted)
{
Console.WriteLine($"_mediaPlayer.Mute:in {_mediaPlayer.Mute}");
_mediaPlayer.Mute = isMuted;
Console.WriteLine($"_mediaPlayer.Mute:out {_mediaPlayer.Mute}");
return _mediaPlayer.Mute;
}
#endregion
#region Dispose

View File

@ -74,7 +74,6 @@ namespace DualScreenDemo
public int previousVolume = 100;
public bool isPaused = false;
private bool isSyncToPrimaryMonitor = false;
public bool IsSyncToPrimaryMonitor
{
get { return isSyncToPrimaryMonitor; }
@ -106,7 +105,7 @@ namespace DualScreenDemo
this.StartPosition = FormStartPosition.Manual;
this.Location = secondMonitor.Bounds.Location;
this.Size = secondMonitor.Bounds.Size;
// this.DoubleBuffered = true;
this.DoubleBuffered = true;
}
Screen screen = Screen.FromHandle(this.Handle);
}
@ -342,20 +341,12 @@ namespace DualScreenDemo
string pathToPlay = song.getFile();
_mediaService0.LoadMedia(pathToPlay, 0);
_mediaService1.LoadMedia(pathToPlay, song.isPublicSong ? 0 : 1);
if (song.isPublicSong)
{
isVocalRemoved = true;
}
else
{
isVocalRemoved = false;
}
_ToggleVocalRemoval(isVocalRemoved);
Play();
Thread.Sleep(100);
// 音量處理
//SetVolume(isMuted ? 0 : previousVolume);
if (isMuted) { Mute(true); }
Mute(isMuted);
SetVolume(100 + song.getBasic().getDbChange());
if (isSyncToPrimaryMonitor) SyncToPrimaryMonitor();
return Task.CompletedTask;
@ -387,7 +378,7 @@ namespace DualScreenDemo
{
try
{
if (_mediaService1.IsAtEnd())
if (_mediaService1.IsAtEnd()&&_mediaService0.IsAtEnd())
{
BeginInvoke(new Action(async () =>
{
@ -484,7 +475,7 @@ namespace DualScreenDemo
{
_ToggleVocalRemoval(isVocalRemoved);
}
// _mediaService1.Mute(isMuted);
return isMuted;
}
public void SetVolume(int volume)
@ -495,7 +486,6 @@ namespace DualScreenDemo
}
public int GetVolume()
{
return _mediaService1.GetVolume();
}
private bool isVocalRemoved = true;
@ -506,8 +496,26 @@ namespace DualScreenDemo
}
private bool _ToggleVocalRemoval(bool isVocal)
{
_mediaService0.Mute(isVocal);
_mediaService1.Mute(!isVocal);
if (isVocal)
{
Console.WriteLine("_ToggleVocalRemoval 0:" + isVocal);
Console.WriteLine("_ToggleVocalRemoval 00:" + _mediaService0.Player.Mute);
Console.WriteLine("_ToggleVocalRemoval 01:" + _mediaService1.Player.Mute);
_mediaService0.Mute(true);
_mediaService1.Mute(false);
Console.WriteLine("_ToggleVocalRemoval: 00:" + _mediaService0.Player.Mute);
Console.WriteLine("_ToggleVocalRemoval: 01" + _mediaService1.Player.Mute);
}
else
{
Console.WriteLine("_ToggleVocalRemoval 1:" + isVocal);
_mediaService0.Mute(false);
_mediaService1.Mute(true);
}
Console.WriteLine("00:"+_mediaService0.Player.Mute);
Console.WriteLine("01:" + _mediaService1.Player.Mute);
return isVocal;
}
}