diff --git a/src/appBase.js b/src/appBase.js index 35aae681..6422c4e4 100644 --- a/src/appBase.js +++ b/src/appBase.js @@ -17,6 +17,7 @@ class ClapperAppBase extends Gtk.Application }); this.doneFirstActivate = false; + this.isFileAppend = false; } vfunc_startup() @@ -79,11 +80,15 @@ class ClapperAppBase extends Gtk.Application const [playlist, subs] = Misc.parsePlaylistFiles(urisArr); const { player } = this.active_window.get_child(); + const action = (this.isFileAppend) ? 'append' : 'set'; if(playlist && playlist.length) - player.set_playlist(playlist); + player[`${action}_playlist`](playlist); if(subs) player.set_subtitles(subs); + + /* Restore default behavior */ + this.isFileAppend = false; } _onFirstActivate() diff --git a/src/player.js b/src/player.js index f4635f60..0aff7743 100644 --- a/src/player.js +++ b/src/player.js @@ -221,19 +221,33 @@ class ClapperPlayer extends GstClapper.Clapper if(this.state !== GstClapper.ClapperState.STOPPED) this.stop(); + debug('new playlist'); + this.playlistWidget.removeAll(); this.canAutoFullscreen = true; - for(let source of playlist) { - const uri = this._getSourceUri(source); - this.playlistWidget.addItem(uri); - } + this._addPlaylistItems(playlist); /* If not mapped yet, first track will play after map */ if(this.windowMapped) this._playFirstTrack(); } + append_playlist(playlist) + { + debug('appending playlist'); + this._addPlaylistItems(playlist); + + if( + !this.windowMapped + || this.state !== GstClapper.ClapperState.STOPPED + ) + return; + + if(!this.playlistWidget.nextTrack()) + debug('playlist append failed'); + } + set_subtitles(source) { const uri = this._getSourceUri(source); @@ -370,6 +384,7 @@ class ClapperPlayer extends GstClapper.Clapper case 'play': case 'pause': case 'set_playlist': + case 'append_playlist': case 'set_subtitles': this[action](value); break; @@ -394,6 +409,16 @@ class ClapperPlayer extends GstClapper.Clapper } } + _addPlaylistItems(playlist) + { + for(let source of playlist) { + const uri = this._getSourceUri(source); + + debug(`added uri: ${uri}`); + this.playlistWidget.addItem(uri); + } + } + _getSourceUri(source) { return (source.get_uri != null)