new: add PlayerViewModel to manage audio playback and session handling

This commit is contained in:
2026-06-16 14:48:29 +02:00
parent b95d81010e
commit 1a6cce4803
@@ -0,0 +1,33 @@
package fr.ajaury.gwenedeg.player.ui.viewmodel
import androidx.lifecycle.ViewModel
import fr.ajaury.gwenedeg.player.AudioPlayer
import fr.ajaury.gwenedeg.player.AudioSessionManager
class PlayerViewModel(
private val audioPlayer: AudioPlayer,
private val audioSessionManager: AudioSessionManager,
) : ViewModel() {
init {
audioSessionManager.activate()
}
fun play(filePath: String) {
audioPlayer.load(filePath = filePath)
audioPlayer.play()
}
fun pause() {
audioPlayer.pause()
}
fun stop() {
audioPlayer.stop()
}
override fun onCleared() {
super.onCleared()
audioSessionManager.deactivate()
audioPlayer.release()
}
}