Avoid preparing the player twice

It's costly for large playlists
This commit is contained in:
Naveen 2023-10-15 22:01:34 +05:30
parent 56ada15410
commit eba6185561
No known key found for this signature in database
GPG key ID: 0E155DAD31671DA3

View file

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