Skip to content
Snippets Groups Projects
Commit a7de49eb authored by Robert Stone's avatar Robert Stone Committed by Nicolas Pomepuy
Browse files

Add ordered rules for the display of artist and subtitle information from streams

parent ce6e4f68
No related branches found
No related tags found
1 merge request!814Update Title, Artist, and Subtitle fields to accomodate streams, podcasts. Handle videos played from Android Auto.
......@@ -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"
......
......@@ -276,9 +276,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
@MainThread
get() {
val media = playlistManager.getCurrentMedia()
return if (media != null) media.nowPlaying
?: MediaUtils.getMediaArtist(this@PlaybackService, media)
else null
return if (media != null) MediaUtils.getMediaArtist(this@PlaybackService, media) else null
}
val artistPrev: String?
......
......@@ -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")
......
......@@ -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 -> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment