Skip to content
Snippets Groups Projects
Commit 85677afc authored by Robert Stone's avatar Robert Stone
Browse files

Add playlist, artist, and album information to the playback screen

parent dae479cd
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,10 @@
package org.videolan.resources
import android.annotation.TargetApi
import android.app.UiModeManager
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.os.Build.VERSION_CODES
......@@ -166,6 +168,11 @@ object AndroidDevices {
return Build.VERSION.SDK_INT > VERSION_CODES.P || Build.VERSION.SDK_INT == VERSION_CODES.P && "samsung" == Build.MANUFACTURER.toLowerCase(Locale.US)
}
fun isCarMode(ctx: Context): Boolean {
val uiModeManager = ctx.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
return uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_CAR
}
private fun hasPlayServices(pm: PackageManager): Boolean {
try {
pm.getPackageInfo("com.google.android.gsf", PackageManager.GET_SERVICES)
......
package org.videolan.tools
fun getMediaDescription(artist: String?, album: String?): String {
val hasArtist = !artist.isNullOrEmpty()
val hasAlbum = !album.isNullOrEmpty()
if (!hasAlbum && !hasArtist) return ""
val contentBuilder = StringBuilder(if (hasArtist) artist!! else "")
if (hasArtist && hasAlbum) contentBuilder.append(" - ")
if (hasAlbum) contentBuilder.append(album)
return contentBuilder.toString()
}
\ No newline at end of file
......@@ -850,6 +850,11 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
putString(MediaMetadataCompat.METADATA_KEY_ALBUM, MediaUtils.getMediaAlbum(ctx, media))
putLong(MediaMetadataCompat.METADATA_KEY_DURATION, if (length != 0L) length else -1L)
}
if (AndroidDevices.isCarMode(ctx)) {
bob.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, title)
bob.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, MediaUtils.getDisplaySubtitle(ctx, media, currentMediaPosition, mediaListSize))
bob.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, MediaUtils.getMediaAlbum(ctx, media))
}
if (coverOnLockscreen) {
val cover = AudioUtil.readCoverBitmap(Uri.decode(media.artworkMrl), 512)
if (cover?.config != null)
......
......@@ -37,8 +37,8 @@ import androidx.media.session.MediaButtonReceiver
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.resources.*
import org.videolan.tools.getContextWithLocale
import org.videolan.tools.getMediaDescription
import org.videolan.vlc.R
import org.videolan.vlc.media.MediaUtils.getMediaDescription
private const val MEDIALIBRRARY_CHANNEL_ID = "vlc_medialibrary"
private const val PLAYBACK_SERVICE_CHANNEL_ID = "vlc_playback"
......
......@@ -348,6 +348,25 @@ object MediaUtils {
return subtitle
}
fun getMediaDescription(artist: String?, album: String?): String {
val hasArtist = !artist.isNullOrEmpty()
val hasAlbum = !album.isNullOrEmpty()
if (!hasAlbum && !hasArtist) return ""
val contentBuilder = StringBuilder(artist ?: "")
if (hasArtist && hasAlbum) contentBuilder.append(" - ")
if (hasAlbum) contentBuilder.append(album)
return contentBuilder.toString()
}
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))
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")
}
fun getMediaTitle(mediaWrapper: MediaWrapper) = mediaWrapper.title
?: FileUtils.getFileNameFromPath(mediaWrapper.location)
......
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