mirror of
https://github.com/samsonjs/media.git
synced 2026-04-24 14:37:45 +00:00
Make seekTo(currentPosition) a no-op in ExoPlayer.
- Also avoid boxing when passing the seek position to the background thread. Issue: #654
This commit is contained in:
parent
6ee6bc5c59
commit
adf98b0fcc
3 changed files with 48 additions and 3 deletions
|
|
@ -144,4 +144,21 @@ public class UtilTest extends TestCase {
|
|||
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;
|
|||
import com.google.android.exoplayer.util.Assertions;
|
||||
import com.google.android.exoplayer.util.PriorityHandlerThread;
|
||||
import com.google.android.exoplayer.util.TraceUtil;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
|
|
@ -137,7 +138,8 @@ import java.util.List;
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
@ -206,7 +208,7 @@ import java.util.List;
|
|||
return true;
|
||||
}
|
||||
case MSG_SEEK_TO: {
|
||||
seekToInternal((Long) msg.obj);
|
||||
seekToInternal(Util.getLong(msg.arg1, msg.arg2));
|
||||
return true;
|
||||
}
|
||||
case MSG_STOP: {
|
||||
|
|
@ -482,8 +484,13 @@ import java.util.List;
|
|||
}
|
||||
|
||||
private void seekToInternal(long positionMs) throws ExoPlaybackException {
|
||||
if (positionMs == (positionUs / 1000)) {
|
||||
// Seek is to the current position. Do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
rebuffering = false;
|
||||
positionUs = positionMs * 1000L;
|
||||
positionUs = positionMs * 1000;
|
||||
standaloneMediaClock.stop();
|
||||
standaloneMediaClock.setPositionUs(positionUs);
|
||||
if (state == ExoPlayer.STATE_IDLE || state == ExoPlayer.STATE_PREPARING) {
|
||||
|
|
|
|||
|
|
@ -568,6 +568,27 @@ public final class Util {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue