diff --git a/RELEASENOTES.md b/RELEASENOTES.md index d9f0ac4274..6ae74edb12 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -8,6 +8,8 @@ ([#6885](https://github.com/google/ExoPlayer/issues/6885)). * Allow missing hours in SubRip (.srt) timecodes ([#7122](https://github.com/google/ExoPlayer/issues/7122)). +* WAV: Fix failure to play WAV files that contain trailing non-media bytes + ([#7129](https://github.com/google/ExoPlayer/issues/7129)) * UI: Add an option to set whether to use the orientation sensor for rotation in spherical playbacks ([#6761](https://github.com/google/ExoPlayer/issues/6761)). diff --git a/library/core/src/main/java/com/google/android/exoplayer2/extractor/wav/WavExtractor.java b/library/core/src/main/java/com/google/android/exoplayer2/extractor/wav/WavExtractor.java index 45a8c24e67..dd27294246 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/extractor/wav/WavExtractor.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/extractor/wav/WavExtractor.java @@ -259,14 +259,14 @@ public final class WavExtractor implements Extractor { public boolean sampleData(ExtractorInput input, long bytesLeft) throws IOException, InterruptedException { // Write sample data until we've reached the target sample size, or the end of the data. - boolean endOfSampleData = bytesLeft == 0; - while (!endOfSampleData && pendingOutputBytes < targetSampleSizeBytes) { + while (bytesLeft > 0 && pendingOutputBytes < targetSampleSizeBytes) { int bytesToRead = (int) Math.min(targetSampleSizeBytes - pendingOutputBytes, bytesLeft); int bytesAppended = trackOutput.sampleData(input, bytesToRead, true); if (bytesAppended == RESULT_END_OF_INPUT) { - endOfSampleData = true; + bytesLeft = 0; } else { pendingOutputBytes += bytesAppended; + bytesLeft -= bytesAppended; } } @@ -288,7 +288,7 @@ public final class WavExtractor implements Extractor { pendingOutputBytes = offset; } - return endOfSampleData; + return bytesLeft <= 0; } } diff --git a/library/core/src/test/assets/wav/sample_with_trailing_bytes.wav b/library/core/src/test/assets/wav/sample_with_trailing_bytes.wav new file mode 100644 index 0000000000..0b06efcf09 Binary files /dev/null and b/library/core/src/test/assets/wav/sample_with_trailing_bytes.wav differ diff --git a/library/core/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java b/library/core/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java index 7f9549ea75..0f4220c7f3 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/extractor/wav/WavExtractorTest.java @@ -15,6 +15,7 @@ */ package com.google.android.exoplayer2.extractor.wav; +import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.testutil.ExtractorAsserts; import org.junit.Test; @@ -30,7 +31,7 @@ public final class WavExtractorTest { } @Test - public void testSampleImaAdpcm() throws Exception { + public void sample_imaAdpcm() throws Exception { ExtractorAsserts.assertBehavior(WavExtractor::new, "wav/sample_ima_adpcm.wav"); } }