1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-08 20:34:05 +02:00

Work around video player black screen when looping & reduce player polling

This commit is contained in:
chylex 2020-03-05 13:26:08 +01:00
parent 980bf2c307
commit 34e049a002
2 changed files with 28 additions and 3 deletions

View File

@ -36,6 +36,7 @@ private void InitializeComponent() {
this.tablePanelCompactBottom = new System.Windows.Forms.TableLayoutPanel();
this.tablePanelCompactTop = new System.Windows.Forms.TableLayoutPanel();
this.labelTooltip = new TweetDuck.Video.Controls.LabelTooltip();
this.timerUI = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.trackBarVolume)).BeginInit();
this.tablePanelFull.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.imageResize)).BeginInit();
@ -45,7 +46,7 @@ private void InitializeComponent() {
//
// timerSync
//
this.timerSync.Interval = 15;
this.timerSync.Interval = 31;
this.timerSync.Tick += new System.EventHandler(this.timerSync_Tick);
//
// trackBarVolume
@ -224,6 +225,12 @@ private void InitializeComponent() {
this.labelTooltip.TabIndex = 3;
this.labelTooltip.Visible = false;
//
// timerUI
//
this.timerUI.Enabled = true;
this.timerUI.Interval = 200;
this.timerUI.Tick += new System.EventHandler(this.timerUI_Tick);
//
// FormPlayer
//
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.TableLayoutPanel tablePanelCompactBottom;
private System.Windows.Forms.TableLayoutPanel tablePanelCompactTop;
private System.Windows.Forms.Timer timerUI;
}
}

View File

@ -61,6 +61,7 @@ public FormPlayer(IntPtr handle, int dpi, int volume, string url, string token){
Player.settings.setMode("loop", true);
Player.PlayStateChange += player_PlayStateChange;
Player.PositionChange += player_PositionChange;
Player.MediaError += player_MediaError;
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);
}
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]
private void timerSync_Tick(object sender, EventArgs e){
if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect)){
@ -224,8 +240,6 @@ private void timerSync_Tick(object sender, EventArgs e){
}
if (isCursorInside || isDragging){
labelTime.Text = $"{controls.currentPositionString} / {media.durationString}";
int value = (int)Math.Round(progressSeek.Maximum * controls.currentPosition / media.duration);
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
}
}
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){
wasCursorInside = true;