Avoid preparing the player twice
It's costly for large playlists
This commit is contained in:
parent
56ada15410
commit
eba6185561
1 changed files with 3 additions and 1 deletions
|
@ -164,8 +164,10 @@ fun Player.prepareUsingTracks(
|
|||
* items are added using [addRemainingMediaItems]. This helps prevent delays, especially with large queues, and
|
||||
* avoids potential issues like [android.app.ForegroundServiceStartNotAllowedException] when starting from background.
|
||||
*/
|
||||
var prepareInProgress = false
|
||||
inline fun Player.maybePreparePlayer(context: Context, crossinline callback: (success: Boolean) -> Unit) {
|
||||
if (currentMediaItem == null) {
|
||||
if (!prepareInProgress && currentMediaItem == null) {
|
||||
prepareInProgress = true
|
||||
ensureBackgroundThread {
|
||||
var prepared = false
|
||||
context.audioHelper.getQueuedTracksLazily { tracks, startIndex, startPositionMs ->
|
||||
|
|
Loading…
Reference in a new issue