mirror of
https://github.com/Rafostar/clapper.git
synced 2025-08-31 00:11:59 +02:00
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:
13
src/misc.js
13
src/misc.js
@@ -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, '&')
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user