[Android] Lazily load libVLCFactory

Geoffrey Métais git at videolan.org
Thu May 7 12:17:11 CEST 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May  5 09:40:59 2020 +0200| [c7691dc09f1cec1b0af4d00308def996bcad06b8] | committer: Nicolas Pomepuy

Lazily load libVLCFactory

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

 .../src/main/java/org/videolan/resources/VLCInstance.kt        | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/VLCInstance.kt b/application/resources/src/main/java/org/videolan/resources/VLCInstance.kt
index a4b3855cb..50172f228 100644
--- a/application/resources/src/main/java/org/videolan/resources/VLCInstance.kt
+++ b/application/resources/src/main/java/org/videolan/resources/VLCInstance.kt
@@ -34,12 +34,12 @@ import org.videolan.resources.util.VLCCrashHandler
 
 @ObsoleteCoroutinesApi
 object VLCInstance {
-    val TAG = "VLC/UiTools/VLCInstance"
+    const val TAG = "VLC/UiTools/VLCInstance"
 
     @SuppressLint("StaticFieldLeak")
     private var sLibVLC: ILibVLC? = null
 
-    private val libVLCFactory = FactoryManager.getFactory(ILibVLCFactory.factoryId) as ILibVLCFactory
+    private val libVLCFactory by lazy { FactoryManager.getFactory(ILibVLCFactory.factoryId) as ILibVLCFactory }
 
     /** A set of utility functions for the VLC application  */
     @Synchronized
@@ -63,10 +63,8 @@ object VLCInstance {
     @Synchronized
     @Throws(IllegalStateException::class)
     fun restart() {
-        if (sLibVLC != null) {
-            sLibVLC!!.release()
-            sLibVLC = libVLCFactory.getFromOptions(AppContextProvider.appContext, VLCOptions.libOptions)
-        }
+        sLibVLC?.release()
+        sLibVLC = libVLCFactory.getFromOptions(AppContextProvider.appContext, VLCOptions.libOptions)
     }
 
     @Synchronized



More information about the Android mailing list