[Android] Display the chapter instead of title in audio player if available
Nicolas Pomepuy
git at videolan.org
Fri Jan 21 13:32:36 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Jan 21 12:08:28 2022 +0100| [3b8fc53efc475c7d840bd1e3dd6bba9bdc2d4a12] | committer: Nicolas Pomepuy
Display the chapter instead of title in audio player if available
> https://code.videolan.org/videolan/vlc-android/commit/3b8fc53efc475c7d840bd1e3dd6bba9bdc2d4a12
---
application/resources/src/main/res/values/strings.xml | 1 +
.../vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt | 6 ++++--
.../vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt | 4 +++-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 561e88c00..d4893eb97 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -494,6 +494,7 @@
<string name="playlist_name_hint">Playlist name</string>
<string name="go_to_chapter">Go to chapter…</string>
<string name="chapter">Chapter</string>
+ <string name="current_chapter">Chapter: %s</string>
<string name="resume_from_position">Resume from last position</string>
<string name="confirm_resume">Resume from last position?</string>
<string name="confirm_resume_title">Resume played videos</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index bf901c911..9588265e4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -308,8 +308,10 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
updateRepeatMode()
binding.audioMediaSwitcher.updateMedia(playlistModel.service)
binding.coverMediaSwitcher.updateMedia(playlistModel.service)
- binding.songTitle?.text = playlistModel.title
- binding.songSubtitle?.text = TextUtils.separatedString(playlistModel.artist, playlistModel.album)
+
+ val chapter = playlistModel.service!!.getChapters(-1)?.get(playlistModel.service!!.chapterIdx)?.name
+ binding.songTitle?.text = if (!chapter.isNullOrEmpty()) getString(R.string.current_chapter, chapter) else playlistModel.title
+ binding.songSubtitle?.text = if (!chapter.isNullOrEmpty()) TextUtils.separatedString(playlistModel.title, playlistModel.artist) else TextUtils.separatedString(playlistModel.artist, playlistModel.album)
binding.songTitle?.isSelected = true
binding.songSubtitle?.isSelected = true
binding.songTrackInfo?.text = playlistModel.service?.trackInfo()
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt b/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt
index 2702da502..df5444c99 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.kt
@@ -30,6 +30,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.withContext
import org.videolan.vlc.PlaybackService
+import org.videolan.vlc.R
import org.videolan.vlc.gui.helpers.AudioUtil
@ObsoleteCoroutinesApi
@@ -106,7 +107,8 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
addMediaView(inflater, service.titlePrev, service.artistPrev, service.albumPrev, coverPrev, prevTrackInfo)
hasPrevious = true
}
- if (service.hasMedia()) addMediaView(inflater, service.title, service.artist, service.album, coverCurrent, trackInfo)
+ val chapter = service.getChapters(-1)?.get(service.chapterIdx)?.name
+ if (service.hasMedia()) addMediaView(inflater, if (!chapter.isNullOrEmpty()) service.getString(R.string.current_chapter, chapter) else service.title, if (!chapter.isNullOrEmpty()) service.title else service.artist, if (!chapter.isNullOrEmpty()) service.artist else service.album, coverCurrent, trackInfo)
if (service.hasNext()) addMediaView(inflater, service.titleNext, service.artistNext, service.albumNext, coverNext, nextTrackInfo)
if (service.hasPrevious() && service.hasMedia()) {
More information about the Android
mailing list