mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #2802 from Bnyro/master
[Audio Player] Auto scroll the title and uploader
This commit is contained in:
commit
a5304e3135
@ -80,6 +80,10 @@ class AudioPlayerFragment : BaseFragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
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 {
|
binding.prev.setOnClickListener {
|
||||||
val currentIndex = PlayingQueue.currentIndex()
|
val currentIndex = PlayingQueue.currentIndex()
|
||||||
if (!PlayingQueue.hasPrev()) return@setOnClickListener
|
if (!PlayingQueue.hasPrev()) return@setOnClickListener
|
||||||
@ -175,25 +179,24 @@ class AudioPlayerFragment : BaseFragment() {
|
|||||||
* Update the position, duration and text views belonging to the seek bar
|
* Update the position, duration and text views belonging to the seek bar
|
||||||
*/
|
*/
|
||||||
private fun updateSeekBar() {
|
private fun updateSeekBar() {
|
||||||
val duration = playerService?.getDuration()?.toFloat() ?: return
|
val duration = playerService?.getDuration()?.takeIf { it > 0 } ?: let {
|
||||||
|
// if there's no duration available, clear everything
|
||||||
// when the video is not loaded yet, retry in 100 ms
|
binding.timeBar.value = 0f
|
||||||
if (duration <= 0) {
|
binding.duration.text = ""
|
||||||
|
binding.currentPosition.text = ""
|
||||||
handler.postDelayed(this::updateSeekBar, 100)
|
handler.postDelayed(this::updateSeekBar, 100)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the current position from the player service
|
|
||||||
val currentPosition = playerService?.getCurrentPosition()?.toFloat() ?: 0f
|
val currentPosition = playerService?.getCurrentPosition()?.toFloat() ?: 0f
|
||||||
|
|
||||||
// set the text for the indicators
|
// 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(
|
binding.currentPosition.text = DateUtils.formatElapsedTime(
|
||||||
(currentPosition / 1000).toLong()
|
(currentPosition / 1000).toLong()
|
||||||
)
|
)
|
||||||
|
|
||||||
// update the time bar current value and maximum value
|
// update the time bar current value and maximum value
|
||||||
binding.timeBar.valueTo = duration / 1000
|
binding.timeBar.valueTo = (duration / 1000).toFloat()
|
||||||
binding.timeBar.value = minOf(
|
binding.timeBar.value = minOf(
|
||||||
currentPosition / 1000,
|
currentPosition / 1000,
|
||||||
binding.timeBar.valueTo
|
binding.timeBar.valueTo
|
||||||
|
@ -39,21 +39,17 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
|
style="@style/TextViewMarquee"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="marquee"
|
|
||||||
android:marqueeRepeatLimit="marquee_forever"
|
|
||||||
android:scrollHorizontally="true"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:textAlignment="center"
|
|
||||||
android:textSize="24sp" />
|
android:textSize="24sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/uploader"
|
android:id="@+id/uploader"
|
||||||
|
style="@style/TextViewMarquee"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:textAlignment="center"
|
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
@ -239,11 +239,23 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="AudioPlayerButton">
|
<style name="AudioPlayerButton">
|
||||||
|
|
||||||
<item name="android:layout_width">30dp</item>
|
<item name="android:layout_width">30dp</item>
|
||||||
<item name="android:layout_height">30dp</item>
|
<item name="android:layout_height">30dp</item>
|
||||||
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
|
<item name="android:background">?attr/selectableItemBackgroundBorderless</item>
|
||||||
<item name="android:layout_marginStart">10dp</item>
|
<item name="android:layout_marginStart">10dp</item>
|
||||||
<item name="android:layout_marginEnd">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>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user