Skip to content

Commit eba6185

Browse files
committed
Avoid preparing the player twice
It's costly for large playlists
1 parent 56ada15 commit eba6185

File tree

1 file changed

+3
-1
lines changed
  • app/src/main/kotlin/com/simplemobiletools/musicplayer/extensions

1 file changed

+3
-1
lines changed

app/src/main/kotlin/com/simplemobiletools/musicplayer/extensions/Player.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ fun Player.prepareUsingTracks(
164164
* items are added using [addRemainingMediaItems]. This helps prevent delays, especially with large queues, and
165165
* avoids potential issues like [android.app.ForegroundServiceStartNotAllowedException] when starting from background.
166166
*/
167+
var prepareInProgress = false
167168
inline fun Player.maybePreparePlayer(context: Context, crossinline callback: (success: Boolean) -> Unit) {
168-
if (currentMediaItem == null) {
169+
if (!prepareInProgress && currentMediaItem == null) {
170+
prepareInProgress = true
169171
ensureBackgroundThread {
170172
var prepared = false
171173
context.audioHelper.getQueuedTracksLazily { tracks, startIndex, startPositionMs ->

0 commit comments

Comments
 (0)