Fix crash that occurred when inserting a Format (foreign key constraint)

This commit is contained in:
vfsfitvnm 2022-11-02 10:59:27 +01:00
parent fab56dd302
commit ac3019ef25

View file

@ -70,12 +70,14 @@ fun StatsForNerds(
}
LaunchedEffect(mediaId) {
Database.format(mediaId).distinctUntilChanged().collectLatest {
if (it?.itag == null) {
Database.format(mediaId).distinctUntilChanged().collectLatest { currentFormat ->
if (currentFormat?.itag == null) {
binder.player.currentMediaItem?.takeIf { it.mediaId == mediaId }?.let { mediaItem ->
withContext(Dispatchers.IO) {
delay(2000)
Innertube.player(PlayerBody(videoId = mediaId))?.onSuccess { response ->
response.streamingData?.highestQualityFormat?.let { format ->
Database.insert(mediaItem)
Database.insert(
Format(
songId = mediaId,
@ -90,8 +92,9 @@ fun StatsForNerds(
}
}
}
}
} else {
format = it
format = currentFormat
}
}
}