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
This commit is contained in:
olly 2016-05-18 04:29:35 -07:00 committed by Oliver Woodman
parent 362ea1d725
commit d43824710e
2 changed files with 5 additions and 19 deletions

View File

@ -31,7 +31,7 @@ import android.os.Looper;
* <a name="Assumptions"></a> * <a name="Assumptions"></a>
* <h3>Assumptions and player construction</h3> * <h3>Assumptions and player construction</h3>
* *
* <p>The implementation is designed make no assumptions about (and hence impose no restrictions * <p>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. * 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 * 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 * delegates this work to one or more {@link TrackRenderer}s, which are injected when the player

View File

@ -30,7 +30,7 @@ import com.google.android.exoplayer.C;
private final int blockAlignment; private final int blockAlignment;
/** Bits per sample for the audio data. */ /** Bits per sample for the audio data. */
private final int bitsPerSample; private final int bitsPerSample;
/** The pcm encoding */ /** The PCM encoding */
private final int encoding; private final int encoding;
/** Offset to the start of sample data. */ /** 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. */ /** Returns the duration in microseconds of this WAV. */
public long getDurationUs() { public long getDurationUs() {
return (getNumFrames() * C.MICROS_PER_SECOND) / sampleRateHz; long numFrames = dataSize / blockAlignment;
} return (numFrames * 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;
} }
/** Returns the bytes per frame of this WAV. */ /** Returns the bytes per frame of this WAV. */
@ -92,7 +78,7 @@ import com.google.android.exoplayer.C;
public long getPosition(long timeUs) { public long getPosition(long timeUs) {
long unroundedPosition = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND; long unroundedPosition = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND;
// Round down to nearest frame. // 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. */ /** Returns the time in microseconds for the given position in bytes in this WAV. */