Merge pull request #2802 from Bnyro/master

[Audio Player] Auto scroll the title and uploader
This commit is contained in:
Bnyro 2023-01-21 18:45:04 +01:00 committed by GitHub
commit a5304e3135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 14 deletions

View File

@ -80,6 +80,10 @@ class AudioPlayerFragment : BaseFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// select the title TV in order for it to automatically scroll
binding.title.isSelected = true
binding.uploader.isSelected = true
binding.prev.setOnClickListener {
val currentIndex = PlayingQueue.currentIndex()
if (!PlayingQueue.hasPrev()) return@setOnClickListener
@ -175,25 +179,24 @@ class AudioPlayerFragment : BaseFragment() {
* Update the position, duration and text views belonging to the seek bar
*/
private fun updateSeekBar() {
val duration = playerService?.getDuration()?.toFloat() ?: return
// when the video is not loaded yet, retry in 100 ms
if (duration <= 0) {
val duration = playerService?.getDuration()?.takeIf { it > 0 } ?: let {
// if there's no duration available, clear everything
binding.timeBar.value = 0f
binding.duration.text = ""
binding.currentPosition.text = ""
handler.postDelayed(this::updateSeekBar, 100)
return
}
// get the current position from the player service
val currentPosition = playerService?.getCurrentPosition()?.toFloat() ?: 0f
// set the text for the indicators
binding.duration.text = DateUtils.formatElapsedTime((duration / 1000).toLong())
binding.duration.text = DateUtils.formatElapsedTime(duration / 1000)
binding.currentPosition.text = DateUtils.formatElapsedTime(
(currentPosition / 1000).toLong()
)
// update the time bar current value and maximum value
binding.timeBar.valueTo = duration / 1000
binding.timeBar.valueTo = (duration / 1000).toFloat()
binding.timeBar.value = minOf(
currentPosition / 1000,
binding.timeBar.valueTo

View File

@ -39,21 +39,17 @@
<TextView
android:id="@+id/title"
style="@style/TextViewMarquee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textAlignment="center"
android:textSize="24sp" />
<TextView
android:id="@+id/uploader"
style="@style/TextViewMarquee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textAlignment="center"
android:textSize="18sp" />
</LinearLayout>

View File

@ -239,11 +239,23 @@
</style>
<style name="AudioPlayerButton">
<item name="android:layout_width">30dp</item>
<item name="android:layout_height">30dp</item>
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
<item name="android:layout_marginStart">10dp</item>
<item name="android:layout_marginEnd">10dp</item>
</style>
<style name="TextViewMarquee">
<item name="android:singleLine">true</item>
<item name="android:ellipsize">marquee</item>
<item name="android:marqueeRepeatLimit">marquee_forever</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAlignment">center</item>
</style>
</resources>