Commit e4b35e88 by Oliver Woodman

Transition ExoPlayer to use longs for ms timestamps.

parent d85f4abb
...@@ -70,7 +70,7 @@ public class FullPlayerActivity extends Activity implements SurfaceHolder.Callba ...@@ -70,7 +70,7 @@ public class FullPlayerActivity extends Activity implements SurfaceHolder.Callba
private boolean playerNeedsPrepare; private boolean playerNeedsPrepare;
private boolean autoPlay = true; private boolean autoPlay = true;
private int playerPosition; private long playerPosition;
private boolean enableBackgroundAudio = false; private boolean enableBackgroundAudio = false;
private Uri contentUri; private Uri contentUri;
......
...@@ -310,7 +310,7 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi ...@@ -310,7 +310,7 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
player.setPlayWhenReady(playWhenReady); player.setPlayWhenReady(playWhenReady);
} }
public void seekTo(int positionMs) { public void seekTo(long positionMs) {
player.seekTo(positionMs); player.seekTo(positionMs);
} }
...@@ -339,11 +339,11 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi ...@@ -339,11 +339,11 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
return playerState; return playerState;
} }
public int getCurrentPosition() { public long getCurrentPosition() {
return player.getCurrentPosition(); return player.getCurrentPosition();
} }
public int getDuration() { public long getDuration() {
return player.getDuration(); return player.getDuration();
} }
......
...@@ -76,7 +76,7 @@ public class SimplePlayerActivity extends Activity implements SurfaceHolder.Call ...@@ -76,7 +76,7 @@ public class SimplePlayerActivity extends Activity implements SurfaceHolder.Call
private MediaCodecVideoTrackRenderer videoRenderer; private MediaCodecVideoTrackRenderer videoRenderer;
private boolean autoPlay = true; private boolean autoPlay = true;
private int playerPosition; private long playerPosition;
private Uri contentUri; private Uri contentUri;
private int contentType; private int contentType;
......
...@@ -229,7 +229,7 @@ public interface ExoPlayer { ...@@ -229,7 +229,7 @@ public interface ExoPlayer {
/** /**
* Represents an unknown time or duration. * Represents an unknown time or duration.
*/ */
public static final int UNKNOWN_TIME = -1; public static final long UNKNOWN_TIME = -1;
/** /**
* Gets the {@link Looper} associated with the playback thread. * Gets the {@link Looper} associated with the playback thread.
...@@ -313,7 +313,7 @@ public interface ExoPlayer { ...@@ -313,7 +313,7 @@ public interface ExoPlayer {
* *
* @param positionMs The seek position. * @param positionMs The seek position.
*/ */
public void seekTo(int positionMs); public void seekTo(long positionMs);
/** /**
* Stops playback. Use {@code setPlayWhenReady(false)} rather than this method if the intention * Stops playback. Use {@code setPlayWhenReady(false)} rather than this method if the intention
...@@ -363,14 +363,14 @@ public interface ExoPlayer { ...@@ -363,14 +363,14 @@ public interface ExoPlayer {
* @return The duration of the track in milliseconds, or {@link ExoPlayer#UNKNOWN_TIME} if the * @return The duration of the track in milliseconds, or {@link ExoPlayer#UNKNOWN_TIME} if the
* duration is not known. * duration is not known.
*/ */
public int getDuration(); public long getDuration();
/** /**
* Gets the current playback position in milliseconds. * Gets the current playback position in milliseconds.
* *
* @return The current playback position in milliseconds. * @return The current playback position in milliseconds.
*/ */
public int getCurrentPosition(); public long getCurrentPosition();
/** /**
* Gets an estimate of the absolute position in milliseconds up to which data is buffered. * Gets an estimate of the absolute position in milliseconds up to which data is buffered.
...@@ -378,7 +378,7 @@ public interface ExoPlayer { ...@@ -378,7 +378,7 @@ public interface ExoPlayer {
* @return An estimate of the absolute position in milliseconds up to which data is buffered, * @return An estimate of the absolute position in milliseconds up to which data is buffered,
* or {@link ExoPlayer#UNKNOWN_TIME} if no estimate is available. * or {@link ExoPlayer#UNKNOWN_TIME} if no estimate is available.
*/ */
public int getBufferedPosition(); public long getBufferedPosition();
/** /**
* Gets an estimate of the percentage into the media up to which data is buffered. * Gets an estimate of the percentage into the media up to which data is buffered.
......
...@@ -130,7 +130,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -130,7 +130,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
@Override @Override
public void seekTo(int positionMs) { public void seekTo(long positionMs) {
internalPlayer.seekTo(positionMs); internalPlayer.seekTo(positionMs);
} }
...@@ -156,26 +156,26 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -156,26 +156,26 @@ import java.util.concurrent.CopyOnWriteArraySet;
} }
@Override @Override
public int getDuration() { public long getDuration() {
return internalPlayer.getDuration(); return internalPlayer.getDuration();
} }
@Override @Override
public int getCurrentPosition() { public long getCurrentPosition() {
return internalPlayer.getCurrentPosition(); return internalPlayer.getCurrentPosition();
} }
@Override @Override
public int getBufferedPosition() { public long getBufferedPosition() {
return internalPlayer.getBufferedPosition(); return internalPlayer.getBufferedPosition();
} }
@Override @Override
public int getBufferedPercentage() { public int getBufferedPercentage() {
int bufferedPosition = getBufferedPosition(); long bufferedPosition = getBufferedPosition();
int duration = getDuration(); long duration = getDuration();
return bufferedPosition == ExoPlayer.UNKNOWN_TIME || duration == ExoPlayer.UNKNOWN_TIME ? 0 return bufferedPosition == ExoPlayer.UNKNOWN_TIME || duration == ExoPlayer.UNKNOWN_TIME ? 0
: (duration == 0 ? 100 : (bufferedPosition * 100) / duration); : (int) (duration == 0 ? 100 : (bufferedPosition * 100) / duration);
} }
// Not private so it can be called from an inner class without going through a thunk method. // Not private so it can be called from an inner class without going through a thunk method.
......
...@@ -117,18 +117,18 @@ import java.util.List; ...@@ -117,18 +117,18 @@ import java.util.List;
return internalPlaybackThread.getLooper(); return internalPlaybackThread.getLooper();
} }
public int getCurrentPosition() { public long getCurrentPosition() {
return (int) (positionUs / 1000); return positionUs / 1000;
} }
public int getBufferedPosition() { public long getBufferedPosition() {
return bufferedPositionUs == TrackRenderer.UNKNOWN_TIME_US ? ExoPlayer.UNKNOWN_TIME return bufferedPositionUs == TrackRenderer.UNKNOWN_TIME_US ? ExoPlayer.UNKNOWN_TIME
: (int) (bufferedPositionUs / 1000); : bufferedPositionUs / 1000;
} }
public int getDuration() { public long getDuration() {
return durationUs == TrackRenderer.UNKNOWN_TIME_US ? ExoPlayer.UNKNOWN_TIME return durationUs == TrackRenderer.UNKNOWN_TIME_US ? ExoPlayer.UNKNOWN_TIME
: (int) (durationUs / 1000); : durationUs / 1000;
} }
public void prepare(TrackRenderer... renderers) { public void prepare(TrackRenderer... renderers) {
...@@ -139,8 +139,8 @@ import java.util.List; ...@@ -139,8 +139,8 @@ import java.util.List;
handler.obtainMessage(MSG_SET_PLAY_WHEN_READY, playWhenReady ? 1 : 0, 0).sendToTarget(); handler.obtainMessage(MSG_SET_PLAY_WHEN_READY, playWhenReady ? 1 : 0, 0).sendToTarget();
} }
public void seekTo(int positionMs) { public void seekTo(long positionMs) {
handler.obtainMessage(MSG_SEEK_TO, positionMs, 0).sendToTarget(); handler.obtainMessage(MSG_SEEK_TO, positionMs).sendToTarget();
} }
public void stop() { public void stop() {
...@@ -204,7 +204,7 @@ import java.util.List; ...@@ -204,7 +204,7 @@ import java.util.List;
return true; return true;
} }
case MSG_SEEK_TO: { case MSG_SEEK_TO: {
seekToInternal(msg.arg1); seekToInternal((Long) msg.obj);
return true; return true;
} }
case MSG_STOP: { case MSG_STOP: {
...@@ -453,7 +453,7 @@ import java.util.List; ...@@ -453,7 +453,7 @@ import java.util.List;
} }
} }
private void seekToInternal(int positionMs) throws ExoPlaybackException { private void seekToInternal(long positionMs) throws ExoPlaybackException {
rebuffering = false; rebuffering = false;
positionUs = positionMs * 1000L; positionUs = positionMs * 1000L;
mediaClock.stop(); mediaClock.stop();
......
...@@ -855,8 +855,8 @@ public final class FragmentedMp4Extractor implements Extractor { ...@@ -855,8 +855,8 @@ public final class FragmentedMp4Extractor implements Extractor {
out.initTables(sampleCount); out.initTables(sampleCount);
int[] sampleSizeTable = out.sampleSizeTable; int[] sampleSizeTable = out.sampleSizeTable;
int[] sampleDecodingTimeTable = out.sampleDecodingTimeTable;
int[] sampleCompositionTimeOffsetTable = out.sampleCompositionTimeOffsetTable; int[] sampleCompositionTimeOffsetTable = out.sampleCompositionTimeOffsetTable;
long[] sampleDecodingTimeTable = out.sampleDecodingTimeTable;
boolean[] sampleIsSyncFrameTable = out.sampleIsSyncFrameTable; boolean[] sampleIsSyncFrameTable = out.sampleIsSyncFrameTable;
long timescale = track.timescale; long timescale = track.timescale;
...@@ -882,7 +882,7 @@ public final class FragmentedMp4Extractor implements Extractor { ...@@ -882,7 +882,7 @@ public final class FragmentedMp4Extractor implements Extractor {
} else { } else {
sampleCompositionTimeOffsetTable[i] = 0; sampleCompositionTimeOffsetTable[i] = 0;
} }
sampleDecodingTimeTable[i] = (int) ((cumulativeTime * 1000) / timescale); sampleDecodingTimeTable[i] = (cumulativeTime * 1000) / timescale;
sampleSizeTable[i] = sampleSize; sampleSizeTable[i] = sampleSize;
sampleIsSyncFrameTable[i] = ((sampleFlags >> 16) & 0x1) == 0 sampleIsSyncFrameTable[i] = ((sampleFlags >> 16) & 0x1) == 0
&& (!workaroundEveryVideoFrameIsSyncFrame || i == 0); && (!workaroundEveryVideoFrameIsSyncFrame || i == 0);
......
...@@ -33,14 +33,14 @@ import com.google.android.exoplayer.upstream.NonBlockingInputStream; ...@@ -33,14 +33,14 @@ import com.google.android.exoplayer.upstream.NonBlockingInputStream;
*/ */
public int[] sampleSizeTable; public int[] sampleSizeTable;
/** /**
* The decoding time of each sample in the run.
*/
public int[] sampleDecodingTimeTable;
/**
* The composition time offset of each sample in the run. * The composition time offset of each sample in the run.
*/ */
public int[] sampleCompositionTimeOffsetTable; public int[] sampleCompositionTimeOffsetTable;
/** /**
* The decoding time of each sample in the run.
*/
public long[] sampleDecodingTimeTable;
/**
* Indicates which samples are sync frames. * Indicates which samples are sync frames.
*/ */
public boolean[] sampleIsSyncFrameTable; public boolean[] sampleIsSyncFrameTable;
......
...@@ -70,12 +70,12 @@ public class PlayerControl implements MediaPlayerControl { ...@@ -70,12 +70,12 @@ public class PlayerControl implements MediaPlayerControl {
@Override @Override
public int getCurrentPosition() { public int getCurrentPosition() {
return exoPlayer.getCurrentPosition(); return (int) exoPlayer.getCurrentPosition();
} }
@Override @Override
public int getDuration() { public int getDuration() {
return exoPlayer.getDuration(); return (int) exoPlayer.getDuration();
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment