Skip to content

Commit

Permalink
Don't lazy inject player in the service, should resolve naman14#64
Browse files Browse the repository at this point in the history
  • Loading branch information
afollestad committed Feb 26, 2019
1 parent 65937e7 commit 2571b82
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koin.android.ext.android.get
import org.koin.android.ext.android.inject
import org.koin.standalone.KoinComponent
import timber.log.Timber.d as log
Expand Down Expand Up @@ -92,7 +93,7 @@ class TimberMusicService : MediaBrowserServiceCompat(), KoinComponent, Lifecycle
private val genreRepository by inject<GenreRepository>()
private val playlistRepository by inject<PlaylistRepository>()

private val player by inject<SongPlayer>()
private lateinit var player: SongPlayer
private val queueHelper by inject<QueueHelper>()
private val permissionsManager by inject<PermissionsManager>()

Expand All @@ -106,6 +107,9 @@ class TimberMusicService : MediaBrowserServiceCompat(), KoinComponent, Lifecycle
lifecycle.currentState = Lifecycle.State.RESUMED
log("onCreate()")

// We get it here so we don't end up lazy-initializing it from a non-UI thread.
player = get()

// We wait until the permission is granted to set the initial queue.
// This observable will immediately emit if the permission is already granted.
permissionsManager.requestStoragePermission(waitForGranted = true)
Expand Down

0 comments on commit 2571b82

Please sign in to comment.