[Android] Add ordered rules for the display of artist and subtitle information from streams
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 20:27:53 2020 -0800| [a7de49eb5b6ccd099811538659636d38ca5f1191] | committer: Nicolas Pomepuy
Add ordered rules for the display of artist and subtitle information from streams
> https://code.videolan.org/videolan/vlc-android/commit/a7de49eb5b6ccd099811538659636d38ca5f1191
---
.../src/main/res/layout/tv_playlist_item.xml | 2 +-
.../src/org/videolan/vlc/PlaybackService.kt | 4 +-
.../src/org/videolan/vlc/media/MediaUtils.kt | 43 ++++++++++++++++++----
.../src/org/videolan/vlc/media/PlaylistManager.kt | 2 +-
4 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/application/television/src/main/res/layout/tv_playlist_item.xml b/application/television/src/main/res/layout/tv_playlist_item.xml
index e656f81f1..c64f1c1a4 100644
--- a/application/television/src/main/res/layout/tv_playlist_item.xml
+++ b/application/television/src/main/res/layout/tv_playlist_item.xml
@@ -41,7 +41,7 @@
android:id="@+id/artist"
android:layout_width="0dp"
android:layout_height="wrap_content"
- android:text="@{MediaUtils.INSTANCE.getMediaArtist(context, media)}"
+ android:text="@{MediaUtils.INSTANCE.getMediaSubtitle(media)}"
android:textColor="@color/grey50"
tools:text="Beethoven"
app:layout_constraintBottom_toBottomOf="parent"
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 1a1ef9a70..926861735 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -276,9 +276,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
@MainThread
get() {
val media = playlistManager.getCurrentMedia()
- return if (media != null) media.nowPlaying
- ?: MediaUtils.getMediaArtist(this at PlaybackService, media)
- else null
+ return if (media != null) MediaUtils.getMediaArtist(this at PlaybackService, media) else null
}
val artistPrev: String?
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index 02f826f3c..a832ea1d5 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -41,6 +41,8 @@ import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.providers.medialibrary.VideoGroupsProvider
import org.videolan.vlc.util.FileUtils
import org.videolan.vlc.util.Permissions
+import org.videolan.vlc.util.generateResolutionClass
+import org.videolan.vlc.util.isSchemeStreaming
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
@@ -325,25 +327,47 @@ object MediaUtils {
}
}
- fun getMediaArtist(ctx: Context, media: MediaWrapper?) = media?.artist
- ?: if (media?.nowPlaying != null) "" else getMediaString(ctx, R.string.unknown_artist)
+ fun getMediaArtist(ctx: Context, media: MediaWrapper?): String = when {
+ media == null -> getMediaString(ctx, R.string.unknown_artist)
+ media.type == MediaWrapper.TYPE_VIDEO -> ""
+ media.artist != null -> media.artist
+ media.nowPlaying != null -> media.title
+ isSchemeStreaming(media.uri.scheme) -> ""
+ else -> getMediaString(ctx, R.string.unknown_artist)
+ }
fun getMediaReferenceArtist(ctx: Context, media: MediaWrapper?) = getMediaArtist(ctx, media)
fun getMediaAlbumArtist(ctx: Context, media: MediaWrapper?) = media?.albumArtist
?: getMediaString(ctx, R.string.unknown_artist)
- fun getMediaAlbum(ctx: Context, media: MediaWrapper?) = media?.album
- ?: if (media?.nowPlaying != null) "" else getMediaString(ctx, R.string.unknown_album)
+ fun getMediaAlbum(ctx: Context, media: MediaWrapper?): String = when {
+ media == null -> getMediaString(ctx, R.string.unknown_album)
+ media.album != null -> media.album
+ media.nowPlaying != null -> ""
+ isSchemeStreaming(media.uri.scheme) -> ""
+ else -> getMediaString(ctx, R.string.unknown_album)
+ }
fun getMediaGenre(ctx: Context, media: MediaWrapper?) = media?.genre
?: getMediaString(ctx, R.string.unknown_genre)
fun getMediaSubtitle(media: MediaWrapper): String? {
- var subtitle = media.nowPlaying ?: media.artist
+ var subtitle = when {
+ media.type == MediaWrapper.TYPE_VIDEO -> ""
+ media.length > 0L -> media.artist
+ isSchemeStreaming(media.uri.scheme) -> media.uri.toString()
+ else -> media.artist
+ }
if (media.length > 0L) {
- subtitle = if (subtitle.isNullOrEmpty()) Tools.millisToString(media.length)
- else "$subtitle • ${Tools.millisToString(media.length)}"
+ if (media.type == MediaWrapper.TYPE_VIDEO) {
+ subtitle = Tools.millisToText(media.length)
+ val resolution = generateResolutionClass(media.width, media.height)
+ if (resolution != null) subtitle = "$subtitle • $resolution"
+ } else {
+ subtitle = if (subtitle.isNullOrEmpty()) Tools.millisToString(media.length)
+ else "$subtitle • ${Tools.millisToString(media.length)}"
+ }
}
return subtitle
}
@@ -361,7 +385,10 @@ object MediaUtils {
fun getDisplaySubtitle(ctx: Context, media: MediaWrapper, mediaPosition: Int, mediaSize: Int): String {
val sb = StringBuilder()
if (mediaSize > 1) sb.append("${mediaPosition + 1} / $mediaSize")
- val desc = getMediaDescription(MediaUtils.getMediaArtist(ctx, media), MediaUtils.getMediaAlbum(ctx, media))
+ val artist = getMediaArtist(ctx, media)
+ val album = getMediaAlbum(ctx, media)
+ val desc = if (artist != getMediaString(ctx, R.string.unknown_artist) && album != getMediaString(ctx, R.string.unknown_album))
+ getMediaDescription(artist, album) else ""
sb.append(if (desc.isNotEmpty()) (if (sb.isNotEmpty()) " • $desc" else desc) else "")
//Replace full-spaces with thin-spaces (Unicode 2009)
return sb.toString().replace(" ", "\u2009")
diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index 931cd968d..052a04f92 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -788,7 +788,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
when (event.type) {
IMedia.Event.MetaChanged -> {
/* Update Meta if file is already parsed */
- if (parsed && player.updateCurrentMeta(event.metaId, getCurrentMedia())) service.executeUpdate()
+ if (parsed && player.updateCurrentMeta(event.metaId, getCurrentMedia())) service.onMediaListChanged()
if (BuildConfig.DEBUG) Log.i(TAG, "Media.Event.MetaChanged: " + event.metaId)
}
IMedia.Event.ParsedChanged -> {
More information about the Android
mailing list