Some vendors' battery optimizers killed the background service quite

quickly when the app is in the background and *not* playing music. This
had the effect of breaking all player actions within the app (queue
listing, playback control, etc.).

This "starts" PlayerService every time MainActivity is resumed, which is
a noop if the service is still running, but allows retrieving app
functionality otherwise.
This commit is contained in:
Antoine POPINEAU 2019-10-31 00:46:35 +01:00
parent bf1bba1162
commit 657c72480e
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
3 changed files with 5 additions and 5 deletions

View File

@ -90,8 +90,8 @@ dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.50")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2")
implementation("androidx.appcompat:appcompat:1.1.0")
implementation("androidx.core:core-ktx:1.2.0-beta01")

View File

@ -17,7 +17,7 @@ class Otter : Application() {
fun get(): Otter = instance
}
var eventBus: BroadcastChannel<Event> = BroadcastChannel(10)
val eventBus: BroadcastChannel<Event> = BroadcastChannel(10)
val commandBus: Channel<Command> = Channel(10)
val requestBus: BroadcastChannel<Request> = BroadcastChannel(10)
val progressBus: BroadcastChannel<Triple<Int, Int, Int>> = ConflatedBroadcastChannel()

View File

@ -59,8 +59,6 @@ class MainActivity : AppCompatActivity() {
.replace(R.id.container, BrowseFragment())
.commit()
startService(Intent(this, PlayerService::class.java))
watchEventBus()
CommandBus.send(Command.RefreshService)
@ -69,6 +67,8 @@ class MainActivity : AppCompatActivity() {
override fun onResume() {
super.onResume()
startService(Intent(this, PlayerService::class.java))
now_playing_toggle.setOnClickListener {
CommandBus.send(Command.ToggleState)
}