Workaround exoplayer bug

This commit is contained in:
vfsfitvnm
2022-10-03 18:30:41 +02:00
parent 549e190965
commit 13028e41c7

View File

@@ -104,6 +104,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.cancellable import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
@@ -297,6 +298,8 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
if (totalPlayTimeMs > 30000) { if (totalPlayTimeMs > 30000) {
query { query {
// THANKS, EXOPLAYER
if (runBlocking { Database.song(mediaItem.mediaId).first() } != null) {
Database.insert( Database.insert(
Event( Event(
songId = mediaItem.mediaId, songId = mediaItem.mediaId,
@@ -307,6 +310,7 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
} }
} }
} }
}
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) { override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
maybeRecoverPlaybackError() maybeRecoverPlaybackError()