[Android] Fix subtitle download error when trying to download for a non-local file

Nicolas Pomepuy git at videolan.org
Tue Jul 7 13:16:03 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Jul  3 09:01:47 2020 +0200| [478b812049a7e80cffb84168fd44d6875d48b723] | committer: Nicolas Pomepuy

Fix subtitle download error when trying to download for a non-local file

Fixes #1396

> https://code.videolan.org/videolan/vlc-android/commit/478b812049a7e80cffb84168fd44d6875d48b723
---

 .../src/org/videolan/vlc/viewmodels/SubtitlesModel.kt          | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
index 1807178c9..376534e4e 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/SubtitlesModel.kt
@@ -145,10 +145,14 @@ class SubtitlesModel(private val context: Context, private val mediaUri: Uri, va
                 val subs = if (byHash) {
                     withContext(coroutineContextProvider.IO) {
                         val videoFile = File(mediaUri.path)
-                        val hash = FileUtils.computeHash(videoFile)
-                        val fileLength = videoFile.length()
+                        if (videoFile.exists()) {
+                            val hash = FileUtils.computeHash(videoFile)
+                            val fileLength = videoFile.length()
+                            getSubtitleByHash(fileLength, hash, observableSearchLanguage.get())
+                        } else {
+                            getSubtitleByName(videoFile.name, null, null, observableSearchLanguage.get())
+                        }
 
-                        getSubtitleByHash(fileLength, hash, observableSearchLanguage.get())
                     }
                 } else {
                     observableSearchName.get()?.let {



More information about the Android mailing list