Updating formatting to match remote
This commit is contained in:
parent
a86501c795
commit
b2d8423543
|
@ -219,31 +219,39 @@ public class PlaybackService extends Service {
|
|||
status = PlayerStatus.STOPPED;
|
||||
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
manager = FeedManager.getInstance();
|
||||
schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOL_SIZE, new ThreadFactory() {
|
||||
schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOL_SIZE,
|
||||
new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setPriority(Thread.MIN_PRIORITY);
|
||||
return t;
|
||||
}
|
||||
}, new RejectedExecutionHandler() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setPriority(Thread.MIN_PRIORITY);
|
||||
return t;
|
||||
}
|
||||
}, new RejectedExecutionHandler() {
|
||||
|
||||
@Override
|
||||
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||
Log.w(TAG, "SchedEx rejected submission of new task");
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void rejectedExecution(Runnable r,
|
||||
ThreadPoolExecutor executor) {
|
||||
Log.w(TAG, "SchedEx rejected submission of new task");
|
||||
}
|
||||
});
|
||||
|
||||
mediaButtonReceiver = new ComponentName(getPackageName(), MediaButtonReceiver.class.getName());
|
||||
mediaButtonReceiver = new ComponentName(getPackageName(),
|
||||
MediaButtonReceiver.class.getName());
|
||||
audioManager.registerMediaButtonEventReceiver(mediaButtonReceiver);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 14) {
|
||||
audioManager.registerRemoteControlClient(setupRemoteControlClient());
|
||||
audioManager
|
||||
.registerRemoteControlClient(setupRemoteControlClient());
|
||||
}
|
||||
registerReceiver(headsetDisconnected, new IntentFilter(Intent.ACTION_HEADSET_PLUG));
|
||||
registerReceiver(shutdownReceiver, new IntentFilter(ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
registerReceiver(audioBecomingNoisy, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
||||
registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(ACTION_SKIP_CURRENT_EPISODE));
|
||||
registerReceiver(headsetDisconnected, new IntentFilter(
|
||||
Intent.ACTION_HEADSET_PLUG));
|
||||
registerReceiver(shutdownReceiver, new IntentFilter(
|
||||
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
registerReceiver(audioBecomingNoisy, new IntentFilter(
|
||||
AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
||||
registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(
|
||||
ACTION_SKIP_CURRENT_EPISODE));
|
||||
|
||||
}
|
||||
|
||||
|
@ -261,17 +269,23 @@ public class PlaybackService extends Service {
|
|||
if (mp != null && media != null) {
|
||||
if (media.getMediaType() == MediaType.AUDIO) {
|
||||
((AudioPlayer) mp).setOnPreparedListener(audioPreparedListener);
|
||||
((AudioPlayer) mp).setOnCompletionListener(audioCompletionListener);
|
||||
((AudioPlayer) mp).setOnSeekCompleteListener(audioSeekCompleteListener);
|
||||
((AudioPlayer) mp)
|
||||
.setOnCompletionListener(audioCompletionListener);
|
||||
((AudioPlayer) mp)
|
||||
.setOnSeekCompleteListener(audioSeekCompleteListener);
|
||||
((AudioPlayer) mp).setOnErrorListener(audioErrorListener);
|
||||
((AudioPlayer) mp).setOnBufferingUpdateListener(audioBufferingUpdateListener);
|
||||
((AudioPlayer) mp)
|
||||
.setOnBufferingUpdateListener(audioBufferingUpdateListener);
|
||||
((AudioPlayer) mp).setOnInfoListener(audioInfoListener);
|
||||
} else {
|
||||
((VideoPlayer) mp).setOnPreparedListener(videoPreparedListener);
|
||||
((VideoPlayer) mp).setOnCompletionListener(videoCompletionListener);
|
||||
((VideoPlayer) mp).setOnSeekCompleteListener(videoSeekCompleteListener);
|
||||
((VideoPlayer) mp)
|
||||
.setOnCompletionListener(videoCompletionListener);
|
||||
((VideoPlayer) mp)
|
||||
.setOnSeekCompleteListener(videoSeekCompleteListener);
|
||||
((VideoPlayer) mp).setOnErrorListener(videoErrorListener);
|
||||
((VideoPlayer) mp).setOnBufferingUpdateListener(videoBufferingUpdateListener);
|
||||
((VideoPlayer) mp)
|
||||
.setOnBufferingUpdateListener(videoBufferingUpdateListener);
|
||||
((VideoPlayer) mp).setOnInfoListener(videoInfoListener);
|
||||
}
|
||||
}
|
||||
|
@ -325,7 +339,8 @@ public class PlaybackService extends Service {
|
|||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Gained audio focus");
|
||||
if (pausedBecauseOfTransientAudiofocusLoss) {
|
||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0);
|
||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
|
||||
AudioManager.ADJUST_RAISE, 0);
|
||||
play();
|
||||
}
|
||||
break;
|
||||
|
@ -333,7 +348,8 @@ public class PlaybackService extends Service {
|
|||
if (status == PlayerStatus.PLAYING) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Lost audio focus temporarily. Ducking...");
|
||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0);
|
||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
|
||||
AudioManager.ADJUST_LOWER, 0);
|
||||
pausedBecauseOfTransientAudiofocusLoss = true;
|
||||
}
|
||||
break;
|
||||
|
@ -362,7 +378,8 @@ public class PlaybackService extends Service {
|
|||
} else {
|
||||
|
||||
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
|
||||
boolean playbackType = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, true);
|
||||
boolean playbackType = intent.getBooleanExtra(EXTRA_SHOULD_STREAM,
|
||||
true);
|
||||
if (playable == null) {
|
||||
Log.e(TAG, "Playable extra wasn't sent to the service");
|
||||
if (media == null) {
|
||||
|
@ -370,17 +387,21 @@ public class PlaybackService extends Service {
|
|||
}
|
||||
// Intent values appear to be valid
|
||||
// check if already playing and playbackType is the same
|
||||
} else if (media == null || playable != media || playbackType != shouldStream) {
|
||||
} else if (media == null || playable != media
|
||||
|| playbackType != shouldStream) {
|
||||
pause(true, false);
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
|
||||
if (media == null || playable.getIdentifier() != media.getIdentifier()) {
|
||||
if (media == null
|
||||
|| playable.getIdentifier() != media.getIdentifier()) {
|
||||
media = playable;
|
||||
}
|
||||
|
||||
if (media != null) {
|
||||
shouldStream = playbackType;
|
||||
startWhenPrepared = intent.getBooleanExtra(EXTRA_START_WHEN_PREPARED, false);
|
||||
prepareImmediately = intent.getBooleanExtra(EXTRA_PREPARE_IMMEDIATELY, false);
|
||||
startWhenPrepared = intent.getBooleanExtra(
|
||||
EXTRA_START_WHEN_PREPARED, false);
|
||||
prepareImmediately = intent.getBooleanExtra(
|
||||
EXTRA_PREPARE_IMMEDIATELY, false);
|
||||
initMediaplayer();
|
||||
|
||||
} else {
|
||||
|
@ -444,7 +465,8 @@ public class PlaybackService extends Service {
|
|||
Log.d(TAG, "Setting display");
|
||||
player.setDisplay(null);
|
||||
player.setDisplay(sh);
|
||||
if (status == PlayerStatus.STOPPED || status == PlayerStatus.AWAITING_VIDEO_SURFACE) {
|
||||
if (status == PlayerStatus.STOPPED
|
||||
|| status == PlayerStatus.AWAITING_VIDEO_SURFACE) {
|
||||
try {
|
||||
InitTask initTask = new InitTask() {
|
||||
|
||||
|
@ -454,11 +476,13 @@ public class PlaybackService extends Service {
|
|||
if (result != null) {
|
||||
try {
|
||||
if (shouldStream) {
|
||||
player.setDataSource(media.getStreamUrl());
|
||||
player.setDataSource(media
|
||||
.getStreamUrl());
|
||||
setStatus(PlayerStatus.PREPARING);
|
||||
player.prepareAsync();
|
||||
} else {
|
||||
player.setDataSource(media.getLocalMediaUrl());
|
||||
player.setDataSource(media
|
||||
.getLocalMediaUrl());
|
||||
setStatus(PlayerStatus.PREPARING);
|
||||
player.prepareAsync();
|
||||
}
|
||||
|
@ -467,7 +491,8 @@ public class PlaybackService extends Service {
|
|||
}
|
||||
} else {
|
||||
setStatus(PlayerStatus.ERROR);
|
||||
sendBroadcast(new Intent(ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
sendBroadcast(new Intent(
|
||||
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -534,9 +559,11 @@ public class PlaybackService extends Service {
|
|||
playingVideo = false;
|
||||
try {
|
||||
if (shouldStream) {
|
||||
player.setDataSource(media.getStreamUrl());
|
||||
player.setDataSource(media
|
||||
.getStreamUrl());
|
||||
} else if (media.localFileAvailable()) {
|
||||
player.setDataSource(media.getLocalMediaUrl());
|
||||
player.setDataSource(media
|
||||
.getLocalMediaUrl());
|
||||
}
|
||||
|
||||
if (prepareImmediately) {
|
||||
|
@ -549,17 +576,20 @@ public class PlaybackService extends Service {
|
|||
e.printStackTrace();
|
||||
media = null;
|
||||
setStatus(PlayerStatus.ERROR);
|
||||
sendBroadcast(new Intent(ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
sendBroadcast(new Intent(
|
||||
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "InitTask could not load metadata");
|
||||
media = null;
|
||||
setStatus(PlayerStatus.ERROR);
|
||||
sendBroadcast(new Intent(ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
sendBroadcast(new Intent(
|
||||
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
}
|
||||
} else {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Status of player has changed during initialization. Stopping init process.");
|
||||
Log.d(TAG,
|
||||
"Status of player has changed during initialization. Stopping init process.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -588,11 +618,14 @@ public class PlaybackService extends Service {
|
|||
}
|
||||
|
||||
private void setupPositionSaver() {
|
||||
if (positionSaverFuture == null || (positionSaverFuture.isCancelled() || positionSaverFuture.isDone())) {
|
||||
if (positionSaverFuture == null
|
||||
|| (positionSaverFuture.isCancelled() || positionSaverFuture
|
||||
.isDone())) {
|
||||
|
||||
positionSaver = new PositionSaver();
|
||||
positionSaverFuture = schedExecutor.scheduleAtFixedRate(positionSaver, PositionSaver.WAITING_INTERVALL, PositionSaver.WAITING_INTERVALL,
|
||||
TimeUnit.MILLISECONDS);
|
||||
positionSaverFuture = schedExecutor.scheduleAtFixedRate(
|
||||
positionSaver, PositionSaver.WAITING_INTERVALL,
|
||||
PositionSaver.WAITING_INTERVALL, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -676,7 +709,8 @@ public class PlaybackService extends Service {
|
|||
|
||||
private final com.aocate.media.MediaPlayer.OnInfoListener audioInfoListener = new com.aocate.media.MediaPlayer.OnInfoListener() {
|
||||
@Override
|
||||
public boolean onInfo(com.aocate.media.MediaPlayer mp, int what, int extra) {
|
||||
public boolean onInfo(com.aocate.media.MediaPlayer mp, int what,
|
||||
int extra) {
|
||||
return genericInfoListener(what);
|
||||
}
|
||||
};
|
||||
|
@ -703,7 +737,8 @@ public class PlaybackService extends Service {
|
|||
|
||||
private final com.aocate.media.MediaPlayer.OnErrorListener audioErrorListener = new com.aocate.media.MediaPlayer.OnErrorListener() {
|
||||
@Override
|
||||
public boolean onError(com.aocate.media.MediaPlayer mp, int what, int extra) {
|
||||
public boolean onError(com.aocate.media.MediaPlayer mp, int what,
|
||||
int extra) {
|
||||
return genericOnError(mp, what, extra);
|
||||
}
|
||||
};
|
||||
|
@ -748,7 +783,8 @@ public class PlaybackService extends Service {
|
|||
|
||||
private final com.aocate.media.MediaPlayer.OnBufferingUpdateListener audioBufferingUpdateListener = new com.aocate.media.MediaPlayer.OnBufferingUpdateListener() {
|
||||
@Override
|
||||
public void onBufferingUpdate(com.aocate.media.MediaPlayer mp, int percent) {
|
||||
public void onBufferingUpdate(com.aocate.media.MediaPlayer mp,
|
||||
int percent) {
|
||||
genericOnBufferingUpdate(percent);
|
||||
}
|
||||
};
|
||||
|
@ -780,7 +816,8 @@ public class PlaybackService extends Service {
|
|||
((FeedMedia) media).setPlaybackCompletionDate(new Date());
|
||||
manager.markItemRead(PlaybackService.this, item, true, true);
|
||||
nextItem = manager.getQueueSuccessorOfItem(item);
|
||||
isInQueue = media instanceof FeedMedia && manager.isInQueue(((FeedMedia) media).getItem());
|
||||
isInQueue = media instanceof FeedMedia
|
||||
&& manager.isInQueue(((FeedMedia) media).getItem());
|
||||
if (isInQueue) {
|
||||
manager.removeQueueItem(PlaybackService.this, item, true);
|
||||
}
|
||||
|
@ -796,7 +833,8 @@ public class PlaybackService extends Service {
|
|||
// is an episode in the queue left.
|
||||
// Start playback immediately if continuous playback is enabled
|
||||
boolean loadNextItem = isInQueue && nextItem != null;
|
||||
playNextEpisode = playNextEpisode && loadNextItem && UserPreferences.isFollowQueue();
|
||||
playNextEpisode = playNextEpisode && loadNextItem
|
||||
&& UserPreferences.isFollowQueue();
|
||||
if (loadNextItem) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Loading next item in queue");
|
||||
|
@ -830,7 +868,8 @@ public class PlaybackService extends Service {
|
|||
if (media != null) {
|
||||
resetVideoSurface();
|
||||
refreshRemoteControlClientState();
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, notificationCode);
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD,
|
||||
notificationCode);
|
||||
} else {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_PLAYBACK_END, 0);
|
||||
stopSelf();
|
||||
|
@ -839,7 +878,8 @@ public class PlaybackService extends Service {
|
|||
|
||||
public void setSleepTimer(long waitingTime) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Setting sleep timer to " + Long.toString(waitingTime) + " milliseconds");
|
||||
Log.d(TAG, "Setting sleep timer to " + Long.toString(waitingTime)
|
||||
+ " milliseconds");
|
||||
if (sleepTimerFuture != null) {
|
||||
sleepTimerFuture.cancel(true);
|
||||
}
|
||||
|
@ -892,7 +932,9 @@ public class PlaybackService extends Service {
|
|||
public void stop() {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Stopping playback");
|
||||
if (status == PlayerStatus.PREPARED || status == PlayerStatus.PAUSED || status == PlayerStatus.STOPPED || status == PlayerStatus.PLAYING) {
|
||||
if (status == PlayerStatus.PREPARED || status == PlayerStatus.PAUSED
|
||||
|| status == PlayerStatus.STOPPED
|
||||
|| status == PlayerStatus.PLAYING) {
|
||||
player.stop();
|
||||
}
|
||||
setCurrentlyPlayingMedia(PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
|
@ -921,8 +963,11 @@ public class PlaybackService extends Service {
|
|||
|
||||
@SuppressLint("NewApi")
|
||||
public void play() {
|
||||
if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED || status == PlayerStatus.STOPPED) {
|
||||
int focusGained = audioManager.requestAudioFocus(audioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
||||
if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED
|
||||
|| status == PlayerStatus.STOPPED) {
|
||||
int focusGained = audioManager.requestAudioFocus(
|
||||
audioFocusChangeListener, AudioManager.STREAM_MUSIC,
|
||||
AudioManager.AUDIOFOCUS_GAIN);
|
||||
|
||||
if (focusGained == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||
if (AppConfig.DEBUG)
|
||||
|
@ -941,9 +986,11 @@ public class PlaybackService extends Service {
|
|||
setupNotification();
|
||||
pausedBecauseOfTransientAudiofocusLoss = false;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 14) {
|
||||
audioManager.registerRemoteControlClient(remoteControlClient);
|
||||
audioManager
|
||||
.registerRemoteControlClient(remoteControlClient);
|
||||
}
|
||||
audioManager.registerMediaButtonEventReceiver(mediaButtonReceiver);
|
||||
audioManager
|
||||
.registerMediaButtonEventReceiver(mediaButtonReceiver);
|
||||
media.onPlaybackStart();
|
||||
} else {
|
||||
if (AppConfig.DEBUG)
|
||||
|
@ -956,24 +1003,42 @@ public class PlaybackService extends Service {
|
|||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Writing playback preferences");
|
||||
|
||||
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
SharedPreferences.Editor editor = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
if (media != null) {
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, media.getPlayableType());
|
||||
editor.putBoolean(PlaybackPreferences.PREF_CURRENT_EPISODE_IS_STREAM, shouldStream);
|
||||
editor.putBoolean(PlaybackPreferences.PREF_CURRENT_EPISODE_IS_VIDEO, playingVideo);
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA,
|
||||
media.getPlayableType());
|
||||
editor.putBoolean(
|
||||
PlaybackPreferences.PREF_CURRENT_EPISODE_IS_STREAM,
|
||||
shouldStream);
|
||||
editor.putBoolean(
|
||||
PlaybackPreferences.PREF_CURRENT_EPISODE_IS_VIDEO,
|
||||
playingVideo);
|
||||
if (media instanceof FeedMedia) {
|
||||
FeedMedia fMedia = (FeedMedia) media;
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, fMedia.getItem().getFeed().getId());
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, fMedia.getId());
|
||||
editor.putLong(
|
||||
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID,
|
||||
fMedia.getItem().getFeed().getId());
|
||||
editor.putLong(
|
||||
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID,
|
||||
fMedia.getId());
|
||||
} else {
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(
|
||||
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID,
|
||||
PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(
|
||||
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID,
|
||||
PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
}
|
||||
media.writeToPreferences(editor);
|
||||
} else {
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID, PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA,
|
||||
PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEED_ID,
|
||||
PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
editor.putLong(
|
||||
PlaybackPreferences.PREF_CURRENTLY_PLAYING_FEEDMEDIA_ID,
|
||||
PlaybackPreferences.NO_MEDIA_PLAYING);
|
||||
}
|
||||
|
||||
editor.commit();
|
||||
|
@ -1007,7 +1072,8 @@ public class PlaybackService extends Service {
|
|||
/** Prepares notification and starts the service in the foreground. */
|
||||
@SuppressLint("NewApi")
|
||||
private void setupNotification() {
|
||||
final PendingIntent pIntent = PendingIntent.getActivity(this, 0, PlaybackService.getPlayerActivityIntent(this),
|
||||
final PendingIntent pIntent = PendingIntent.getActivity(this, 0,
|
||||
PlaybackService.getPlayerActivityIntent(this),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
if (notificationSetupTask != null) {
|
||||
|
@ -1022,13 +1088,17 @@ public class PlaybackService extends Service {
|
|||
Log.d(TAG, "Starting background work");
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
if (media != null && media != null) {
|
||||
int iconSize = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
|
||||
icon = BitmapDecoder.decodeBitmapFromWorkerTaskResource(iconSize, media);
|
||||
int iconSize = getResources().getDimensionPixelSize(
|
||||
android.R.dimen.notification_large_icon_width);
|
||||
icon = BitmapDecoder
|
||||
.decodeBitmapFromWorkerTaskResource(iconSize,
|
||||
media);
|
||||
}
|
||||
|
||||
}
|
||||
if (icon == null) {
|
||||
icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_antenna);
|
||||
icon = BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.ic_stat_antenna);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -1037,24 +1107,40 @@ public class PlaybackService extends Service {
|
|||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
super.onPostExecute(result);
|
||||
if (!isCancelled() && status == PlayerStatus.PLAYING && media != null) {
|
||||
if (!isCancelled() && status == PlayerStatus.PLAYING
|
||||
&& media != null) {
|
||||
String contentText = media.getFeedTitle();
|
||||
String contentTitle = media.getEpisodeTitle();
|
||||
Notification notification = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 16) {
|
||||
Intent pauseButtonIntent = new Intent(PlaybackService.this, PlaybackService.class);
|
||||
pauseButtonIntent.putExtra(MediaButtonReceiver.EXTRA_KEYCODE, KeyEvent.KEYCODE_MEDIA_PAUSE);
|
||||
PendingIntent pauseButtonPendingIntent = PendingIntent.getService(PlaybackService.this, 0, pauseButtonIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification.Builder notificationBuilder = new Notification.Builder(PlaybackService.this).setContentTitle(contentTitle)
|
||||
.setContentText(contentText).setOngoing(true).setContentIntent(pIntent).setLargeIcon(icon)
|
||||
Intent pauseButtonIntent = new Intent(
|
||||
PlaybackService.this, PlaybackService.class);
|
||||
pauseButtonIntent.putExtra(
|
||||
MediaButtonReceiver.EXTRA_KEYCODE,
|
||||
KeyEvent.KEYCODE_MEDIA_PAUSE);
|
||||
PendingIntent pauseButtonPendingIntent = PendingIntent
|
||||
.getService(PlaybackService.this, 0,
|
||||
pauseButtonIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification.Builder notificationBuilder = new Notification.Builder(
|
||||
PlaybackService.this)
|
||||
.setContentTitle(contentTitle)
|
||||
.setContentText(contentText)
|
||||
.setOngoing(true)
|
||||
.setContentIntent(pIntent)
|
||||
.setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_stat_antenna)
|
||||
.addAction(android.R.drawable.ic_media_pause, getString(R.string.pause_label), pauseButtonPendingIntent);
|
||||
.addAction(android.R.drawable.ic_media_pause,
|
||||
getString(R.string.pause_label),
|
||||
pauseButtonPendingIntent);
|
||||
notification = notificationBuilder.build();
|
||||
} else {
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(PlaybackService.this)
|
||||
.setContentTitle(contentTitle).setContentText(contentText).setOngoing(true).setContentIntent(pIntent)
|
||||
.setLargeIcon(icon).setSmallIcon(R.drawable.ic_stat_antenna);
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
|
||||
PlaybackService.this)
|
||||
.setContentTitle(contentTitle)
|
||||
.setContentText(contentText).setOngoing(true)
|
||||
.setContentIntent(pIntent).setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_stat_antenna);
|
||||
notification = notificationBuilder.getNotification();
|
||||
}
|
||||
startForeground(NOTIFICATION_ID, notification);
|
||||
|
@ -1065,7 +1151,8 @@ public class PlaybackService extends Service {
|
|||
|
||||
};
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
notificationSetupTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
notificationSetupTask
|
||||
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
notificationSetupTask.execute();
|
||||
}
|
||||
|
@ -1087,7 +1174,9 @@ public class PlaybackService extends Service {
|
|||
|
||||
public void seek(int i) {
|
||||
saveCurrentPosition();
|
||||
if (status == PlayerStatus.INITIALIZED || status == PlayerStatus.INITIALIZING || status == PlayerStatus.PREPARING) {
|
||||
if (status == PlayerStatus.INITIALIZED
|
||||
|| status == PlayerStatus.INITIALIZING
|
||||
|| status == PlayerStatus.PREPARING) {
|
||||
media.setPosition(i);
|
||||
setStartWhenPrepared(true);
|
||||
prepare();
|
||||
|
@ -1114,7 +1203,9 @@ public class PlaybackService extends Service {
|
|||
if (position != INVALID_TIME) {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Saving current position to " + position);
|
||||
media.saveCurrentPosition(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()), position);
|
||||
media.saveCurrentPosition(PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext()),
|
||||
position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1129,17 +1220,22 @@ public class PlaybackService extends Service {
|
|||
|
||||
@SuppressLint("NewApi")
|
||||
private void setupWidgetUpdater() {
|
||||
if (widgetUpdaterFuture == null || (widgetUpdaterFuture.isCancelled() || widgetUpdaterFuture.isDone())) {
|
||||
if (widgetUpdaterFuture == null
|
||||
|| (widgetUpdaterFuture.isCancelled() || widgetUpdaterFuture
|
||||
.isDone())) {
|
||||
widgetUpdater = new WidgetUpdateWorker();
|
||||
widgetUpdaterFuture = schedExecutor.scheduleAtFixedRate(widgetUpdater, WidgetUpdateWorker.NOTIFICATION_INTERVALL,
|
||||
WidgetUpdateWorker.NOTIFICATION_INTERVALL, TimeUnit.MILLISECONDS);
|
||||
widgetUpdaterFuture = schedExecutor.scheduleAtFixedRate(
|
||||
widgetUpdater, WidgetUpdateWorker.NOTIFICATION_INTERVALL,
|
||||
WidgetUpdateWorker.NOTIFICATION_INTERVALL,
|
||||
TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateWidget() {
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Sending widget update request");
|
||||
PlaybackService.this.sendBroadcast(new Intent(PlayerWidget.FORCE_WIDGET_UPDATE));
|
||||
PlaybackService.this.sendBroadcast(new Intent(
|
||||
PlayerWidget.FORCE_WIDGET_UPDATE));
|
||||
}
|
||||
|
||||
public boolean sleepTimerActive() {
|
||||
|
@ -1158,11 +1254,13 @@ public class PlaybackService extends Service {
|
|||
private RemoteControlClient setupRemoteControlClient() {
|
||||
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
|
||||
mediaButtonIntent.setComponent(mediaButtonReceiver);
|
||||
PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0);
|
||||
PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(
|
||||
getApplicationContext(), 0, mediaButtonIntent, 0);
|
||||
remoteControlClient = new RemoteControlClient(mediaPendingIntent);
|
||||
int controlFlags;
|
||||
if (android.os.Build.VERSION.SDK_INT < 16) {
|
||||
controlFlags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_NEXT;
|
||||
controlFlags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
|
||||
| RemoteControlClient.FLAG_KEY_MEDIA_NEXT;
|
||||
} else {
|
||||
controlFlags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE;
|
||||
}
|
||||
|
@ -1177,26 +1275,34 @@ public class PlaybackService extends Service {
|
|||
if (remoteControlClient != null) {
|
||||
switch (status) {
|
||||
case PLAYING:
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
|
||||
remoteControlClient
|
||||
.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
|
||||
break;
|
||||
case PAUSED:
|
||||
case INITIALIZED:
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
|
||||
remoteControlClient
|
||||
.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
|
||||
break;
|
||||
case STOPPED:
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
|
||||
remoteControlClient
|
||||
.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
|
||||
break;
|
||||
case ERROR:
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_ERROR);
|
||||
remoteControlClient
|
||||
.setPlaybackState(RemoteControlClient.PLAYSTATE_ERROR);
|
||||
break;
|
||||
default:
|
||||
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);
|
||||
remoteControlClient
|
||||
.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);
|
||||
}
|
||||
if (media != null) {
|
||||
MetadataEditor editor = remoteControlClient.editMetadata(false);
|
||||
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, media.getEpisodeTitle());
|
||||
MetadataEditor editor = remoteControlClient
|
||||
.editMetadata(false);
|
||||
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE,
|
||||
media.getEpisodeTitle());
|
||||
|
||||
editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, media.getFeedTitle());
|
||||
editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM,
|
||||
media.getFeedTitle());
|
||||
|
||||
editor.apply();
|
||||
}
|
||||
|
@ -1266,7 +1372,8 @@ public class PlaybackService extends Service {
|
|||
|
||||
/** Pauses playback if PREF_PAUSE_ON_HEADSET_DISCONNECT was set to true. */
|
||||
private void pauseIfPauseOnDisconnect() {
|
||||
if (UserPreferences.isPauseOnHeadsetDisconnect() && status == PlayerStatus.PLAYING) {
|
||||
if (UserPreferences.isPauseOnHeadsetDisconnect()
|
||||
&& status == PlayerStatus.PLAYING) {
|
||||
pause(true, true);
|
||||
}
|
||||
}
|
||||
|
@ -1310,7 +1417,8 @@ public class PlaybackService extends Service {
|
|||
try {
|
||||
saveCurrentPosition();
|
||||
} catch (IllegalStateException e) {
|
||||
Log.w(TAG, "saveCurrentPosition was called in illegal state");
|
||||
Log.w(TAG,
|
||||
"saveCurrentPosition was called in illegal state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1492,7 +1600,8 @@ public class PlaybackService extends Service {
|
|||
}
|
||||
|
||||
private void setCurrentlyPlayingMedia(long id) {
|
||||
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
SharedPreferences.Editor editor = PreferenceManager
|
||||
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
||||
editor.putLong(PlaybackPreferences.PREF_CURRENTLY_PLAYING_MEDIA, id);
|
||||
editor.commit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue