Skip to content

Commit

Permalink
fix: offline mode not responding closes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Jul 6, 2024
1 parent ef4cb6e commit 8fd13b0
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
Expand Down Expand Up @@ -144,7 +143,8 @@ class MusicService :
@Inject
lateinit var mediaLibrarySessionCallback: MediaLibrarySessionCallback

private val scope = CoroutineScope(Dispatchers.Main) + Job()
// private val scope = CoroutineScope(Dispatchers.Main) + Job()
private var scope = CoroutineScope(Dispatchers.Main)
private val binder = MusicBinder()

private lateinit var connectivityManager: ConnectivityManager
Expand Down Expand Up @@ -420,6 +420,7 @@ class MusicService :
queue: Queue,
playWhenReady: Boolean = true,
) {
if (!scope.isActive) scope = CoroutineScope(Dispatchers.Main)
currentQueue = queue
queueTitle = null
player.shuffleModeEnabled = false
Expand All @@ -428,8 +429,7 @@ class MusicService :
player.prepare()
player.playWhenReady = playWhenReady
}

scope.launch(SilentHandler) {
scope.launch {
val initialStatus = withContext(Dispatchers.IO) { queue.getInitialStatus() }
if (queue.preloadItem != null && player.playbackState == STATE_IDLE) return@launch
if (initialStatus.title != null) {
Expand Down

0 comments on commit 8fd13b0

Please sign in to comment.