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
This commit is contained in:
tonihei 2022-10-10 09:33:21 +00:00 committed by Marc Baechinger
parent a426cb27c0
commit 5d6d069e4e

View File

@ -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)