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.
This commit is contained in:
Rafostar
2020-09-10 19:53:04 +02:00
parent b8ed6b32dc
commit ed5d449142
2 changed files with 32 additions and 6 deletions

View File

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