Commit 8c5af10a by olly Committed by Oliver Woodman

Don't pass INDEX_UNSET to ExoPlayer seek methods

It's not valid, and will cause IllegalSeekPositionException to be thrown

PiperOrigin-RevId: 327301325
parent ee743870
...@@ -294,7 +294,7 @@ import java.util.List; ...@@ -294,7 +294,7 @@ import java.util.List;
@Nullable @Nullable
public androidx.media2.common.MediaItem getCurrentMediaItem() { public androidx.media2.common.MediaItem getCurrentMediaItem() {
int index = getCurrentMediaItemIndex(); int index = getCurrentMediaItemIndex();
return (index != C.INDEX_UNSET) ? media2Playlist.get(index) : null; return index == C.INDEX_UNSET ? null : media2Playlist.get(index);
} }
public boolean prepare() { public boolean prepare() {
...@@ -307,9 +307,9 @@ import java.util.List; ...@@ -307,9 +307,9 @@ import java.util.List;
public boolean play() { public boolean play() {
if (player.getPlaybackState() == Player.STATE_ENDED) { if (player.getPlaybackState() == Player.STATE_ENDED) {
int currentWindowIndex = getCurrentMediaItemIndex();
boolean seekHandled = boolean seekHandled =
controlDispatcher.dispatchSeekTo(player, currentWindowIndex, /* positionMs= */ 0); controlDispatcher.dispatchSeekTo(
player, player.getCurrentWindowIndex(), /* positionMs= */ 0);
if (!seekHandled) { if (!seekHandled) {
return false; return false;
} }
...@@ -332,8 +332,7 @@ import java.util.List; ...@@ -332,8 +332,7 @@ import java.util.List;
} }
public boolean seekTo(long position) { public boolean seekTo(long position) {
int currentWindowIndex = getCurrentMediaItemIndex(); return controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), position);
return controlDispatcher.dispatchSeekTo(player, currentWindowIndex, position);
} }
public long getCurrentPosition() { public long getCurrentPosition() {
......
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