Commit adf98b0f by Oliver Woodman

Make seekTo(currentPosition) a no-op in ExoPlayer.

- Also avoid boxing when passing the seek position to the background
  thread.

Issue: #654
parent 6ee6bc5c
...@@ -144,4 +144,21 @@ public class UtilTest extends TestCase { ...@@ -144,4 +144,21 @@ public class UtilTest extends TestCase {
assertEquals(1407322800000L, Util.parseXsDateTime("2014-08-06T11:00:00Z")); assertEquals(1407322800000L, Util.parseXsDateTime("2014-08-06T11:00:00Z"));
} }
public void testLongSplitting() {
assertLongSplittingForValue(Long.MIN_VALUE);
assertLongSplittingForValue(Long.MIN_VALUE + 1);
assertLongSplittingForValue(-1);
assertLongSplittingForValue(0);
assertLongSplittingForValue(1);
assertLongSplittingForValue(Long.MAX_VALUE - 1);
assertLongSplittingForValue(Long.MAX_VALUE);
}
private static void assertLongSplittingForValue(long value) {
int topBits = Util.getTopInt(value);
int bottomBots = Util.getBottomInt(value);
long reconstructedValue = Util.getLong(topBits, bottomBots);
assertEquals(value, reconstructedValue);
}
} }
...@@ -19,6 +19,7 @@ import com.google.android.exoplayer.ExoPlayer.ExoPlayerComponent; ...@@ -19,6 +19,7 @@ import com.google.android.exoplayer.ExoPlayer.ExoPlayerComponent;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.PriorityHandlerThread; import com.google.android.exoplayer.util.PriorityHandlerThread;
import com.google.android.exoplayer.util.TraceUtil; import com.google.android.exoplayer.util.TraceUtil;
import com.google.android.exoplayer.util.Util;
import android.os.Handler; import android.os.Handler;
import android.os.HandlerThread; import android.os.HandlerThread;
...@@ -137,7 +138,8 @@ import java.util.List; ...@@ -137,7 +138,8 @@ import java.util.List;
} }
public void seekTo(long positionMs) { public void seekTo(long positionMs) {
handler.obtainMessage(MSG_SEEK_TO, positionMs).sendToTarget(); handler.obtainMessage(MSG_SEEK_TO, Util.getTopInt(positionMs),
Util.getBottomInt(positionMs)).sendToTarget();
} }
public void stop() { public void stop() {
...@@ -206,7 +208,7 @@ import java.util.List; ...@@ -206,7 +208,7 @@ import java.util.List;
return true; return true;
} }
case MSG_SEEK_TO: { case MSG_SEEK_TO: {
seekToInternal((Long) msg.obj); seekToInternal(Util.getLong(msg.arg1, msg.arg2));
return true; return true;
} }
case MSG_STOP: { case MSG_STOP: {
...@@ -482,8 +484,13 @@ import java.util.List; ...@@ -482,8 +484,13 @@ import java.util.List;
} }
private void seekToInternal(long positionMs) throws ExoPlaybackException { private void seekToInternal(long positionMs) throws ExoPlaybackException {
if (positionMs == (positionUs / 1000)) {
// Seek is to the current position. Do nothing.
return;
}
rebuffering = false; rebuffering = false;
positionUs = positionMs * 1000L; positionUs = positionMs * 1000;
standaloneMediaClock.stop(); standaloneMediaClock.stop();
standaloneMediaClock.setPositionUs(positionUs); standaloneMediaClock.setPositionUs(positionUs);
if (state == ExoPlayer.STATE_IDLE || state == ExoPlayer.STATE_PREPARING) { if (state == ExoPlayer.STATE_IDLE || state == ExoPlayer.STATE_PREPARING) {
......
...@@ -569,6 +569,27 @@ public final class Util { ...@@ -569,6 +569,27 @@ public final class Util {
} }
/** /**
* Returns the top 32 bits of a long as an integer.
*/
public static int getTopInt(long value) {
return (int) (value >>> 32);
}
/**
* Returns the bottom 32 bits of a long as an integer.
*/
public static int getBottomInt(long value) {
return (int) value;
}
/**
* Returns a long created by concatenating the bits of two integers.
*/
public static long getLong(int topInteger, int bottomInteger) {
return ((long) topInteger << 32) | (bottomInteger & 0xFFFFFFFFL);
}
/**
* Returns a hex string representation of the data provided. * Returns a hex string representation of the data provided.
* *
* @param data The byte array containing the data to be turned into a hex string. * @param data The byte array containing the data to be turned into a hex string.
......
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