diff --git a/android/app/src/main/java/com/ohdodok/catchytape/mediasession/PlaybackService.kt b/android/app/src/main/java/com/ohdodok/catchytape/mediasession/PlaybackService.kt index 59796f6..028ce69 100644 --- a/android/app/src/main/java/com/ohdodok/catchytape/mediasession/PlaybackService.kt +++ b/android/app/src/main/java/com/ohdodok/catchytape/mediasession/PlaybackService.kt @@ -20,7 +20,6 @@ class PlaybackService : MediaSessionService() { override fun onDestroy() { mediaSession?.run { - player.release() release() mediaSession = null } diff --git a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/player/CurrentPlayListUseCase.kt b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/player/CurrentPlayListUseCase.kt index d930094..2606b58 100644 --- a/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/player/CurrentPlayListUseCase.kt +++ b/android/core/domain/src/main/java/com/ohdodok/catchytape/core/domain/usecase/player/CurrentPlayListUseCase.kt @@ -23,8 +23,6 @@ class CurrentPlaylistUseCase @Inject constructor() { musics = musics, ) - scope.launch { - _currentPlaylist.send(newPlaylist) - } + scope.launch { _currentPlaylist.send(newPlaylist) } } } \ No newline at end of file diff --git a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt index 56d9f2a..bf70810 100644 --- a/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt +++ b/android/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerViewModel.kt @@ -10,7 +10,6 @@ import com.ohdodok.catchytape.core.domain.repository.MusicRepository import com.ohdodok.catchytape.core.domain.usecase.player.CurrentPlaylistUseCase import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.CoroutineExceptionHandler -import kotlinx.coroutines.channels.consumeEach import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharedFlow @@ -39,12 +38,14 @@ sealed interface PlayerEvent { data class PlaylistChanged(val currentPlaylist: CurrentPlaylist) : PlayerEvent } + @HiltViewModel class PlayerViewModel @Inject constructor( private val currentPlaylistUseCase: CurrentPlaylistUseCase, private val musicRepository: MusicRepository, ) : ViewModel(), PlayerEventListener { + private val _currentPlaylist = MutableStateFlow?>(null) val currentPlaylist: StateFlow?> = _currentPlaylist.asStateFlow() @@ -65,9 +66,9 @@ class PlayerViewModel @Inject constructor( private fun observePlaylistChange() { viewModelScope.launch(exceptionHandler) { - currentPlaylistUseCase.currentPlaylist.consumeEach { - _currentPlaylist.value = it.musics - _events.emit(PlayerEvent.PlaylistChanged(it)) + for (currentPlaylist in currentPlaylistUseCase.currentPlaylist) { + _currentPlaylist.value = currentPlaylist.musics + _events.emit(PlayerEvent.PlaylistChanged(currentPlaylist)) } } } diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index 8dcdc40..12605b5 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -21,7 +21,7 @@ retrofit = "2.9.0" okhttp = "4.11.0" kotlinx-serialization = "1.6.0" kotlinx-serialization-converter = "1.0.0" -coroutines = "1.3.5" +coroutines = "1.7.0" glide = "4.15.0" timber = "5.0.1"