-Changed thumbnail toggle in disabled mode to load dark dummy image.
-Changed play queue items to display service names. -Fixed Soundcloud playlist not fitting thumbnail. -Refactored image display options to follow uniform behavior. -Refactoring and style changes on audio reactor and media button receiver.
This commit is contained in:
parent
88af9ad400
commit
f4eb3f269b
25 changed files with 206 additions and 271 deletions
|
|
@ -121,7 +121,7 @@ public final class BackgroundPlayer extends Service {
|
|||
shouldUpdateOnProgress = true;
|
||||
|
||||
mReceiverComponent = new ComponentName(this, MediaButtonReceiver.class);
|
||||
basePlayerImpl.audioReactor.registerMediaButtonEventReceiver(mReceiverComponent);
|
||||
basePlayerImpl.getAudioReactor().registerMediaButtonEventReceiver(mReceiverComponent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -152,7 +152,7 @@ public final class BackgroundPlayer extends Service {
|
|||
lockManager.releaseWifiAndCpu();
|
||||
}
|
||||
if (basePlayerImpl != null) {
|
||||
basePlayerImpl.audioReactor.unregisterMediaButtonEventReceiver(mReceiverComponent);
|
||||
basePlayerImpl.getAudioReactor().unregisterMediaButtonEventReceiver(mReceiverComponent);
|
||||
basePlayerImpl.stopActivityBinding();
|
||||
basePlayerImpl.destroy();
|
||||
}
|
||||
|
|
@ -575,38 +575,46 @@ public final class BackgroundPlayer extends Service {
|
|||
}
|
||||
|
||||
public static class MediaButtonReceiver extends BroadcastReceiver {
|
||||
|
||||
public MediaButtonReceiver() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
|
||||
KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
|
||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||
int keycode = event.getKeyCode();
|
||||
PendingIntent pendingIntent = null;
|
||||
if (keycode == KeyEvent.KEYCODE_MEDIA_NEXT) {
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_PLAY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else if (keycode == KeyEvent.KEYCODE_MEDIA_PREVIOUS) {
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else if (keycode == KeyEvent.KEYCODE_HEADSETHOOK || keycode == KeyEvent.KEYCODE_MEDIA_PAUSE || keycode == KeyEvent.KEYCODE_MEDIA_PLAY) {
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else if (keycode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_FAST_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
} else if (keycode == KeyEvent.KEYCODE_MEDIA_REWIND) {
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, new Intent(ACTION_FAST_REWIND), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
if (pendingIntent != null) {
|
||||
try {
|
||||
pendingIntent.send();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error Sending intent MediaButtonReceiver", e);
|
||||
}
|
||||
}
|
||||
if (!Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) return;
|
||||
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
|
||||
if (event.getAction() != KeyEvent.ACTION_UP) return;
|
||||
final int keycode = event.getKeyCode();
|
||||
|
||||
}
|
||||
final PendingIntent pendingIntent;
|
||||
switch (keycode) {
|
||||
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID,
|
||||
new Intent(ACTION_PLAY_NEXT), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID,
|
||||
new Intent(ACTION_PLAY_PREVIOUS), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||
case KeyEvent.KEYCODE_MEDIA_PAUSE:
|
||||
case KeyEvent.KEYCODE_MEDIA_PLAY:
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID,
|
||||
new Intent(ACTION_PLAY_PAUSE), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID,
|
||||
new Intent(ACTION_FAST_FORWARD), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_REWIND:
|
||||
pendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID,
|
||||
new Intent(ACTION_FAST_REWIND), PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
break;
|
||||
default:
|
||||
pendingIntent = null;
|
||||
}
|
||||
|
||||
if (pendingIntent == null) return;
|
||||
try {
|
||||
pendingIntent.send();
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error Sending intent MediaButtonReceiver", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -838,9 +838,9 @@ public abstract class BasePlayer implements
|
|||
"queue index=[" + playQueue.getIndex() + "]");
|
||||
|
||||
// Check if bad seek position
|
||||
} else if ((currentPlaylistSize > 0 && currentPlayQueueIndex > currentPlaylistSize) ||
|
||||
currentPlaylistIndex < 0) {
|
||||
Log.e(TAG, "Playback - Trying to seek to " +
|
||||
} else if ((currentPlaylistSize > 0 && currentPlayQueueIndex >= currentPlaylistSize) ||
|
||||
currentPlayQueueIndex < 0) {
|
||||
Log.e(TAG, "Playback - Trying to seek to invalid " +
|
||||
"index=[" + currentPlayQueueIndex + "] with " +
|
||||
"playlist length=[" + currentPlaylistSize + "]");
|
||||
|
||||
|
|
@ -848,9 +848,9 @@ public abstract class BasePlayer implements
|
|||
} else if (currentPlaylistIndex != currentPlayQueueIndex || !isPlaying()) {
|
||||
final long startPos = info != null ? info.getStartPosition() : C.TIME_UNSET;
|
||||
if (DEBUG) Log.d(TAG, "Playback - Rewinding to correct" +
|
||||
" window=[" + currentPlayQueueIndex + "]," +
|
||||
" index=[" + currentPlayQueueIndex + "]," +
|
||||
" at=[" + getTimeString((int)startPos) + "]," +
|
||||
" from=[" + simpleExoPlayer.getCurrentWindowIndex() + "].");
|
||||
" from=[" + currentPlaylistIndex + "], size=[" + currentPlaylistSize + "].");
|
||||
simpleExoPlayer.seekTo(currentPlayQueueIndex, startPos);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,14 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au
|
|||
|
||||
private static final String TAG = "AudioFocusReactor";
|
||||
|
||||
private static final boolean SHOULD_BUILD_FOCUS_REQUEST =
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||
|
||||
private static final boolean CAN_USE_MEDIA_BUTTONS =
|
||||
Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1;
|
||||
private static final String MEDIA_BUTTON_DEPRECATED_ERROR =
|
||||
"registerMediaButtonEventReceiver has been deprecated and maybe not supported anymore.";
|
||||
|
||||
private static final int DUCK_DURATION = 1500;
|
||||
private static final float DUCK_AUDIO_TO = .2f;
|
||||
|
||||
|
|
@ -38,9 +46,9 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au
|
|||
this.player = player;
|
||||
this.context = context;
|
||||
this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
player.setAudioDebugListener(this);
|
||||
player.addAudioDebugListener(this);
|
||||
|
||||
if (shouldBuildFocusRequest()) {
|
||||
if (SHOULD_BUILD_FOCUS_REQUEST) {
|
||||
request = new AudioFocusRequest.Builder(FOCUS_GAIN_TYPE)
|
||||
.setAcceptsDelayedFocusGain(true)
|
||||
.setWillPauseWhenDucked(true)
|
||||
|
|
@ -56,7 +64,7 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au
|
|||
//////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
public void requestAudioFocus() {
|
||||
if (shouldBuildFocusRequest()) {
|
||||
if (SHOULD_BUILD_FOCUS_REQUEST) {
|
||||
audioManager.requestAudioFocus(request);
|
||||
} else {
|
||||
audioManager.requestAudioFocus(this, STREAM_TYPE, FOCUS_GAIN_TYPE);
|
||||
|
|
@ -64,7 +72,7 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au
|
|||
}
|
||||
|
||||
public void abandonAudioFocus() {
|
||||
if (shouldBuildFocusRequest()) {
|
||||
if (SHOULD_BUILD_FOCUS_REQUEST) {
|
||||
audioManager.abandonAudioFocusRequest(request);
|
||||
} else {
|
||||
audioManager.abandonAudioFocus(this);
|
||||
|
|
@ -83,24 +91,20 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au
|
|||
audioManager.setStreamVolume(STREAM_TYPE, volume, 0);
|
||||
}
|
||||
|
||||
private boolean shouldBuildFocusRequest() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
|
||||
}
|
||||
|
||||
public void registerMediaButtonEventReceiver(ComponentName componentName) {
|
||||
if (android.os.Build.VERSION.SDK_INT > 27) {
|
||||
Log.e(TAG, "registerMediaButtonEventReceiver has been deprecated and maybe not supported anymore.");
|
||||
return;
|
||||
if (CAN_USE_MEDIA_BUTTONS) {
|
||||
audioManager.registerMediaButtonEventReceiver(componentName);
|
||||
} else {
|
||||
Log.e(TAG, MEDIA_BUTTON_DEPRECATED_ERROR);
|
||||
}
|
||||
audioManager.registerMediaButtonEventReceiver(componentName);
|
||||
}
|
||||
|
||||
public void unregisterMediaButtonEventReceiver(ComponentName componentName) {
|
||||
if (android.os.Build.VERSION.SDK_INT > 27) {
|
||||
Log.e(TAG, "unregisterMediaButtonEventReceiver has been deprecated and maybe not supported anymore.");
|
||||
return;
|
||||
if (CAN_USE_MEDIA_BUTTONS) {
|
||||
audioManager.unregisterMediaButtonEventReceiver(componentName);
|
||||
} else {
|
||||
Log.e(TAG, MEDIA_BUTTON_DEPRECATED_ERROR);
|
||||
}
|
||||
audioManager.unregisterMediaButtonEventReceiver(componentName);
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -165,12 +169,8 @@ public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, Au
|
|||
player.setVolume(to);
|
||||
}
|
||||
});
|
||||
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
player.setVolume(((float) animation.getAnimatedValue()));
|
||||
}
|
||||
});
|
||||
valueAnimator.addUpdateListener(animation ->
|
||||
player.setVolume(((float) animation.getAnimatedValue())));
|
||||
valueAnimator.start();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue