Check if local subtitle file exists before loading it

Otherwise GStreamer will error out and playback will stop. Non-existing subtitle file is common on Flatpak when user tries to open/drop a file from a folder that container does not have access to.
This commit is contained in:
Rafał Dzięgiel
2021-04-09 10:55:06 +02:00
parent a3f78432f8
commit a39c67e5e7
2 changed files with 22 additions and 4 deletions

View File

@@ -126,6 +126,19 @@ function parsePlaylistFiles(filesArray)
return [filesArray, subs];
}
function getFileFromLocalUri(uri)
{
const file = Gio.file_new_for_uri(uri);
if(!file.query_exists(null)) {
debug(`file does not exist: ${file.get_path()}`, 'LEVEL_WARNING');
return null;
}
return file;
}
function encodeHTML(text)
{
return text.replace(/&/g, '&')

View File

@@ -60,10 +60,8 @@ class ClapperPlayer extends PlayerBase
return;
}
let file = Gio.file_new_for_uri(uri);
if(!file.query_exists(null)) {
debug(`file does not exist: ${file.get_path()}`, 'LEVEL_WARNING');
const file = Misc.getFileFromLocalUri(uri);
if(!file) {
if(!this.playlistWidget.nextTrack())
debug('set media reached end of playlist');
@@ -160,6 +158,13 @@ class ClapperPlayer extends PlayerBase
{
const uri = this._getSourceUri(source);
/* Check local file existence */
if(
Gst.Uri.get_protocol(uri) === 'file'
&& !Misc.getFileFromLocalUri(uri)
)
return;
this.set_subtitle_uri(uri);
this.set_subtitle_track_enabled(true);