Added support for play/pause key on wired headset

This commit is contained in:
daniel oeh 2012-10-02 11:16:05 +02:00
parent d34746e049
commit 2b69696359
2 changed files with 8 additions and 2 deletions

View File

@ -96,7 +96,7 @@
android:label="@string/download_log_label" > android:label="@string/download_log_label" >
</activity> </activity>
<receiver android:name=".receiver.MediaButtonReceiver" > <receiver android:name=".receiver.MediaButtonReceiver" android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" /> <action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter> </intent-filter>

View File

@ -411,12 +411,17 @@ public class PlaybackService extends Service {
/** Handles media button events */ /** Handles media button events */
private void handleKeycode(int keycode) { private void handleKeycode(int keycode) {
if (AppConfig.DEBUG)
Log.d(TAG, "Handling keycode: " + keycode);
switch (keycode) { switch (keycode) {
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (status == PlayerStatus.PLAYING) { if (status == PlayerStatus.PLAYING) {
pause(false); pause(false);
} else if (status == PlayerStatus.PAUSED) { } else if (status == PlayerStatus.PAUSED) {
play(); play();
} else if (status == PlayerStatus.PREPARING) {
setStartWhenPrepared(!startWhenPrepared);
} }
break; break;
case KeyEvent.KEYCODE_MEDIA_PLAY: case KeyEvent.KEYCODE_MEDIA_PLAY:
@ -732,6 +737,7 @@ public class PlaybackService extends Service {
/** /**
* Saves the current position and pauses playback. Note that, if audiofocus * Saves the current position and pauses playback. Note that, if audiofocus
* is abandoned, the lockscreen controls will also disapear. * is abandoned, the lockscreen controls will also disapear.
*
* @param abandonFocus * @param abandonFocus
* is true if the service should release audio focus * is true if the service should release audio focus
*/ */
@ -976,7 +982,7 @@ public class PlaybackService extends Service {
.editMetadata(false); .editMetadata(false);
editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, editor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE,
media.getItem().getTitle()); media.getItem().getTitle());
editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, editor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM,
media.getItem().getFeed().getTitle()); media.getItem().getFeed().getTitle());