mirror of
https://github.com/Michatec/Radio.git
synced 2026-11-16 08:11:38 +01:00
feat: implement command-based playback triggering in PlayerService
- Add `EXTRA_PLAY_COMMAND`, `PLAY_COMMAND_PLAY`, and `PLAY_COMMAND_PLAY_STATION` constants to `Keys.kt`. - Update `PlayerService.onStartCommand` to process playback commands from intent extras. - Modify `RadioApiService` to pass playback commands when starting `PlayerService`.
This commit is contained in:
1 parent
f2d926d8ba
commit
04a1aa3dde
3 files changed
+19
No files matched your search
@@ -26,6 +26,9 @@ object Keys {
|
||||
const val EXTRA_STATION_UUID: String = "STATION_UUID"
|
||||
const val EXTRA_STREAM_URI: String = "STREAM_URI"
|
||||
const val EXTRA_START_LAST_PLAYED_STATION: String = "START_LAST_PLAYED_STATION"
|
||||
const val EXTRA_PLAY_COMMAND: String = "PLAY_COMMAND"
|
||||
const val PLAY_COMMAND_PLAY: String = "PLAY"
|
||||
const val PLAY_COMMAND_PLAY_STATION: String = "PLAY_STATION"
|
||||
const val EXTRA_SLEEP_TIMER_REMAINING: String = "SLEEP_TIMER_REMAINING"
|
||||
const val EXTRA_METADATA_HISTORY: String = "METADATA_HISTORY"
|
||||
const val EXTRA_VISUALIZER_DATA: String = "VISUALIZER_DATA"
|
||||
|
||||
@@ -245,6 +245,18 @@ class PlayerService : MediaLibraryService(), SharedPreferences.OnSharedPreferenc
|
||||
/* Overrides onStartCommand from Service */
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
val playCommand = intent?.getStringExtra(Keys.EXTRA_PLAY_COMMAND)
|
||||
when (playCommand) {
|
||||
Keys.PLAY_COMMAND_PLAY -> {
|
||||
RadioApiService.playbackController?.play()
|
||||
}
|
||||
Keys.PLAY_COMMAND_PLAY_STATION -> {
|
||||
val uuid = intent.getStringExtra(Keys.EXTRA_STATION_UUID)
|
||||
if (!uuid.isNullOrEmpty()) {
|
||||
RadioApiService.playbackController?.playStationByUuid(uuid)
|
||||
}
|
||||
}
|
||||
}
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.annotation.OptIn
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import com.google.gson.Gson
|
||||
import com.michatec.radio.PlayerService
|
||||
import com.michatec.radio.Keys
|
||||
import com.michatec.radio.helpers.PreferencesHelper
|
||||
import com.michatec.radio.helpers.CollectionHelper
|
||||
import com.michatec.radio.helpers.FileHelper
|
||||
@@ -37,6 +38,7 @@ class RadioApiService : Service() {
|
||||
} else {
|
||||
val intent = Intent(applicationContext, PlayerService::class.java).apply {
|
||||
action = "com.michatec.radio.action.START_PLAYER_SERVICE"
|
||||
putExtra(Keys.EXTRA_PLAY_COMMAND, Keys.PLAY_COMMAND_PLAY)
|
||||
}
|
||||
applicationContext.startService(intent)
|
||||
}
|
||||
@@ -91,6 +93,8 @@ 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_PLAY_COMMAND, Keys.PLAY_COMMAND_PLAY_STATION)
|
||||
putExtra(Keys.EXTRA_STATION_UUID, uuid)
|
||||
}
|
||||
applicationContext.startService(intent)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user