[Android] Ensure Medialibrary is started only once

Geoffrey Métais git at videolan.org
Thu Oct 10 16:07:22 CEST 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 10 14:20:48 2019 +0200| [70e74112171b07c4488dc0b85344b5dc92af7599] | committer: Geoffrey Métais

Ensure Medialibrary is started only once

(cherry picked from commit 154f0c66a3d4b6aea0a9326681df5264d490d8ba)

> https://code.videolan.org/videolan/vlc-android/commit/70e74112171b07c4488dc0b85344b5dc92af7599
---

 medialibrary/src/org/videolan/medialibrary/Medialibrary.java | 2 ++
 vlc-android/src/org/videolan/vlc/MediaParsingService.kt      | 8 +++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 06289f076..bb783377a 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -49,6 +49,7 @@ public class Medialibrary extends AbstractMedialibrary {
 
     public int init(Context context) {
         if (context == null) return ML_INIT_FAILED;
+        if (mIsInitiated) return ML_INIT_ALREADY_INITIALIZED;
         sContext = context;
         final File extFilesDir = context.getExternalFilesDir(null);
         File dbDirectory = context.getDir("db", Context.MODE_PRIVATE);
@@ -92,6 +93,7 @@ public class Medialibrary extends AbstractMedialibrary {
     }
 
     public void start() {
+        if (isStarted()) return;
         nativeStart();
         isMedialibraryStarted = true;
         synchronized (onMedialibraryReadyListeners) {
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 86c1fc6f2..fcc6314a4 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -420,9 +420,11 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
                 var shouldInit = !dbExists()
                 val initCode = medialibrary.init(context)
                 medialibrary.exceptionHandler = exceptionHandler
-                shouldInit = shouldInit or (initCode == AbstractMedialibrary.ML_INIT_DB_RESET) or (initCode == AbstractMedialibrary.ML_INIT_DB_CORRUPTED)
-                if (initCode != AbstractMedialibrary.ML_INIT_FAILED) initMedialib(action.parse, context, shouldInit, action.upgrade)
-                else exitCommand()
+                if (initCode != AbstractMedialibrary.ML_INIT_ALREADY_INITIALIZED) {
+                    shouldInit = shouldInit or (initCode == AbstractMedialibrary.ML_INIT_DB_RESET) or (initCode == AbstractMedialibrary.ML_INIT_DB_CORRUPTED)
+                    if (initCode != AbstractMedialibrary.ML_INIT_FAILED) initMedialib(action.parse, context, shouldInit, action.upgrade)
+                    else exitCommand()
+                } else  exitCommand()
             }
             is StartScan -> {
                 scanActivated = true



More information about the Android mailing list