1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Merge pull request #2917 from raphj/patch-1

Allow a BasePlayer to start paused
This commit is contained in:
Tobias Groza 2020-01-26 17:39:39 +01:00 committed by GitHub
commit 609855f774
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 23 deletions

View File

@ -55,10 +55,7 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity {
return true;
}
this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(PopupVideoPlayer.class));
return true;
return switchTo(PopupVideoPlayer.class);
}
return false;
}

View File

@ -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";
/*//////////////////////////////////////////////////////////////////////////
@ -304,7 +306,7 @@ public abstract class BasePlayer implements
}
// Good to go...
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true);
/*playOnInit=*/!intent.getBooleanExtra(START_PAUSED, false));
}
protected void initPlayback(@NonNull final PlayQueue queue,
@ -944,10 +946,10 @@ public abstract class BasePlayer implements
public void onPlayPause() {
if (DEBUG) Log.d(TAG, "onPlayPause() called");
if (!isPlaying()) {
onPlay();
} else {
if (isPlaying()) {
onPause();
} else {
onPlay();
}
}

View File

@ -614,7 +614,8 @@ public final class MainVideoPlayer extends AppCompatActivity
this.getPlaybackPitch(),
this.getPlaybackSkipSilence(),
this.getPlaybackQuality(),
false
false,
!isPlaying()
);
context.startService(intent);
@ -637,7 +638,8 @@ public final class MainVideoPlayer extends AppCompatActivity
this.getPlaybackPitch(),
this.getPlaybackSkipSilence(),
this.getPlaybackQuality(),
false
false,
!isPlaying()
);
context.startService(intent);

View File

@ -567,7 +567,8 @@ public final class PopupVideoPlayer extends Service {
this.getPlaybackPitch(),
this.getPlaybackSkipSilence(),
this.getPlaybackQuality(),
false
false,
!isPlaying()
);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

View File

@ -48,10 +48,7 @@ public final class PopupVideoPlayerActivity extends ServicePlayerActivity {
@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;
}

View File

@ -161,10 +161,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
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);
}
@ -185,8 +182,17 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
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;
}
////////////////////////////////////////////////////////////////////////////

View File

@ -109,12 +109,14 @@ public class NavigationHelper {
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) {