[Android] Copy HRTF files to internal storage
Geoffrey Métais
git at videolan.org
Thu Apr 16 14:38:49 CEST 2020
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Apr 10 18:08:05 2020 +0200| [278a39e823490fccf499ef58d178bc10a8bee95b] | committer: Nicolas Pomepuy
Copy HRTF files to internal storage
Currently pushed in .share/hrtfs/
> https://code.videolan.org/videolan/vlc-android/commit/278a39e823490fccf499ef58d178bc10a8bee95b
---
.../src/org/videolan/vlc/StartActivity.kt | 1 +
.../src/org/videolan/vlc/util/FileUtils.kt | 27 ++++++++++++++--------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
index b689d77f3..f51d77bc8 100644
--- a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
@@ -170,6 +170,7 @@ class StartActivity : FragmentActivity() {
startApplication(tv, firstRun, upgrade, target)
}
FileUtils.copyLua(applicationContext, upgrade)
+ FileUtils.copyHrtfs(applicationContext, upgrade)
if (AndroidDevices.watchDevices) this.enableStorageMonitoring()
finish()
}
diff --git a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
index e47f583a1..3306ecd1a 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
@@ -35,15 +35,13 @@ import android.text.TextUtils
import android.util.Log
import androidx.annotation.WorkerThread
import androidx.documentfile.provider.DocumentFile
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.ObsoleteCoroutinesApi
-import kotlinx.coroutines.withContext
+import kotlinx.coroutines.*
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.resources.AndroidDevices
import org.videolan.resources.AppContextProvider
+import org.videolan.tools.AppScope
import org.videolan.tools.CloseableUtils
import org.videolan.tools.Settings
import org.videolan.tools.runIO
@@ -51,6 +49,7 @@ import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.media.MediaUtils
import java.io.*
+import java.lang.Runnable
import java.util.*
import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream
@@ -109,33 +108,43 @@ object FileUtils {
}
}
+ fun copyHrtfs(context: Context, force: Boolean) {
+ AppScope.launch(Dispatchers.IO) {
+ val destinationFolder = context.getDir("vlc",
+ Context.MODE_PRIVATE).absolutePath + "/.share/hrtfs"
+ val am = context.assets
+ copyAssetFolder(am, "hrtfs", destinationFolder, force)
+ }
+ }
+
fun copyLua(context: Context, force: Boolean) {
- runIO(Runnable {
+ AppScope.launch(Dispatchers.IO) {
val destinationFolder = context.getDir("vlc",
Context.MODE_PRIVATE).absolutePath + "/.share/lua"
val am = context.assets
copyAssetFolder(am, "lua", destinationFolder, force)
- })
+ }
}
@WorkerThread
internal fun copyAssetFolder(assetManager: AssetManager, fromAssetPath: String, toPath: String, force: Boolean): Boolean {
try {
val files = assetManager.list(fromAssetPath)
- if (files!!.isEmpty()) return false
+ if (files.isNullOrEmpty()) return false
File(toPath).mkdirs()
var res = true
for (file in files)
- res = if (file.contains("."))
+ res = if (file.contains(".")) {
res and copyAsset(assetManager,
"$fromAssetPath/$file",
"$toPath/$file",
force)
- else
+ } else {
res and copyAssetFolder(assetManager,
"$fromAssetPath/$file",
"$toPath/$file",
force)
+ }
return res
} catch (e: Exception) {
e.printStackTrace()
More information about the Android
mailing list