Skip to content

Commit

Permalink
don't call stop before preparing the player
Browse files Browse the repository at this point in the history
Issue: #5891
PiperOrigin-RevId: 248369509
  • Loading branch information
marcbaechinger authored and ojw28 committed May 31, 2019
1 parent ecb7b87 commit 0a5a8f5
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,9 @@ private boolean canDispatchMediaButtonEvent() {
return player != null && mediaButtonEventHandler != null;
}

private void stopPlayerForPrepare(boolean playWhenReady) {
private void setPlayWhenReady(boolean playWhenReady) {
if (player != null) {
player.stop();
player.setPlayWhenReady(playWhenReady);
controlDispatcher.dispatchSetPlayWhenReady(player, playWhenReady);
}
}

Expand Down Expand Up @@ -1052,14 +1051,14 @@ public void onPlay() {
} else if (player.getPlaybackState() == Player.STATE_ENDED) {
controlDispatcher.dispatchSeekTo(player, player.getCurrentWindowIndex(), C.TIME_UNSET);
}
controlDispatcher.dispatchSetPlayWhenReady(player, /* playWhenReady= */ true);
setPlayWhenReady(/* playWhenReady= */ true);
}
}

@Override
public void onPause() {
if (canDispatchPlaybackAction(PlaybackStateCompat.ACTION_PAUSE)) {
controlDispatcher.dispatchSetPlayWhenReady(player, /* playWhenReady= */ false);
setPlayWhenReady(/* playWhenReady= */ false);
}
}

Expand Down Expand Up @@ -1182,55 +1181,55 @@ public void onCommand(String command, Bundle extras, ResultReceiver cb) {
@Override
public void onPrepare() {
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE)) {
stopPlayerForPrepare(/* playWhenReady= */ false);
setPlayWhenReady(/* playWhenReady= */ false);
playbackPreparer.onPrepare();
}
}

@Override
public void onPrepareFromMediaId(String mediaId, Bundle extras) {
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_MEDIA_ID)) {
stopPlayerForPrepare(/* playWhenReady= */ false);
setPlayWhenReady(/* playWhenReady= */ false);
playbackPreparer.onPrepareFromMediaId(mediaId, extras);
}
}

@Override
public void onPrepareFromSearch(String query, Bundle extras) {
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_SEARCH)) {
stopPlayerForPrepare(/* playWhenReady= */ false);
setPlayWhenReady(/* playWhenReady= */ false);
playbackPreparer.onPrepareFromSearch(query, extras);
}
}

@Override
public void onPrepareFromUri(Uri uri, Bundle extras) {
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PREPARE_FROM_URI)) {
stopPlayerForPrepare(/* playWhenReady= */ false);
setPlayWhenReady(/* playWhenReady= */ false);
playbackPreparer.onPrepareFromUri(uri, extras);
}
}

@Override
public void onPlayFromMediaId(String mediaId, Bundle extras) {
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID)) {
stopPlayerForPrepare(/* playWhenReady= */ true);
setPlayWhenReady(/* playWhenReady= */ true);
playbackPreparer.onPrepareFromMediaId(mediaId, extras);
}
}

@Override
public void onPlayFromSearch(String query, Bundle extras) {
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH)) {
stopPlayerForPrepare(/* playWhenReady= */ true);
setPlayWhenReady(/* playWhenReady= */ true);
playbackPreparer.onPrepareFromSearch(query, extras);
}
}

@Override
public void onPlayFromUri(Uri uri, Bundle extras) {
if (canDispatchToPlaybackPreparer(PlaybackStateCompat.ACTION_PLAY_FROM_URI)) {
stopPlayerForPrepare(/* playWhenReady= */ true);
setPlayWhenReady(/* playWhenReady= */ true);
playbackPreparer.onPrepareFromUri(uri, extras);
}
}
Expand Down

0 comments on commit 0a5a8f5

Please sign in to comment.