Skip to content

Commit

Permalink
Fixed bug with media button intents causing media session callback to…
Browse files Browse the repository at this point in the history
… handle the same call twice
  • Loading branch information
freshollie committed Dec 25, 2017
1 parent afd18f3 commit 5b64611
Showing 1 changed file with 2 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,8 @@ public void onPause() {
}

@Override
public void onStop() { notifyDismissed();
public void onStop() {
notifyDismissed();
}

@Override
Expand All @@ -1436,60 +1437,6 @@ public void onSkipToPrevious() {
handleSearchBackwards();
}
}

@Override
public boolean onMediaButtonEvent(Intent mediaButtonIntent) {
Log.v(TAG, "Got media button intent");
KeyEvent event = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

if (event.getAction() == KeyEvent.ACTION_UP) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (sharedPreferences.getBoolean(
getString(R.string.PREF_HEADUNIT_CONTROLLER_INPUT),
false
)) {
handlePlayRequest();
} else {
if (isPlaying()) {
handlePauseRequest();
} else {
handlePlayRequest();
}
}
return true;

case KeyEvent.KEYCODE_MEDIA_PLAY:
onPlay();
return true;

case KeyEvent.KEYCODE_MEDIA_NEXT:
onSkipToNext();
return true;

case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
onFastForward();
return true;

case KeyEvent.KEYCODE_MEDIA_REWIND:
onRewind();
return true;

case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
onSkipToPrevious();
return true;

case KeyEvent.KEYCODE_MEDIA_STOP:
onPause();
return true;

default:
return false;
}
} else {
return false;
}
}
}

private boolean searchPauseState = false;
Expand Down

0 comments on commit 5b64611

Please sign in to comment.