Support loading files using full or relative paths

This commit is contained in:
Rafostar
2020-09-08 08:58:43 +02:00
parent 689edd9cf3
commit 649ff7682c
3 changed files with 26 additions and 5 deletions

View File

@@ -249,7 +249,7 @@ var App = GObject.registerClass({
if(!this.playlist.length)
return;
this.player.set_uri(this.playlist[0]);
this.player.set_media(this.playlist[0]);
}
_onPlayerStateChanged(self, state)

View File

@@ -1,4 +1,4 @@
const { GLib, GObject, Gst, GstPlayer } = imports.gi;
const { Gio, GLib, GObject, Gst, GstPlayer } = imports.gi;
const Debug = imports.clapper_src.debug;
const GSTPLAYER_DEFAULTS = {
@@ -62,6 +62,27 @@ class ClapperPlayer extends GstPlayer.Player
this.widget.connect('destroy', this._onWidgetDestroy.bind(this));
}
set_media(source)
{
if(Gst.uri_is_valid(source)) {
debug(`setting source URI: ${source}`);
return this.set_uri(source);
}
debug(`parsing source: ${source}`);
let uri = Gst.filename_to_uri(source);
if(!uri)
return debug('parsing to URI failed');
debug(`parsed source to URI: ${uri}`);
if(!Gio.file_new_for_uri(uri).query_exists(null))
return debug(`file does not exist: ${source}`, 'LEVEL_WARNING');
this.set_uri(uri);
}
seek_seconds(position)
{
this.seek(position * 1000000000);