diff --git a/clapper_src/controls.js b/clapper_src/controls.js index 8d9aebcc..8b13af9f 100644 --- a/clapper_src/controls.js +++ b/clapper_src/controls.js @@ -71,13 +71,9 @@ var Controls = GObject.registerClass({ setLiveMode(isLive, isSeekable) { - /* This update must always happen - * after media duration is set */ - let text = (isLive) - ? 'LIVE' - : '00:00:00' + '/' + this.durationFormated; + if(isLive) + this.elapsedButton.set_label('LIVE'); - this.elapsedButton.set_label(text); this.positionScale.visible = isSeekable; } diff --git a/clapper_src/interface.js b/clapper_src/interface.js index 896f7ce6..1553333f 100644 --- a/clapper_src/interface.js +++ b/clapper_src/interface.js @@ -28,6 +28,7 @@ class ClapperInterface extends Gtk.Grid this.needsTracksUpdate = true; this.headerBar = null; this.defaultTitle = null; + this.mediaInfoSignal = null; this.videoBox = new Gtk.Box(); this.overlay = new Gtk.Overlay(); @@ -124,9 +125,9 @@ class ClapperInterface extends Gtk.Grid debug(`interface in fullscreen mode: ${isFullscreen}`); } - updateMediaTracks() + _onMediaInfoUpdated(player, mediaInfo) { - let mediaInfo = this._player.get_media_info(); + this._player.disconnect(this.mediaInfoSignal); /* Set titlebar media title and path */ this.updateTitles(mediaInfo); @@ -223,6 +224,8 @@ class ClapperInterface extends Gtk.Grid this.controls[`${type}TracksButton`].show(); } } + + this.mediaInfoSignal = null; } updateTitles(mediaInfo) @@ -345,17 +348,26 @@ class ClapperInterface extends Gtk.Grid { switch(state) { case GstPlayer.PlayerState.BUFFERING: + if(!this._player.isLocalFile) + this.needsTracksUpdate = true; break; case GstPlayer.PlayerState.STOPPED: this.needsTracksUpdate = true; + if(this.mediaInfoSignal) { + this._player.disconnect(this.mediaInfoSignal); + this.mediaInfoSignal = null; + } + break; case GstPlayer.PlayerState.PAUSED: this.controls.togglePlayButton.setPrimaryIcon(); break; case GstPlayer.PlayerState.PLAYING: this.controls.togglePlayButton.setSecondaryIcon(); - if(this.needsTracksUpdate) { + if(this.needsTracksUpdate && !this.mediaInfoSignal) { this.needsTracksUpdate = false; - this.updateMediaTracks(); + this.mediaInfoSignal = this._player.connect( + 'media_info_updated', this._onMediaInfoUpdated.bind(this) + ); } break; default: @@ -365,7 +377,7 @@ class ClapperInterface extends Gtk.Grid _onPlayerDurationChanged(player) { - let duration = player.get_duration() / 1000000000; + let duration = this._player.get_duration() / 1000000000; let increment = (duration < 1) ? 0 : (duration < 100) diff --git a/clapper_src/player.js b/clapper_src/player.js index 0db1e644..be22c1fb 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -51,6 +51,7 @@ class ClapperPlayer extends GstPlayer.Player this.renderer = renderer; this.gstRegistry = Gst.Registry.get(); + this.isLocalFile = false; this._playerSignals = []; this._widgetSignals = []; @@ -115,8 +116,10 @@ class ClapperPlayer extends GstPlayer.Player debug(`parsed source to URI: ${source}`); - if(Gst.Uri.get_protocol(source) !== 'file') + if(Gst.Uri.get_protocol(source) !== 'file') { + this.isLocalFile = false; return this.set_uri(source); + } let file = Gio.file_new_for_uri(source); @@ -133,6 +136,7 @@ class ClapperPlayer extends GstPlayer.Player if(file.get_path().endsWith(`.${this.playlist_ext}`)) return this.load_playlist_file(file); + this.isLocalFile = true; this.set_uri(source); } @@ -230,12 +234,18 @@ class ClapperPlayer extends GstPlayer.Player connect(signal, fn) { - this._playerSignals.push(super.connect(signal, fn)); + let connection = super.connect(signal, fn); + this._playerSignals.push(connection); + + return connection; } connectWidget(signal, fn) { - this._widgetSignals.push(this.widget.connect(signal, fn)); + let connection = this.widget.connect(signal, fn); + this._widgetSignals.push(connection); + + return connection; } _onStateChanged(player, state)