Example usage for android.view KeyEvent KEYCODE_MEDIA_PREVIOUS

List of usage examples for android.view KeyEvent KEYCODE_MEDIA_PREVIOUS

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_MEDIA_PREVIOUS.

Prototype

int KEYCODE_MEDIA_PREVIOUS

To view the source code for android.view KeyEvent KEYCODE_MEDIA_PREVIOUS.

Click Source Link

Document

Key code constant: Play Previous media key.

Usage

From source file:com.doctoror.fuckoffmusicplayer.presentation.playback.PlaybackAndroidService.java

private void onActionMediaButton(@NonNull final Intent intent) {
    final KeyEvent keyEvent = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyEvent.getKeyCode()) {
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            onActionPlayPause();/*w  w  w.j  av  a2 s .  co m*/
            break;

        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            onActionPause();
            break;

        case KeyEvent.KEYCODE_MEDIA_NEXT:
            onActionNext();
            break;

        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            onActionPrev();
            break;

        case KeyEvent.KEYCODE_MEDIA_STOP:
            onActionStop();
            break;

        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            onActionPlayPause();
            break;
        }
    }
}

From source file:singh.amandeep.musicplayer.MediaButtonIntentReceiver.java

/**
 * {@inheritDoc}/*w  w  w  .  j  a v a  2 s.  c  o m*/
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, MusicService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:com.bullmobi.message.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}/*from w w w  .j  av a2 s . c  o  m*/
 */
public void sendMediaAction(int action) {
    int keyCode;
    switch (action) {
    case ACTION_PLAY_PAUSE:
        keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
        break;
    case ACTION_STOP:
        keyCode = KeyEvent.KEYCODE_MEDIA_STOP;
        break;
    case ACTION_SKIP_TO_NEXT:
        keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
        break;
    case ACTION_SKIP_TO_PREVIOUS:
        keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        break;
    default:
        throw new IllegalArgumentException();
    }

    // TODO We should think about sending these up/down events accurately with touch up/down
    // on the buttons, but in the near term this will interfere with the long press behavior.
    RemoteController rc = mService.getRemoteController();
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
}

From source file:com.cw.litenote.note.Note.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int newPos;// w w w.ja  v  a2s.  c  o m
    System.out.println("Note / _onKeyDown / keyCode = " + keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS: //88
        if (viewPager.getCurrentItem() == 0)
            newPos = mPagerAdapter.getCount() - 1;//back to last one
        else
            newPos = NoteUi.getFocus_notePos() - 1;

        NoteUi.setFocus_notePos(newPos);
        viewPager.setCurrentItem(newPos);

        BackgroundAudioService.mIsPrepared = false;
        BackgroundAudioService.mMediaPlayer = null;
        Audio_manager.isRunnableOn_page = false;
        findViewById(R.id.pager_btn_audio_play).performClick();
        return true;

    case KeyEvent.KEYCODE_MEDIA_NEXT: //87
        if (viewPager.getCurrentItem() == (mPagerAdapter.getCount() - 1))
            newPos = 0;
        else
            newPos = NoteUi.getFocus_notePos() + 1;

        NoteUi.setFocus_notePos(newPos);
        viewPager.setCurrentItem(newPos);

        BackgroundAudioService.mIsPrepared = false;
        BackgroundAudioService.mMediaPlayer = null;
        Audio_manager.isRunnableOn_page = false;
        AudioUi_note.mPager_audio_play_button.performClick();
        return true;

    case KeyEvent.KEYCODE_MEDIA_PLAY: //126
        AudioUi_note.mPager_audio_play_button.performClick();
        return true;

    case KeyEvent.KEYCODE_MEDIA_PAUSE: //127
        AudioUi_note.mPager_audio_play_button.performClick();
        return true;

    case KeyEvent.KEYCODE_BACK:
        onBackPressed();
        return true;

    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
        return true;

    case KeyEvent.KEYCODE_MEDIA_REWIND:
        return true;

    case KeyEvent.KEYCODE_MEDIA_STOP:
        return true;
    }
    return false;
}

From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}//from   w  w  w.j a v  a 2s . c  om
 */
public void sendMediaAction(int action) {
    if (mService == null) {
        Log.w(TAG, "Sending a media action on stopped controller.");
        return;
    }

    int keyCode;
    switch (action) {
    case ACTION_PLAY_PAUSE:
        keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
        break;
    case ACTION_STOP:
        keyCode = KeyEvent.KEYCODE_MEDIA_STOP;
        break;
    case ACTION_SKIP_TO_NEXT:
        keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
        break;
    case ACTION_SKIP_TO_PREVIOUS:
        keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        break;
    default:
        throw new IllegalArgumentException();
    }

    // TODO We should think about sending these up/down events accurately with touch up/down
    // on the buttons, but in the near term this will interfere with the long press behavior.
    RemoteController rc = mService.getRemoteController();
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
    rc.sendMediaKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
}

From source file:com.av.remusic.receiver.MediaButtonIntentReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        if (true)
            startService(context, MediaService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }/*from www  .j  a v a2  s. c  om*/

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MediaService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MediaService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MediaService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MediaService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MediaService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MediaService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MediaService.CMDTOGGLEPAUSE.equals(command) || MediaService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {

                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:com.bluros.music.helpers.MediaButtonIntentReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        if (PreferencesUtility.getInstance(context).pauseEnabledOnDetach())
            startService(context, MusicService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }/*www  .  ja  v a2  s . c o  m*/

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {

                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:github.daneren2005.dsub.util.Notifications.java

private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded,
        boolean playing, boolean remote) {

    // Use the same text for the ticker and the expanded notification
    String title = song.getTitle();
    String arist = song.getArtist();
    String album = song.getAlbum();

    // Set the album art.
    try {//from  ww w . jav  a2 s. c  o  m
        ImageLoader imageLoader = SubsonicActivity.getStaticImageLoader(context);
        Bitmap bitmap = null;
        if (imageLoader != null) {
            bitmap = imageLoader.getCachedImage(context, song, false);
        }
        if (bitmap == null) {
            // set default album art
            rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
        } else {
            rv.setImageViewBitmap(R.id.notification_image, bitmap);
        }
    } catch (Exception x) {
        Log.w(TAG, "Failed to get notification cover art", x);
        rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
    }

    // set the text for the notifications
    rv.setTextViewText(R.id.notification_title, title);
    rv.setTextViewText(R.id.notification_artist, arist);
    rv.setTextViewText(R.id.notification_album, album);

    boolean persistent = Util.getPreferences(context)
            .getBoolean(Constants.PREFERENCES_KEY_PERSISTENT_NOTIFICATION, false);
    if (persistent) {
        if (expanded) {
            rv.setImageViewResource(R.id.control_pause,
                    playing ? R.drawable.notification_pause : R.drawable.notification_start);
        } else {
            rv.setImageViewResource(R.id.control_previous,
                    playing ? R.drawable.notification_pause : R.drawable.notification_start);
            rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward);
            rv.setImageViewResource(R.id.control_next, R.drawable.notification_close);
        }
    }

    // Create actions for media buttons
    PendingIntent pendingIntent;
    int previous = 0, pause = 0, next = 0, close = 0;
    if (persistent && !expanded) {
        pause = R.id.control_previous;
        next = R.id.control_pause;
        close = R.id.control_next;
    } else {
        previous = R.id.control_previous;
        pause = R.id.control_pause;
        next = R.id.control_next;
    }

    if ((remote || persistent) && close == 0 && expanded) {
        close = R.id.notification_close;
        rv.setViewVisibility(close, View.VISIBLE);
    }

    if (previous > 0) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
        prevIntent.setComponent(new ComponentName(context, DownloadService.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(previous, pendingIntent);
    }
    if (pause > 0) {
        if (playing) {
            Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
            pauseIntent.setComponent(new ComponentName(context, DownloadService.class));
            pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                    new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
            pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0);
            rv.setOnClickPendingIntent(pause, pendingIntent);
        } else {
            Intent prevIntent = new Intent("KEYCODE_MEDIA_START");
            prevIntent.setComponent(new ComponentName(context, DownloadService.class));
            prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                    new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY));
            pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
            rv.setOnClickPendingIntent(pause, pendingIntent);
        }
    }
    if (next > 0) {
        Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
        nextIntent.setComponent(new ComponentName(context, DownloadService.class));
        nextIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
        pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
        rv.setOnClickPendingIntent(next, pendingIntent);
    }
    if (close > 0) {
        Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
        prevIntent.setComponent(new ComponentName(context, DownloadService.class));
        prevIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(close, pendingIntent);
    }
}

From source file:net.sourceforge.kalimbaradio.androidapp.util.NotificationUtil.java

private static RemoteViews createBigContentView(Context context, MusicDirectory.Entry song, Bitmap albumArt,
        boolean playing) {

    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
    contentView.setTextViewText(R.id.notification_title, song.getTitle());
    contentView.setTextViewText(R.id.notification_artist, song.getArtist());
    contentView.setTextViewText(R.id.notification_album, song.getAlbum());
    contentView.setImageViewBitmap(R.id.notification_image, albumArt);
    contentView.setImageViewResource(R.id.notification_playpause,
            playing ? R.drawable.media_pause : R.drawable.media_start);

    Intent intent = new Intent("1");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
    contentView.setOnClickPendingIntent(R.id.notification_playpause,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("2");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT));
    contentView.setOnClickPendingIntent(R.id.notification_next,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("3");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Intent.EXTRA_KEY_EVENT,
            new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
    contentView.setOnClickPendingIntent(R.id.notification_prev,
            PendingIntent.getService(context, 0, intent, 0));

    intent = new Intent("4");
    intent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
    intent.putExtra(Constants.INTENT_EXTRA_NAME_HIDE_NOTIFICATION, true);
    contentView.setOnClickPendingIntent(R.id.notification_close,
            PendingIntent.getService(context, 0, intent, 0));

    return contentView;
}

From source file:net.sf.asap.Player.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mediaController == null) {
        // error shown
        return super.onKeyDown(keyCode, event);
    }/* w w w  .  j  av a 2s. c  om*/
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        if (isPaused())
            resume();
        else
            audioTrack.pause();
        return true;
    case KeyEvent.KEYCODE_MEDIA_NEXT:
        playNextSong();
        return true;
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        playPreviousSong();
        return true;
    default:
        return super.onKeyDown(keyCode, event);
    }
}