From 576440faff620a9e4db899fcb0c864e08a530474 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Fri, 23 Oct 2020 10:26:11 +0200 Subject: [PATCH] Fix update media end time --- clapper_src/controls.js | 10 +++------- clapper_src/player.js | 14 ++++++++++---- clapper_src/revealers.js | 7 ++++--- clapper_src/widget.js | 7 ++++--- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/clapper_src/controls.js b/clapper_src/controls.js index 3e53409a..a757ccd4 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -371,14 +371,10 @@ class ClapperControls extends Gtk.Box _onPositionScaleValueChanged(scale) { - let value = Math.round(scale.get_value()); - this.updateElapsedLabel(value); + let positionSeconds = Math.round(scale.get_value()); - if(this.currentPosition === value || this.isPositionSeeking) - return; - - let { player } = this.get_ancestor(Gtk.Grid); - player.seek_seconds(value); + this.currentPosition = positionSeconds; + this.updateElapsedLabel(positionSeconds); } _onVolumeScaleValueChanged(scale) diff --git a/clapper_src/player.js b/clapper_src/player.js index 01291272..6eb357b4 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -344,6 +344,9 @@ class ClapperPlayer extends GstPlayer.Player let clapperWidget = this.widget.get_ancestor(Gtk.Grid); let nextUpdate = clapperWidget.updateTime(); + if(nextUpdate === null) + return; + this._updateTimeTimeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, nextUpdate, () => { this._updateTimeTimeout = null; @@ -370,14 +373,15 @@ class ClapperPlayer extends GstPlayer.Player { this.state = state; + let clapperWidget = this.widget.get_ancestor(Gtk.Grid); + if(!clapperWidget) return; + if(!this.seek_done && this.state !== GstPlayer.PlayerState.BUFFERING) { + clapperWidget.updateTime(); this.seek_done = true; debug('seeking finished'); } - let clapperWidget = this.widget.get_ancestor(Gtk.Grid); - if(!clapperWidget) return; - clapperWidget._onPlayerStateChanged(player, state); } @@ -468,7 +472,9 @@ class ClapperPlayer extends GstPlayer.Player break; case Gdk.KEY_Right: case Gdk.KEY_Left: - value = clapperWidget.controls.positionScale.get_value(); + value = Math.round( + clapperWidget.controls.positionScale.get_value() + ); this.seek_seconds(value); this._setHideControlsTimeout(); clapperWidget.controls.isPositionSeeking = false; diff --git a/clapper_src/revealers.js b/clapper_src/revealers.js index 9cdd4b25..700a3c23 100644 --- a/clapper_src/revealers.js +++ b/clapper_src/revealers.js @@ -145,15 +145,16 @@ class ClapperRevealerTop extends CustomRevealer setTimes(currTime, endTime) { let now = currTime.format(this.timeFormat); - let end = `Ends at: ${endTime.format(this.timeFormat)}`; + let end = endTime.format(this.timeFormat); + let endText = `Ends at: ${end}`; this.currentTime.set_label(now); - this.endTime.set_label(end); + this.endTime.set_label(endText); /* Make sure that next timeout is always run after clock changes, * by delaying it for additional few milliseconds */ let nextUpdate = 60002 - parseInt(currTime.get_seconds() * 1000); - debug(`updated current time: ${now}`); + debug(`updated current time: ${now}, ends at: ${end}`); return nextUpdate; } diff --git a/clapper_src/widget.js b/clapper_src/widget.js index 21f099dd..6eed3a29 100644 --- a/clapper_src/widget.js +++ b/clapper_src/widget.js @@ -223,6 +223,9 @@ var Widget = GObject.registerClass({ updateTime() { + if(!this.revealerTop.visible) + return null; + let currTime = GLib.DateTime.new_now_local(); let endTime = currTime.add_seconds( this.controls.positionAdjustment.get_upper() - this.controls.currentPosition @@ -338,9 +341,8 @@ var Widget = GObject.registerClass({ { if( !this.isSeekable - || !player.seek_done || this.controls.isPositionSeeking - || player.state === GstPlayer.PlayerState.BUFFERING + || !player.seek_done ) return; @@ -348,7 +350,6 @@ var Widget = GObject.registerClass({ if(positionSeconds === this.controls.currentPosition) return; - this.controls.currentPosition = positionSeconds; this.controls.positionScale.set_value(positionSeconds); }