Skip to content

Commit

Permalink
Merge pull request #2917 from raphj/patch-1
Browse files Browse the repository at this point in the history
Allow a BasePlayer to start paused
  • Loading branch information
TobiGr authored Jan 26, 2020
2 parents cc83991 + 7dbb2b2 commit 609855f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ public boolean onPlayerOptionSelected(MenuItem item) {
return true;
}

this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(PopupVideoPlayer.class));
return true;
return switchTo(PopupVideoPlayer.class);
}
return false;
}
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public abstract class BasePlayer implements
@NonNull
public static final String RESUME_PLAYBACK = "resume_playback";
@NonNull
public static final String START_PAUSED = "start_paused";
@NonNull
public static final String SELECT_ON_APPEND = "select_on_append";

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -304,7 +306,7 @@ public void handleIntent(Intent intent) {
}
// Good to go...
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true);
/*playOnInit=*/!intent.getBooleanExtra(START_PAUSED, false));
}

protected void initPlayback(@NonNull final PlayQueue queue,
Expand Down Expand Up @@ -944,10 +946,10 @@ public void onPause() {
public void onPlayPause() {
if (DEBUG) Log.d(TAG, "onPlayPause() called");

if (!isPlaying()) {
onPlay();
} else {
if (isPlaying()) {
onPause();
} else {
onPlay();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ public void onFullScreenButtonClicked() {
this.getPlaybackPitch(),
this.getPlaybackSkipSilence(),
this.getPlaybackQuality(),
false
false,
!isPlaying()
);
context.startService(intent);

Expand All @@ -637,7 +638,8 @@ public void onPlayBackgroundButtonClicked() {
this.getPlaybackPitch(),
this.getPlaybackSkipSilence(),
this.getPlaybackQuality(),
false
false,
!isPlaying()
);
context.startService(intent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ public void onFullScreenButtonClicked() {
this.getPlaybackPitch(),
this.getPlaybackSkipSilence(),
this.getPlaybackQuality(),
false
false,
!isPlaying()
);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Expand Down Expand Up @@ -1123,4 +1124,4 @@ private boolean isInsideClosingRadius(MotionEvent popupMotionEvent) {
return distanceFromCloseButton(popupMotionEvent) <= getClosingRadius();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public int getPlayerOptionMenuResource() {
@Override
public boolean onPlayerOptionSelected(MenuItem item) {
if (item.getItemId() == R.id.action_switch_background) {
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(BackgroundPlayer.class));
return true;
return switchTo(BackgroundPlayer.class);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(new Intent(Settings.ACTION_SOUND_SETTINGS));
return true;
case R.id.action_switch_main:
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startActivity(getSwitchIntent(MainVideoPlayer.class));
return true;
return switchTo(MainVideoPlayer.class);
}
return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item);
}
Expand All @@ -185,8 +182,17 @@ protected Intent getSwitchIntent(final Class clazz) {
this.player.getPlaybackPitch(),
this.player.getPlaybackSkipSilence(),
null,
false,
false
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying());
}

protected boolean switchTo(final Class clazz) {
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startActivity(getSwitchIntent(clazz));
return true;
}

////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ public static Intent getPlayerIntent(@NonNull final Context context,
final float playbackPitch,
final boolean playbackSkipSilence,
@Nullable final String playbackQuality,
final boolean resumePlayback) {
final boolean resumePlayback,
final boolean startPaused) {
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback)
.putExtra(BasePlayer.REPEAT_MODE, repeatMode)
.putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed)
.putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch)
.putExtra(BasePlayer.PLAYBACK_SKIP_SILENCE, playbackSkipSilence);
.putExtra(BasePlayer.PLAYBACK_SKIP_SILENCE, playbackSkipSilence)
.putExtra(BasePlayer.START_PAUSED, startPaused);
}

public static void playOnMainPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {
Expand Down

0 comments on commit 609855f

Please sign in to comment.