Add append_playlist function

This commit is contained in:
Rafał Dzięgiel
2021-04-21 14:55:20 +02:00
parent 231af36ef6
commit deb273179f
2 changed files with 35 additions and 5 deletions

View File

@@ -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()

View File

@@ -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)