Skip to content

Commit

Permalink
Fix AudioTrack position reporting whilst paused.
Browse files Browse the repository at this point in the history
Issue: google#158
  • Loading branch information
ojw28 committed Nov 20, 2014
1 parent 2a832fd commit 33c37eb
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.google.android.exoplayer.audio;

import com.google.android.exoplayer.ExoPlaybackException;
import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.Util;

Expand Down Expand Up @@ -192,9 +191,12 @@ public long getCurrentPositionUs(boolean sourceEnded) {
return CURRENT_POSITION_NOT_SET;
}

if (audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_PLAYING) {
maybeSampleSyncParams();
}

long systemClockUs = System.nanoTime() / 1000;
long currentPositionUs;
maybeSampleSyncParams();
if (audioTimestampSet) {
// How long ago in the past the audio timestamp is (negative if it's in the future).
long presentationDiff = systemClockUs - (audioTimestampCompat.getNanoTime() / 1000);
Expand Down Expand Up @@ -508,10 +510,6 @@ private boolean hasCurrentPositionUs() {

/** Updates the audio track latency and playback position parameters. */
private void maybeSampleSyncParams() {
if (!hasCurrentPositionUs()) {
return;
}

long playbackPositionUs = getPlaybackPositionUs();
if (playbackPositionUs == 0) {
// The AudioTrack hasn't output anything yet.
Expand Down Expand Up @@ -574,7 +572,7 @@ private void maybeSampleSyncParams() {
* method is a no-op. If it hasn't then {@link #audioTrack} is released and set to null, and an
* exception is thrown.
*
* @throws ExoPlaybackException If {@link #audioTrack} has not been successfully initialized.
* @throws InitializationException If {@link #audioTrack} has not been successfully initialized.
*/
private void checkAudioTrackInitialized() throws InitializationException {
int state = audioTrack.getState();
Expand Down

0 comments on commit 33c37eb

Please sign in to comment.