mirror of
https://github.com/samsonjs/media.git
synced 2026-04-01 10:35:48 +00:00
Set new playlist and start index with one command
PlayableFolderActivity currently uses two seperate commands
to set the playlist and then seek to the requested item.
This is slightly inefficient and also causes analytics
listeners to believe the first item in the playlist was
briefly active.
#minor-release
Issue: androidx/media#180
PiperOrigin-RevId: 480031682
(cherry picked from commit 5d6d069e4e)
This commit is contained in:
parent
b436001e32
commit
d35f67a8a6
1 changed files with 6 additions and 2 deletions
|
|
@ -30,6 +30,7 @@ import android.widget.ListView
|
|||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.media3.common.C
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.session.MediaBrowser
|
||||
|
|
@ -68,10 +69,13 @@ class PlayableFolderActivity : AppCompatActivity() {
|
|||
mediaList.setOnItemClickListener { _, _, position, _ ->
|
||||
run {
|
||||
val browser = this.browser ?: return@run
|
||||
browser.setMediaItems(subItemMediaList)
|
||||
browser.setMediaItems(
|
||||
subItemMediaList,
|
||||
/* startIndex= */ position,
|
||||
/* startPositionMs= */ C.TIME_UNSET
|
||||
)
|
||||
browser.shuffleModeEnabled = false
|
||||
browser.prepare()
|
||||
browser.seekToDefaultPosition(/* windowIndex= */ position)
|
||||
browser.play()
|
||||
val intent = Intent(this, PlayerActivity::class.java)
|
||||
startActivity(intent)
|
||||
|
|
|
|||
Loading…
Reference in a new issue