mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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:
parent
362ea1d725
commit
d43824710e
@ -31,7 +31,7 @@ import android.os.Looper;
|
||||
* <a name="Assumptions"></a>
|
||||
* <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.
|
||||
* 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
|
||||
|
@ -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. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user