From d43824710e09b1ee6e15af7a39b8bfbcaf76d994 Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 18 May 2016 04:29:35 -0700 Subject: [PATCH] Fix seeking with WAV files. Previously, rounding down to the nearest frame wasn't being done correctly; seeking could seek into a sample. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=122618668 --- .../google/android/exoplayer/ExoPlayer.java | 2 +- .../exoplayer/extractor/wav/WavHeader.java | 22 ++++--------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/ExoPlayer.java b/library/src/main/java/com/google/android/exoplayer/ExoPlayer.java index 406d353b1f..5a512d8880 100644 --- a/library/src/main/java/com/google/android/exoplayer/ExoPlayer.java +++ b/library/src/main/java/com/google/android/exoplayer/ExoPlayer.java @@ -31,7 +31,7 @@ import android.os.Looper; * *

Assumptions and player construction

* - *

The implementation is designed make no assumptions about (and hence impose no restrictions + *

The implementation is designed to make no assumptions about (and hence impose no restrictions * on) the type of the media being played, how and where it is stored, or how it is rendered. * Rather than implementing the loading and rendering of media directly, {@link ExoPlayer} instead * delegates this work to one or more {@link TrackRenderer}s, which are injected when the player diff --git a/library/src/main/java/com/google/android/exoplayer/extractor/wav/WavHeader.java b/library/src/main/java/com/google/android/exoplayer/extractor/wav/WavHeader.java index b8eac814a5..852fe45262 100644 --- a/library/src/main/java/com/google/android/exoplayer/extractor/wav/WavHeader.java +++ b/library/src/main/java/com/google/android/exoplayer/extractor/wav/WavHeader.java @@ -30,7 +30,7 @@ import com.google.android.exoplayer.C; private final int blockAlignment; /** Bits per sample for the audio data. */ private final int bitsPerSample; - /** The pcm encoding */ + /** The PCM encoding */ private final int encoding; /** Offset to the start of sample data. */ @@ -50,22 +50,8 @@ import com.google.android.exoplayer.C; /** Returns the duration in microseconds of this WAV. */ public long getDurationUs() { - return (getNumFrames() * C.MICROS_PER_SECOND) / sampleRateHz; - } - - /** Returns the number of samples in this WAV. */ - public long getNumSamples() { - return dataSize / getBytesPerSample(); - } - - /** Returns the number of frames in this WAV. */ - public long getNumFrames() { - return getNumSamples() / getNumChannels(); - } - - /** Returns the bytes per sample of this WAV. */ - public int getBytesPerSample() { - return blockAlignment / numChannels; + long numFrames = dataSize / blockAlignment; + return (numFrames * C.MICROS_PER_SECOND) / sampleRateHz; } /** Returns the bytes per frame of this WAV. */ @@ -92,7 +78,7 @@ import com.google.android.exoplayer.C; public long getPosition(long timeUs) { long unroundedPosition = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND; // Round down to nearest frame. - return (unroundedPosition / numChannels) * numChannels + dataStartPosition; + return (unroundedPosition / blockAlignment) * blockAlignment + dataStartPosition; } /** Returns the time in microseconds for the given position in bytes in this WAV. */