Browse Source

Display album in audio player cover mode

Fixes #2312
merge-requests/1287/head
Nicolas Pomepuy 5 years ago
parent
commit
edf8c994e2
  1. 6
      application/vlc-android/res/layout-land/audio_player.xml
  2. 14
      application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
  3. 5
      application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
  4. 8
      application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt
  5. 5
      application/vlc-android/src/org/videolan/vlc/gui/view/CoverMediaSwitcher.kt
  6. 2
      application/vlc-android/src/org/videolan/vlc/gui/view/HeaderMediaSwitcher.kt
  7. 36
      application/vlc-android/src/org/videolan/vlc/util/TextUtils.kt
  8. 3
      application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt

6
application/vlc-android/res/layout-land/audio_player.xml

@ -472,6 +472,9 @@
android:fontFamily="sans-serif-light"
android:maxLines="1"
android:textColor="?attr/font_default"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"
android:singleLine="true"
android:textSize="24sp"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constrainedWidth="true"
@ -489,6 +492,9 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
app:layout_goneMarginBottom="16dp"
android:ellipsize="marquee"
android:marqueeRepeatLimit="1"
android:singleLine="true"
android:maxLines="1"
android:textColor="?attr/font_audio_light"
android:textSize="14sp"

14
application/vlc-android/src/org/videolan/vlc/PlaybackService.kt

@ -301,6 +301,20 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
return if (media != null) MediaUtils.getMediaAlbum(this@PlaybackService, media) else null
}
val albumPrev: String?
@MainThread
get() {
val prev = playlistManager.getPrevMedia()
return if (prev != null) MediaUtils.getMediaAlbum(this@PlaybackService, prev) else null
}
val albumNext: String?
@MainThread
get() {
val next = playlistManager.getNextMedia()
return if (next != null) MediaUtils.getMediaAlbum(this@PlaybackService, next) else null
}
val artist: String?
@MainThread
get() {

5
application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt

@ -74,6 +74,7 @@ import org.videolan.vlc.gui.view.AudioMediaSwitcher
import org.videolan.vlc.gui.view.AudioMediaSwitcher.AudioMediaSwitcherListener
import org.videolan.vlc.manageAbRepeatStep
import org.videolan.vlc.media.PlaylistManager.Companion.hasMedia
import org.videolan.vlc.util.TextUtils
import org.videolan.vlc.util.launchWhenStarted
import org.videolan.vlc.util.share
import org.videolan.vlc.viewmodels.BookmarkModel
@ -308,7 +309,9 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
binding.audioMediaSwitcher.updateMedia(playlistModel.service)
binding.coverMediaSwitcher.updateMedia(playlistModel.service)
binding.songTitle?.text = playlistModel.title
binding.songSubtitle?.text = playlistModel.artist
binding.songSubtitle?.text = TextUtils.separatedString(playlistModel.artist, playlistModel.album)
binding.songTitle?.isSelected = true
binding.songSubtitle?.isSelected = true
binding.songTrackInfo?.text = playlistModel.service?.trackInfo()
binding.songTrackInfo?.visibility = if (Settings.showAudioTrackInfo) View.VISIBLE else View.GONE

8
application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt

@ -103,11 +103,11 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
val inflater = LayoutInflater.from(context)
if (service.hasPrevious()) {
addMediaView(inflater, service.titlePrev, service.artistPrev, coverPrev, prevTrackInfo)
addMediaView(inflater, service.titlePrev, service.artistPrev, service.albumPrev, coverPrev, prevTrackInfo)
hasPrevious = true
}
if (service.hasMedia()) addMediaView(inflater, service.title, service.artist, coverCurrent, trackInfo)
if (service.hasNext()) addMediaView(inflater, service.titleNext, service.artistNext, coverNext, nextTrackInfo)
if (service.hasMedia()) addMediaView(inflater, service.title, service.artist, service.album, coverCurrent, trackInfo)
if (service.hasNext()) addMediaView(inflater, service.titleNext, service.artistNext, service.albumNext, coverNext, nextTrackInfo)
if (service.hasPrevious() && service.hasMedia()) {
previousPosition = 1
@ -116,7 +116,7 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
scrollTo(0)
}
protected abstract fun addMediaView(inflater: LayoutInflater, title: String?, artist: String?, cover: Bitmap?, trackInfo: String?)
protected abstract fun addMediaView(inflater: LayoutInflater, title: String?, artist: String?, album: String?, cover: Bitmap?, trackInfo: String?)
fun setAudioMediaSwitcherListener(l: AudioMediaSwitcherListener) {
audioMediaSwitcherListener = l

5
application/vlc-android/src/org/videolan/vlc/gui/view/CoverMediaSwitcher.kt

@ -33,12 +33,13 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.tools.Settings
import org.videolan.vlc.R
import org.videolan.vlc.gui.helpers.setEllipsizeModeByPref
import org.videolan.vlc.util.TextUtils
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
class CoverMediaSwitcher(context: Context, attrs: AttributeSet) : AudioMediaSwitcher(context, attrs) {
override fun addMediaView(inflater: LayoutInflater, title: String?, artist: String?, cover: Bitmap?, trackInfo: String?) {
override fun addMediaView(inflater: LayoutInflater, title: String?, artist: String?, album: String?, cover: Bitmap?, trackInfo: String?) {
val v = inflater.inflate(R.layout.cover_media_switcher_item, this, false)
val coverView = v.findViewById<ImageView>(R.id.cover)
@ -58,7 +59,7 @@ class CoverMediaSwitcher(context: Context, attrs: AttributeSet) : AudioMediaSwit
artistView.setOnClickListener { onTextClicked() }
titleView.text = title
artistView.text = artist
artistView.text = TextUtils.separatedString(artist, album)
trackInfoView?.text = trackInfo
setEllipsizeModeByPref(titleView, true)

2
application/vlc-android/src/org/videolan/vlc/gui/view/HeaderMediaSwitcher.kt

@ -35,7 +35,7 @@ import org.videolan.vlc.R
@ObsoleteCoroutinesApi
class HeaderMediaSwitcher(context: Context, attrs: AttributeSet) : AudioMediaSwitcher(context, attrs) {
override fun addMediaView(inflater: LayoutInflater, title: String?, artist: String?, cover: Bitmap?, trackInfo: String?) {
override fun addMediaView(inflater: LayoutInflater, title: String?, artist: String?, album: String?, cover: Bitmap?, trackInfo: String?) {
val v = inflater.inflate(R.layout.audio_media_switcher_item, this, false)
val coverView = v.findViewById<View>(R.id.cover) as ImageView

36
application/vlc-android/src/org/videolan/vlc/util/TextUtils.kt

@ -0,0 +1,36 @@
/*
* ************************************************************************
* TextUtils.kt
* *************************************************************************
* Copyright © 2022 VLC authors and VideoLAN
* Author: Nicolas POMEPUY
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
* **************************************************************************
*
*
*/
package org.videolan.vlc.util
object TextUtils {
fun separator() = "·"
@JvmName("separatedStringArr")
fun separatedString(vararg pieces: String?) = separatedString(arrayOf(*pieces))
private fun separatedString(pieces: Array<String?>) = pieces.filter { it?.isNotBlank() == true }.joinToString(separator = " ${separator()} ")
}

3
application/vlc-android/src/org/videolan/vlc/viewmodels/PlaylistModel.kt

@ -109,6 +109,9 @@ class PlaylistModel : ViewModel(), PlaybackService.Callback by EmptyPBSCallback
val artist
get() = service?.artist
val album
get() = service?.album
public override fun onCleared() {
service?.apply {
removeCallback(this@PlaylistModel)

Loading…
Cancel
Save