Commit 73845dd1 authored by Geoffrey Métais's avatar Geoffrey Métais

Prevent crash on Oreo when app is in background

parent e2aa54c7
...@@ -44,13 +44,20 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver { ...@@ -44,13 +44,20 @@ public class RemoteControlClientReceiver extends MediaButtonReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final String action = intent.getAction(); final String action = intent.getAction();
if (action == null) return;
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event != null && action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) { if (event != null && action.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON)) {
if (event.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK && if (event.getKeyCode() != KeyEvent.KEYCODE_HEADSETHOOK &&
event.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { event.getKeyCode() != KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
super.onReceive(context, intent); if (!AndroidUtil.isOOrLater || VLCApplication.isForeground()) super.onReceive(context, intent);
else if (event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_MEDIA_PLAY) {
intent = new Intent(context, PlaybackService.class);
intent.setAction(Constants.ACTION_REMOTE_PLAYPAUSE);
Util.startService(context, intent);
}
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment