Skip to content

Commit

Permalink
Set new playlist and start index with one command
Browse files Browse the repository at this point in the history
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: #180
PiperOrigin-RevId: 480031682
(cherry picked from commit 5d6d069)
  • Loading branch information
tonihei authored and microkatz committed Oct 10, 2022
1 parent b436001 commit d35f67a
Showing 1 changed file with 6 additions and 2 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d35f67a

Please sign in to comment.