Skip to content

Commit 249cc4c

Browse files
committed
perf: select lightweight storyboard seek previews
1 parent 868b2df commit 249cc4c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎app/src/main/java/dev/typetype/android/data/stream/StreamRepositoryImpl.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ internal class StreamRepositoryImpl @Inject constructor(
180180
},
181181
storyboard = previewFrames
182182
.mapNotNull { it.toDomainStoryboard() }
183-
.maxByOrNull { it.frameWidth },
183+
.let(::selectStoryboard),
184184
startPositionMillis = startPosition * 1000L,
185185
sponsorBlockSegments = sponsorBlockSegments.mapNotNull {
186186
it.toDomainSponsorBlockSegment(duration)
@@ -207,6 +207,11 @@ internal class StreamRepositoryImpl @Inject constructor(
207207
.maxByOrNull { it.height }
208208
?.url
209209

210+
private fun selectStoryboard(storyboards: List<StreamStoryboard>): StreamStoryboard? =
211+
storyboards.filter { it.frameWidth >= TARGET_STORYBOARD_FRAME_WIDTH }
212+
.minByOrNull { it.frameWidth }
213+
?: storyboards.maxByOrNull { it.frameWidth }
214+
210215
private fun PreviewFrameItem.toDomainStoryboard(): StreamStoryboard? =
211216
StreamStoryboard(
212217
urls = urls.filter(String::isNotBlank),
@@ -289,6 +294,7 @@ internal suspend fun <T> cancellableStreamResult(
289294
}
290295

291296
private const val SABR_DELIVERY_METHOD = "sabr"
297+
private const val TARGET_STORYBOARD_FRAME_WIDTH = 160
292298

293299
private class SabrContractException :
294300
IllegalStateException("The server returned no playable SABR contract"),

0 commit comments

Comments
 (0)