fix: delay playback initiation and use playbackController directly

- Add a 500ms delay using `Handler` before triggering playback actions to ensure controller availability.
- Remove `EXTRA_STATION_UUID` from the `PlayerService` start intent.
- Transition to calling `playbackController.play()` and `playbackController.playStationByUuid(uuid)` directly.
This commit is contained in:
Michatec committed 2026-10-31 22:08:03 +01:00
1 parent b8130c64c8
commit 91c33d4abf
1 file changed
+12 -1
@@ -2,7 +2,9 @@ package com.michatec.radio.api
import android.app.Service
import android.content.Intent
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import com.google.gson.Gson
@@ -40,6 +42,11 @@ class RadioApiService : Service() {
action = "com.michatec.radio.action.START_PLAYER_SERVICE"
}
applicationContext.startService(intent)
Handler(Looper.getMainLooper()).postDelayed({
if (playbackController != null) {
playbackController?.play()
}
}, 500)
}
}
@@ -92,9 +99,13 @@ class RadioApiService : Service() {
PreferencesHelper.saveCurrentStationId(uuid)
val intent = Intent(applicationContext, PlayerService::class.java).apply {
action = "com.michatec.radio.action.START_PLAYER_SERVICE"
putExtra(Keys.EXTRA_STATION_UUID, uuid)
}
applicationContext.startService(intent)
Handler(Looper.getMainLooper()).postDelayed({
if (playbackController != null) {
playbackController?.playStationByUuid(uuid)
}
}, 500)
}
}