Fix crash that occurred when inserting a Format (foreign key constraint)
This commit is contained in:
@@ -70,12 +70,14 @@ fun StatsForNerds(
|
|||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(mediaId) {
|
LaunchedEffect(mediaId) {
|
||||||
Database.format(mediaId).distinctUntilChanged().collectLatest {
|
Database.format(mediaId).distinctUntilChanged().collectLatest { currentFormat ->
|
||||||
if (it?.itag == null) {
|
if (currentFormat?.itag == null) {
|
||||||
|
binder.player.currentMediaItem?.takeIf { it.mediaId == mediaId }?.let { mediaItem ->
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
delay(2000)
|
delay(2000)
|
||||||
Innertube.player(PlayerBody(videoId = mediaId))?.onSuccess { response ->
|
Innertube.player(PlayerBody(videoId = mediaId))?.onSuccess { response ->
|
||||||
response.streamingData?.highestQualityFormat?.let { format ->
|
response.streamingData?.highestQualityFormat?.let { format ->
|
||||||
|
Database.insert(mediaItem)
|
||||||
Database.insert(
|
Database.insert(
|
||||||
Format(
|
Format(
|
||||||
songId = mediaId,
|
songId = mediaId,
|
||||||
@@ -90,8 +92,9 @@ fun StatsForNerds(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
format = it
|
format = currentFormat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user