Add field START_PAUSED to the Player Intent

This allows fixing spurious playback resume when minimizing to the background player.
This commit is contained in:
Raphaël Jakse 2020-01-16 20:44:08 +01:00
parent 9f47a274a8
commit 570dded8d6
7 changed files with 27 additions and 10 deletions

View file

@ -57,7 +57,10 @@ public final class BackgroundPlayerActivity extends ServicePlayerActivity {
this.player.setRecovery(); this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(PopupVideoPlayer.class)); getApplicationContext().startService(
getSwitchIntent(PopupVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true; return true;
} }
return false; return false;

View file

@ -150,6 +150,8 @@ public abstract class BasePlayer implements
@NonNull @NonNull
public static final String RESUME_PLAYBACK = "resume_playback"; public static final String RESUME_PLAYBACK = "resume_playback";
@NonNull @NonNull
public static final String START_PAUSED = "start_paused";
@NonNull
public static final String SELECT_ON_APPEND = "select_on_append"; public static final String SELECT_ON_APPEND = "select_on_append";
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
@ -304,7 +306,7 @@ public abstract class BasePlayer implements
} }
// Good to go... // Good to go...
initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence, initPlayback(queue, repeatMode, playbackSpeed, playbackPitch, playbackSkipSilence,
/*playOnInit=*/true); /*playOnInit=*/!intent.getBooleanExtra(START_PAUSED, false));
} }
protected void initPlayback(@NonNull final PlayQueue queue, protected void initPlayback(@NonNull final PlayQueue queue,

View file

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

View file

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

View file

@ -50,7 +50,10 @@ public final class PopupVideoPlayerActivity extends ServicePlayerActivity {
if (item.getItemId() == R.id.action_switch_background) { if (item.getItemId() == R.id.action_switch_background) {
this.player.setRecovery(); this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(BackgroundPlayer.class)); getApplicationContext().startService(
getSwitchIntent(BackgroundPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true; return true;
} }
return false; return false;

View file

@ -167,7 +167,10 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
case R.id.action_switch_main: case R.id.action_switch_main:
this.player.setRecovery(); this.player.setRecovery();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent()); getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startActivity(getSwitchIntent(MainVideoPlayer.class)); getApplicationContext().startActivity(
getSwitchIntent(MainVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true; return true;
} }
return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item); return onPlayerOptionSelected(item) || super.onOptionsItemSelected(item);
@ -189,6 +192,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
this.player.getPlaybackPitch(), this.player.getPlaybackPitch(),
this.player.getPlaybackSkipSilence(), this.player.getPlaybackSkipSilence(),
null, null,
false,
false false
).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} }

View file

@ -109,12 +109,14 @@ public class NavigationHelper {
final float playbackPitch, final float playbackPitch,
final boolean playbackSkipSilence, final boolean playbackSkipSilence,
@Nullable final String playbackQuality, @Nullable final String playbackQuality,
final boolean resumePlayback) { final boolean resumePlayback,
final boolean startPaused) {
return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback) return getPlayerIntent(context, targetClazz, playQueue, playbackQuality, resumePlayback)
.putExtra(BasePlayer.REPEAT_MODE, repeatMode) .putExtra(BasePlayer.REPEAT_MODE, repeatMode)
.putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed) .putExtra(BasePlayer.PLAYBACK_SPEED, playbackSpeed)
.putExtra(BasePlayer.PLAYBACK_PITCH, playbackPitch) .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) { public static void playOnMainPlayer(final Context context, final PlayQueue queue, final boolean resumePlayback) {