Skip to content

Commit 94d72e0

Browse files
authored
Merge pull request #428 from Clash-Projects/fix/download-atmos-and-nonflac-seeking
fix(download): correct stream types in Fmp4IndexBuilder and duration resolution in TrackDownloadManager
2 parents f815be0 + 822c2a2 commit 94d72e0

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎app/src/main/java/com/lastwave/app/data/download/Fmp4IndexBuilder.kt‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import java.io.ByteArrayOutputStream
55
import java.io.File
66
import java.io.FileInputStream
77
import java.io.FileOutputStream
8+
import java.io.InputStream
9+
import java.io.OutputStream
810
import java.io.RandomAccessFile
911

1012
/**
@@ -676,7 +678,7 @@ object Fmp4IndexBuilder {
676678
return out.toByteArray()
677679
}
678680

679-
private fun copyExactly(input: FileInputStream, output: FileOutputStream, count: Long) {
681+
private fun copyExactly(input: InputStream, output: OutputStream, count: Long) {
680682
var remaining = count
681683
val buffer = ByteArray(COPY_BUFFER_SIZE)
682684
while (remaining > 0L) {
@@ -688,7 +690,7 @@ object Fmp4IndexBuilder {
688690
}
689691
}
690692

691-
private fun copyStream(input: FileInputStream, output: FileOutputStream) {
693+
private fun copyStream(input: InputStream, output: OutputStream) {
692694
val buffer = ByteArray(COPY_BUFFER_SIZE)
693695
while (true) {
694696
val read = input.read(buffer)

‎app/src/main/java/com/lastwave/app/data/download/TrackDownloadManager.kt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,9 +1329,7 @@ class TrackDownloadManager @Inject constructor(
13291329
expectedContentLength = ytStream.contentLength
13301330
?: runCatching { Uri.parse(ytStream.url).getQueryParameter("clen")?.toLongOrNull() }.getOrNull()
13311331
if (durationMs <= 0L) {
1332-
val candidateMs = chosenTrack?.durationMs
1333-
?: preloadedBestMatch?.durationMs
1334-
?: pickedStream?.duration?.times(1000L)
1332+
val candidateMs = pickedStream?.durationMs
13351333
?: (chosenTrack?.durationSeconds?.takeIf { it > 0 }?.times(1000L))
13361334
?: (preloadedBestMatch?.durationSeconds?.takeIf { it > 0 }?.times(1000L))
13371335
if (candidateMs != null && candidateMs > 0L) {

0 commit comments

Comments
 (0)