Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

앱 재진입시 재생 버그 fix ( 재생 중(isPlaying=true)인 상태에서 앱 종료 ) #333

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class PlaybackService : MediaSessionService() {

override fun onDestroy() {
mediaSession?.run {
player.release()
release()
mediaSession = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class CurrentPlaylistUseCase @Inject constructor() {
musics = musics,
)

scope.launch {
_currentPlaylist.send(newPlaylist)
}
scope.launch { _currentPlaylist.send(newPlaylist) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<List<Music>?>(null)
val currentPlaylist: StateFlow<List<Music>?> = _currentPlaylist.asStateFlow()

Expand All @@ -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))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down