Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
fix: use full cache length instead of chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasDissa committed May 11, 2024
1 parent e25e737 commit b25244d
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,12 @@ class PlayerService : MediaSessionService(), MediaSession.Callback, Player.Liste

@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
private fun createDataSourceFactory(): DataSource.Factory {
val chunkLength = 512 * 1024L

val defaultDataSource = DefaultDataSource.Factory(this@PlayerService)
val resolvingDataSource = ResolvingDataSource.Factory(createCacheDataSource()) { dataSpec ->
val videoId = dataSpec.key ?: error("A key must be set")

if (cache.isCached(videoId, dataSpec.position, chunkLength)) {
dataSpec
val cacheLength = cache.getCachedBytes(videoId, dataSpec.position, Long.MAX_VALUE)
if (cacheLength > 0) {
dataSpec.subrange(dataSpec.position, dataSpec.position + cacheLength)
} else {
val url = runBlocking(Dispatchers.IO) {
container.pipedMusicRepository.getAudioSource(videoId)
Expand Down

0 comments on commit b25244d

Please sign in to comment.