Review changes
This commit is contained in:
parent
ffdfefc35d
commit
f66e19845c
|
@ -613,11 +613,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
|
|||
Log.d(TAG, "onResume()");
|
||||
StorageUtils.checkStorageAvailability(this);
|
||||
if (controller != null) {
|
||||
if (PlaybackService.isRunning) {
|
||||
controller.init();
|
||||
} else {
|
||||
controller.resumeServiceNotRunning();
|
||||
}
|
||||
controller.init();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,15 +81,11 @@ public class DefaultActionButtonCallback implements ActionButtonCallback {
|
|||
}
|
||||
} else { // media is downloaded
|
||||
if (item.hasMedia() && item.getMedia().isCurrentlyPlaying()) {
|
||||
if (!PlaybackService.isRunning) {
|
||||
PlaybackService.startService(context, media, true, false);
|
||||
}
|
||||
PlaybackService.startIfNotRunning(context, media, true, false);
|
||||
context.sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
|
||||
}
|
||||
else if (item.hasMedia() && item.getMedia().isCurrentlyPaused()) {
|
||||
if (!PlaybackService.isRunning) {
|
||||
PlaybackService.startService(context, media, true, false);
|
||||
}
|
||||
PlaybackService.startIfNotRunning(context, media, true, false);
|
||||
context.sendBroadcast(new Intent(PlaybackService.ACTION_RESUME_PLAY_CURRENT_EPISODE));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -127,11 +127,7 @@ public class ExternalPlayerFragment extends Fragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (PlaybackService.isRunning) {
|
||||
controller.init();
|
||||
} else {
|
||||
controller.resumeServiceNotRunning();
|
||||
}
|
||||
controller.init();
|
||||
onPositionObserverUpdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -244,9 +244,7 @@ public class ItemFragment extends Fragment implements OnSwipeGesture {
|
|||
if (item.hasMedia()) {
|
||||
FeedMedia media = item.getMedia();
|
||||
if (!media.isDownloaded()) {
|
||||
if (!PlaybackService.isRunning) {
|
||||
PlaybackService.startService(getActivity(), media, true, false);
|
||||
}
|
||||
PlaybackService.startIfNotRunning(getActivity(), media, true, false);
|
||||
DBTasks.playMedia(getActivity(), media, true, true, true);
|
||||
((MainActivity) getActivity()).dismissChildFragment();
|
||||
} else {
|
||||
|
|
|
@ -111,7 +111,6 @@ public class UserPreferences {
|
|||
|
||||
// JobScheduler
|
||||
private static final int JOB_ID_FEED_UPDATE = 42;
|
||||
private static final float JOB_SCHEDULER_TIME_VARIATION = 1.5f;
|
||||
|
||||
// Mediaplayer
|
||||
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
|
||||
|
@ -813,13 +812,19 @@ public class UserPreferences {
|
|||
return;
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
JobInfo.Builder builder = getFeedUpdateJobBuilder();
|
||||
builder.setOverrideDeadline((long) (triggerAtMillis * JOB_SCHEDULER_TIME_VARIATION));
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
|
||||
if (jobScheduler != null) {
|
||||
jobScheduler.schedule(builder.build());
|
||||
Log.d(TAG, "JobScheduler was set for " + triggerAtMillis);
|
||||
JobInfo oldJob = jobScheduler.getPendingJob(JOB_ID_FEED_UPDATE);
|
||||
if (oldJob == null || oldJob.getIntervalMillis() != intervalMillis) {
|
||||
JobInfo.Builder builder = getFeedUpdateJobBuilder();
|
||||
builder.setPeriodic(intervalMillis);
|
||||
jobScheduler.cancel(JOB_ID_FEED_UPDATE);
|
||||
jobScheduler.schedule(builder.build());
|
||||
Log.d(TAG, "JobScheduler was set at interval " + intervalMillis);
|
||||
} else {
|
||||
Log.d(TAG, "JobScheduler was already set at interval " + intervalMillis + ", ignoring.");
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -848,12 +853,13 @@ public class UserPreferences {
|
|||
alarm.add(Calendar.DATE, 1);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
JobInfo.Builder builder = getFeedUpdateJobBuilder();
|
||||
long triggerAtMillis = alarm.getTimeInMillis() - now.getTimeInMillis();
|
||||
builder.setOverrideDeadline((long) (triggerAtMillis * JOB_SCHEDULER_TIME_VARIATION));
|
||||
builder.setMinimumLatency(triggerAtMillis);
|
||||
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
|
||||
if (jobScheduler != null) {
|
||||
jobScheduler.cancel(JOB_ID_FEED_UPDATE);
|
||||
jobScheduler.schedule(builder.build());
|
||||
Log.d(TAG, "JobScheduler was set for " + triggerAtMillis);
|
||||
}
|
||||
|
@ -876,7 +882,6 @@ public class UserPreferences {
|
|||
private static JobInfo.Builder getFeedUpdateJobBuilder() {
|
||||
ComponentName serviceComponent = new ComponentName(context, FeedUpdateJobService.class);
|
||||
JobInfo.Builder builder = new JobInfo.Builder(JOB_ID_FEED_UPDATE, serviceComponent);
|
||||
builder.setMinimumLatency(15 * 60 * 1000);
|
||||
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
|
||||
return builder;
|
||||
}
|
||||
|
|
|
@ -795,6 +795,12 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
}
|
||||
};
|
||||
|
||||
public static void startIfNotRunning(final Context context, final Playable media, boolean startWhenPrepared, boolean shouldStream) {
|
||||
if (!isRunning) {
|
||||
startService(context, media, startWhenPrepared, shouldStream);
|
||||
}
|
||||
}
|
||||
|
||||
public static void startService(final Context context, final Playable media, boolean startWhenPrepared, boolean shouldStream) {
|
||||
Intent launchIntent = new Intent(context, PlaybackService.class);
|
||||
launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, media);
|
||||
|
|
|
@ -96,7 +96,15 @@ public abstract class PlaybackController {
|
|||
/**
|
||||
* Creates a new connection to the playbackService.
|
||||
*/
|
||||
public synchronized void init() {
|
||||
public void init() {
|
||||
if (PlaybackService.isRunning) {
|
||||
initServiceRunning();
|
||||
} else {
|
||||
initServiceNotRunning();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void initServiceRunning() {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
@ -779,7 +787,7 @@ public abstract class PlaybackController {
|
|||
}
|
||||
}
|
||||
|
||||
public void resumeServiceNotRunning() {
|
||||
private void initServiceNotRunning() {
|
||||
if (getMedia() == null) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue