Browse Source

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.
housekeeping/remove-warnings
Antoine POPINEAU 5 years ago
parent
commit
657c72480e
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 4
      app/build.gradle.kts
  2. 2
      app/src/main/java/com/github/apognu/otter/Otter.kt
  3. 4
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt

4
app/build.gradle.kts

@ -90,8 +90,8 @@ dependencies { @@ -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")

2
app/src/main/java/com/github/apognu/otter/Otter.kt

@ -17,7 +17,7 @@ class Otter : Application() { @@ -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()

4
app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt

@ -59,8 +59,6 @@ class MainActivity : AppCompatActivity() { @@ -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() { @@ -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)
}

Loading…
Cancel
Save