perf: remove duplicate getMediaSources call when preparing player items

This commit is contained in:
Jarne Demeulemeester 2023-05-20 15:25:57 +02:00
parent b63bc6d68a
commit 7e4ac39e83
No known key found for this signature in database
GPG key ID: 1E5C6AFBD622E9F5

View file

@ -136,10 +136,11 @@ class PlayerViewModel @Inject internal constructor(
mediaSourceIndex: Int?,
playbackPosition: Long
): PlayerItem {
val mediaSources = repository.getMediaSources(id, true)
val mediaSource = if (mediaSourceIndex == null) {
repository.getMediaSources(id, true).firstOrNull { it.type == FindroidSourceType.LOCAL } ?: repository.getMediaSources(id, true)[0]
mediaSources.firstOrNull { it.type == FindroidSourceType.LOCAL } ?: mediaSources[0]
} else {
repository.getMediaSources(id, true)[mediaSourceIndex]
mediaSources[mediaSourceIndex]
}
val externalSubtitles = mediaSource.mediaStreams
.filter { mediaStream ->