mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-29 20:34:05 +02:00
Work around video player black screen when looping & reduce player polling
This commit is contained in:
parent
980bf2c307
commit
34e049a002
10
video/FormPlayer.Designer.cs
generated
10
video/FormPlayer.Designer.cs
generated
@ -36,6 +36,7 @@ private void InitializeComponent() {
|
|||||||
this.tablePanelCompactBottom = new System.Windows.Forms.TableLayoutPanel();
|
this.tablePanelCompactBottom = new System.Windows.Forms.TableLayoutPanel();
|
||||||
this.tablePanelCompactTop = new System.Windows.Forms.TableLayoutPanel();
|
this.tablePanelCompactTop = new System.Windows.Forms.TableLayoutPanel();
|
||||||
this.labelTooltip = new TweetDuck.Video.Controls.LabelTooltip();
|
this.labelTooltip = new TweetDuck.Video.Controls.LabelTooltip();
|
||||||
|
this.timerUI = new System.Windows.Forms.Timer(this.components);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.trackBarVolume)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.trackBarVolume)).BeginInit();
|
||||||
this.tablePanelFull.SuspendLayout();
|
this.tablePanelFull.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.imageResize)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.imageResize)).BeginInit();
|
||||||
@ -45,7 +46,7 @@ private void InitializeComponent() {
|
|||||||
//
|
//
|
||||||
// timerSync
|
// timerSync
|
||||||
//
|
//
|
||||||
this.timerSync.Interval = 15;
|
this.timerSync.Interval = 31;
|
||||||
this.timerSync.Tick += new System.EventHandler(this.timerSync_Tick);
|
this.timerSync.Tick += new System.EventHandler(this.timerSync_Tick);
|
||||||
//
|
//
|
||||||
// trackBarVolume
|
// trackBarVolume
|
||||||
@ -224,6 +225,12 @@ private void InitializeComponent() {
|
|||||||
this.labelTooltip.TabIndex = 3;
|
this.labelTooltip.TabIndex = 3;
|
||||||
this.labelTooltip.Visible = false;
|
this.labelTooltip.Visible = false;
|
||||||
//
|
//
|
||||||
|
// timerUI
|
||||||
|
//
|
||||||
|
this.timerUI.Enabled = true;
|
||||||
|
this.timerUI.Interval = 200;
|
||||||
|
this.timerUI.Tick += new System.EventHandler(this.timerUI_Tick);
|
||||||
|
//
|
||||||
// FormPlayer
|
// FormPlayer
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@ -269,6 +276,7 @@ private void InitializeComponent() {
|
|||||||
private System.Windows.Forms.PictureBox imageClose;
|
private System.Windows.Forms.PictureBox imageClose;
|
||||||
private System.Windows.Forms.TableLayoutPanel tablePanelCompactBottom;
|
private System.Windows.Forms.TableLayoutPanel tablePanelCompactBottom;
|
||||||
private System.Windows.Forms.TableLayoutPanel tablePanelCompactTop;
|
private System.Windows.Forms.TableLayoutPanel tablePanelCompactTop;
|
||||||
|
private System.Windows.Forms.Timer timerUI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ public FormPlayer(IntPtr handle, int dpi, int volume, string url, string token){
|
|||||||
Player.settings.setMode("loop", true);
|
Player.settings.setMode("loop", true);
|
||||||
|
|
||||||
Player.PlayStateChange += player_PlayStateChange;
|
Player.PlayStateChange += player_PlayStateChange;
|
||||||
|
Player.PositionChange += player_PositionChange;
|
||||||
Player.MediaError += player_MediaError;
|
Player.MediaError += player_MediaError;
|
||||||
|
|
||||||
trackBarVolume.Value = volume; // changes player volume too if non-default
|
trackBarVolume.Value = volume; // changes player volume too if non-default
|
||||||
@ -189,6 +190,21 @@ private void player_MediaError(object pMediaObject){
|
|||||||
Environment.Exit(Program.CODE_MEDIA_ERROR);
|
Environment.Exit(Program.CODE_MEDIA_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void player_PositionChange(double oldPosition, double newPosition){
|
||||||
|
timerUI_Tick(null, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void timerUI_Tick(object sender, EventArgs e){
|
||||||
|
IWMPMedia media = Player.currentMedia;
|
||||||
|
IWMPControls controls = Player.controls;
|
||||||
|
|
||||||
|
string current = controls.currentPositionString;
|
||||||
|
labelTime.Text = $"{(string.IsNullOrEmpty(current) ? "00:00" : current)} / {media.durationString}";
|
||||||
|
|
||||||
|
Marshal.ReleaseComObject(media);
|
||||||
|
Marshal.ReleaseComObject(controls);
|
||||||
|
}
|
||||||
|
|
||||||
[HandleProcessCorruptedStateExceptions]
|
[HandleProcessCorruptedStateExceptions]
|
||||||
private void timerSync_Tick(object sender, EventArgs e){
|
private void timerSync_Tick(object sender, EventArgs e){
|
||||||
if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect)){
|
if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect)){
|
||||||
@ -224,8 +240,6 @@ private void timerSync_Tick(object sender, EventArgs e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCursorInside || isDragging){
|
if (isCursorInside || isDragging){
|
||||||
labelTime.Text = $"{controls.currentPositionString} / {media.durationString}";
|
|
||||||
|
|
||||||
int value = (int)Math.Round(progressSeek.Maximum * controls.currentPosition / media.duration);
|
int value = (int)Math.Round(progressSeek.Maximum * controls.currentPosition / media.duration);
|
||||||
|
|
||||||
if (value >= progressSeek.Maximum){
|
if (value >= progressSeek.Maximum){
|
||||||
@ -262,6 +276,9 @@ private void timerSync_Tick(object sender, EventArgs e){
|
|||||||
// the controls.play() call even though it runs on the UI thread
|
// the controls.play() call even though it runs on the UI thread
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (controls.currentPosition > media.duration - 0.05 && !isPaused){ // reset before it reaches the end to avoid black screen
|
||||||
|
controls.currentPosition = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (isCursorInside && !wasCursorInside){
|
if (isCursorInside && !wasCursorInside){
|
||||||
wasCursorInside = true;
|
wasCursorInside = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user