From ed5d449142e2951836754418ea5e22450af53773 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Thu, 10 Sep 2020 19:53:04 +0200 Subject: [PATCH] Support for multiple media files This enables support for starting media player with more than one file path specified. When a file playback finishes, next is loaded automatically. --- clapper_src/app.js | 6 ++---- clapper_src/player.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/clapper_src/app.js b/clapper_src/app.js index 3676c7fb..0e02dc8b 100644 --- a/clapper_src/app.js +++ b/clapper_src/app.js @@ -264,10 +264,8 @@ var App = GObject.registerClass({ this.player.widget.disconnect(this.playerDrawSignal); this.emit('ready', true); - if(!this.playlist.length) - return; - - this.player.set_media(this.playlist[0]); + if(this.playlist.length) + this.player.set_playlist(this.playlist); } _onPlayerStateChanged(self, state) diff --git a/clapper_src/player.js b/clapper_src/player.js index 8c364afd..ddf20e22 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -57,8 +57,12 @@ class ClapperPlayer extends GstPlayer.Player this.widget = gtkglsink.widget; this.state = GstPlayer.PlayerState.STOPPED; - this.connect('state_changed', this._onStateChanged.bind(this)); - this.connect('uri_loaded', this._onUriLoaded.bind(this)); + this._playlist = []; + this._trackId = 0; + + this.connect('state-changed', this._onStateChanged.bind(this)); + this.connect('uri-loaded', this._onUriLoaded.bind(this)); + this.connect('end-of-stream', this._onStreamEnded.bind(this)); this.widget.connect('destroy', this._onWidgetDestroy.bind(this)); } @@ -83,6 +87,22 @@ class ClapperPlayer extends GstPlayer.Player this.set_uri(uri); } + set_playlist(playlist) + { + if(!Array.isArray(playlist)) + return; + + this._trackId = 0; + this._playlist = playlist; + + this.set_media(this._playlist[0]); + } + + get_playlist() + { + return this._playlist; + } + seek_seconds(position) { this.seek(position * 1000000000); @@ -115,6 +135,14 @@ class ClapperPlayer extends GstPlayer.Player this.loop.quit(); } + _onStreamEnded(player) + { + this._trackId++; + + if(this._trackId < this._playlist.length) + this.set_media(this._playlist[this._trackId]); + } + _onUriLoaded() { this.play();