[Android] Use common streaming uri util
Robert Stone
git at videolan.org
Tue Dec 1 13:11:24 CET 2020
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Sun Nov 29 19:49:43 2020 -0800| [ce6e4f68190a92010cddb449019f091d0cb7d2bc] | committer: Nicolas Pomepuy
Use common streaming uri util
> https://code.videolan.org/videolan/vlc-android/commit/ce6e4f68190a92010cddb449019f091d0cb7d2bc
---
.../vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt | 4 ++--
.../vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.kt | 3 ++-
.../src/org/videolan/vlc/gui/helpers/ImageLoader.kt | 5 +++--
.../src/org/videolan/vlc/media/MediaSessionBrowser.kt | 7 +++----
.../vlc-android/src/org/videolan/vlc/util/Browserutils.kt | 10 ++++++++++
5 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
index 041c80278..578106761 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/PlaylistActivity.kt
@@ -252,8 +252,8 @@ open class PlaylistActivity : AudioPlayerContainerActivity(), IEventsHandler<Med
override fun onCtxClick(v: View, position: Int, item: MediaLibraryItem) {
if (actionMode == null) {
var flags = CTX_PLAYLIST_ITEM_FLAGS
- (item as? MediaWrapper)?.let {media ->
- if (media.type == MediaWrapper.TYPE_STREAM || (media.type == MediaWrapper.TYPE_ALL && media.uri.scheme?.startsWith("http") == true)) flags = flags or CTX_RENAME
+ (item as? MediaWrapper)?.let { media ->
+ if (media.type == MediaWrapper.TYPE_STREAM || (media.type == MediaWrapper.TYPE_ALL && isSchemeHttpOrHttps(media.uri.scheme))) flags = flags or CTX_RENAME
}
showContext(this, this, position, item.title, flags)
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.kt
index c96ddf588..f8dbe9471 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/AudioUtil.kt
@@ -46,6 +46,7 @@ import org.videolan.tools.HttpImageLoader
import org.videolan.vlc.R
import org.videolan.vlc.gui.helpers.UiTools.snackerConfirm
import org.videolan.vlc.util.Permissions
+import org.videolan.vlc.util.isSchemeHttpOrHttps
import java.io.*
import java.lang.Runnable
@@ -166,7 +167,7 @@ object AudioUtil {
@WorkerThread
fun readCoverBitmap(path: String?, width: Int): Bitmap? {
val path = path ?: return null
- if (path.startsWith("http")) return runBlocking(Dispatchers.Main) {
+ if (isSchemeHttpOrHttps(path)) return runBlocking(Dispatchers.Main) {
HttpImageLoader.downloadBitmap(path)
}
return BitmapCache.getBitmapFromMemCache(path.substringAfter("file://")+"_$width") ?: fetchCoverBitmap(path, width)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index f6ec6f47f..661dc8829 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -42,6 +42,7 @@ import org.videolan.vlc.BR
import org.videolan.vlc.R
import org.videolan.vlc.util.ThumbnailsProvider
import org.videolan.vlc.util.ThumbnailsProvider.obtainBitmap
+import org.videolan.vlc.util.isSchemeHttpOrHttps
import org.videolan.vlc.util.scope
private val sMedialibrary = Medialibrary.getInstance()
@@ -188,7 +189,7 @@ fun imageCardViewContent(v: View, content: String?) {
@BindingAdapter(value = ["imageUri", "tv" ], requireAll = false)
fun downloadIcon(v: View, imageUri: Uri?, tv: Boolean = true) {
- if (imageUri?.scheme == "http" || imageUri?.scheme == "https") {
+ if (isSchemeHttpOrHttps(imageUri?.scheme)) {
v.scope.takeIf { it.isActive }?.launch {
val image = HttpImageLoader.downloadBitmap(imageUri.toString())
updateImageView(image, v, DataBindingUtil.findBinding(v), tv = tv)
@@ -200,7 +201,7 @@ fun downloadIcon(v: View, imageUri: Uri?, tv: Boolean = true) {
fun downloadIcon(v: View, imageUrl: String?, tv: Boolean = true) {
if (imageUrl.isNullOrEmpty()) return
val imageUri = imageUrl.toUri()
- if (imageUri.scheme in arrayOf("http", "https")) {
+ if (isSchemeHttpOrHttps(imageUri.scheme)) {
v.scope.takeIf { it.isActive }?.launch {
val image = HttpImageLoader.downloadBitmap(imageUri.toString())
updateImageView(image, v, DataBindingUtil.findBinding(v), tv = tv)
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
index d78dfd5d2..24e0b712c 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaSessionBrowser.kt
@@ -67,6 +67,7 @@ import org.videolan.vlc.media.MediaUtils.getMediaArtist
import org.videolan.vlc.media.MediaUtils.getMediaDescription
import org.videolan.vlc.media.MediaUtils.getMediaSubtitle
import org.videolan.vlc.util.ThumbnailsProvider
+import org.videolan.vlc.util.isSchemeStreaming
import java.util.*
import java.util.concurrent.Semaphore
@@ -357,10 +358,8 @@ class MediaSessionBrowser : ExtensionManagerActivity {
results.ensureCapacity(list.size.coerceAtMost(MAX_RESULT_SIZE))
for (libraryItem in list) {
if (libraryItem.itemType == MediaLibraryItem.TYPE_MEDIA
- && ((libraryItem as MediaWrapper).type == MediaWrapper.TYPE_STREAM
- || (libraryItem as MediaWrapper).uri.scheme?.startsWith("http") == true)) {
- val media = libraryItem as MediaWrapper
- media.type = MediaWrapper.TYPE_STREAM
+ && ((libraryItem as MediaWrapper).type == MediaWrapper.TYPE_STREAM || isSchemeStreaming(libraryItem.uri.scheme))) {
+ libraryItem.type = MediaWrapper.TYPE_STREAM
} else if (libraryItem.itemType == MediaLibraryItem.TYPE_MEDIA && (libraryItem as MediaWrapper).type != MediaWrapper.TYPE_AUDIO)
continue
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
index a491bfdee..3364a47bf 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
@@ -27,6 +27,16 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.mediadb.models.BrowserFav
import java.io.File
+fun isSchemeStreaming(scheme: String?): Boolean = when {
+ scheme.isNullOrEmpty() -> false
+ isSchemeHttpOrHttps(scheme) -> true
+ scheme.startsWith("mms") -> true
+ scheme.startsWith("rtsp") -> true
+ else -> false
+}
+
+fun isSchemeHttpOrHttps(scheme: String?): Boolean = scheme?.startsWith("http") == true
+
fun isSchemeSupported(scheme: String?) = when(scheme) {
"file", "smb", "ssh", "nfs", "ftp", "ftps", "content" -> true
else -> false
More information about the Android
mailing list