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();
getApplicationContext().sendBroadcast(getPlayerShutdownIntent());
getApplicationContext().startService(getSwitchIntent(PopupVideoPlayer.class));
getApplicationContext().startService(
getSwitchIntent(PopupVideoPlayer.class)
.putExtra(BasePlayer.START_PAUSED, !this.player.isPlaying())
);
return true;
}
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,

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);
@ -1123,4 +1124,4 @@ public final class PopupVideoPlayer extends Service {
return distanceFromCloseButton(popupMotionEvent) <= getClosingRadius();
}
}
}
}

View File

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

View File

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

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) {