From 059ee932fef2e7369846cb47a05c678228369eb7 Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Sun, 13 Sep 2020 11:13:04 +0200 Subject: [PATCH] Skip non-existing files in playlist --- clapper_src/player.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/clapper_src/player.js b/clapper_src/player.js index f77991ea..63747fb1 100644 --- a/clapper_src/player.js +++ b/clapper_src/player.js @@ -60,6 +60,7 @@ class ClapperPlayer extends GstPlayer.Player this._playlist = []; this._trackId = 0; + this.playlist_ext = opts.playlist_ext || 'claps'; this.connect('state-changed', this._onStateChanged.bind(this)); this.connect('uri-loaded', this._onUriLoaded.bind(this)); @@ -84,10 +85,17 @@ class ClapperPlayer extends GstPlayer.Player let file = Gio.file_new_for_uri(uri); - if(!file.query_exists(null)) - return debug(`file does not exist: ${source}`, 'LEVEL_WARNING'); + if(!file.query_exists(null)) { + debug(`file does not exist: ${source}`, 'LEVEL_WARNING'); + this._trackId++; - if(file.get_path().endsWith('.claps')) + if(this._playlist.length <= this._trackId) + return debug('set media reached end of playlist'); + + return this.set_media(this._playlist[this._trackId]); + } + + if(file.get_path().endsWith(`.${this.playlist_ext}`)) return this.load_playlist_file(file); this.set_uri(uri); @@ -98,17 +106,17 @@ class ClapperPlayer extends GstPlayer.Player let stream = new Gio.DataInputStream({ base_stream: file.read(null) }); - let plist = []; + let playlist = []; let line; while((line = stream.read_line(null)[0])) { line = String(line); debug(`new playlist item: ${line}`); - plist.push(line); + playlist.push(line); } stream.close(null); - this.set_playlist(plist); + this.set_playlist(playlist); } set_playlist(playlist)