Example usage for android.view KeyEvent KEYCODE_MEDIA_STOP

List of usage examples for android.view KeyEvent KEYCODE_MEDIA_STOP

Introduction

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

Prototype

int KEYCODE_MEDIA_STOP

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

Click Source Link

Document

Key code constant: Stop media key.

Usage

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

/**
 * {@inheritDoc}/*from   www.  j a  v  a  2  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.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  w  w  w .j av  a 2  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 = 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 . java  2 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:com.achep.acdisplay.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}/*from  w ww .java2 s  .  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.cw.litenote.note.Note.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int newPos;/*w w w. j  a  v  a 2s .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: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 {//  w w  w. jav  a  2 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:github.popeen.dsub.util.Notifications.java

private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean expanded,
        boolean playing, boolean remote, boolean isSingleFile, boolean shouldFastForward) {
    // 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 {/* w  ww  . j  av  a2 s  .c  om*/
        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 {
            imageLoader.setNowPlayingSmall(bitmap);
            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);

            if (shouldFastForward) {
                rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind);
                rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward);
            } else {
                rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward);
                rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward);
            }
        } else {
            rv.setImageViewResource(R.id.control_previous,
                    playing ? R.drawable.notification_pause : R.drawable.notification_start);
            if (shouldFastForward) {
                rv.setImageViewResource(R.id.control_pause, R.drawable.notification_fastforward);
            } else {
                rv.setImageViewResource(R.id.control_pause, R.drawable.notification_forward);
            }
            rv.setImageViewResource(R.id.control_next, R.drawable.notification_close);
        }
    } else if (shouldFastForward) {
        rv.setImageViewResource(R.id.control_previous, R.drawable.notification_rewind);
        rv.setImageViewResource(R.id.control_next, R.drawable.notification_fastforward);
    } else {
        // Necessary for switching back since it appears to re-use the same layout
        rv.setImageViewResource(R.id.control_previous, R.drawable.notification_backward);
        rv.setImageViewResource(R.id.control_next, R.drawable.notification_forward);
    }

    // Create actions for media buttons

    int previous = 0, pause = 0, next = 0, close = 0, rewind = 0, fastForward = 0;
    if (expanded) {
        pause = R.id.control_pause;

        if (shouldFastForward) {
            rewind = R.id.control_previous;
            fastForward = R.id.control_next;
        } else {
            previous = R.id.control_previous;
            next = R.id.control_next;
        }

        if (remote || persistent) {
            close = R.id.notification_close;
            rv.setViewVisibility(close, View.VISIBLE);
        }
    } else {
        if (persistent) {
            pause = R.id.control_previous;
            if (shouldFastForward) {
                fastForward = R.id.control_pause;
            } else {
                next = R.id.control_pause;
            }
            close = R.id.control_next;
        } else {
            if (shouldFastForward) {
                rewind = R.id.control_previous;
                fastForward = R.id.control_next;
            } else {
                previous = R.id.control_previous;
                next = R.id.control_next;
            }

            pause = R.id.control_pause;
        }
    }

    if (isSingleFile) {
        if (previous > 0) {
            rv.setViewVisibility(previous, View.GONE);
            previous = 0;
        }
        if (rewind > 0) {
            rv.setViewVisibility(rewind, View.GONE);
            rewind = 0;
        }

        if (next > 0) {
            rv.setViewVisibility(next, View.GONE);
            next = 0;
        }

        if (fastForward > 0) {
            rv.setViewVisibility(fastForward, View.GONE);
            fastForward = 0;
        }
    }

    PendingIntent pendingIntent;
    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_UP, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(previous, pendingIntent);
    }
    if (rewind > 0) {
        Intent rewindIntent = new Intent("KEYCODE_MEDIA_REWIND");
        rewindIntent.setComponent(new ComponentName(context, DownloadService.class));
        rewindIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_REWIND));
        pendingIntent = PendingIntent.getService(context, 0, rewindIntent, 0);
        rv.setOnClickPendingIntent(rewind, 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_UP, 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_UP, 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_UP, KeyEvent.KEYCODE_MEDIA_NEXT));
        pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0);
        rv.setOnClickPendingIntent(next, pendingIntent);
    }
    if (fastForward > 0) {
        Intent fastForwardIntent = new Intent("KEYCODE_MEDIA_FAST_FORWARD");
        fastForwardIntent.setComponent(new ComponentName(context, DownloadService.class));
        fastForwardIntent.putExtra(Intent.EXTRA_KEY_EVENT,
                new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_FAST_FORWARD));
        pendingIntent = PendingIntent.getService(context, 0, fastForwardIntent, 0);
        rv.setOnClickPendingIntent(fastForward, 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_UP, KeyEvent.KEYCODE_MEDIA_STOP));
        pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
        rv.setOnClickPendingIntent(close, pendingIntent);
    }
}

From source file:com.example.android.mediarouter.player.MainActivity.java

public boolean handleMediaKey(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: {
            Log.d(TAG, "Received Play/Pause event from RemoteControlClient");
            mPaused = !mPaused;/* w  w  w. j  a v a  2  s  .co  m*/
            if (mPaused) {
                mSessionManager.pause();
            } else {
                mSessionManager.resume();
            }
            return true;
        }
        case KeyEvent.KEYCODE_MEDIA_PLAY: {
            Log.d(TAG, "Received Play event from RemoteControlClient");
            if (mPaused) {
                mPaused = false;
                mSessionManager.resume();
            }
            return true;
        }
        case KeyEvent.KEYCODE_MEDIA_PAUSE: {
            Log.d(TAG, "Received Pause event from RemoteControlClient");
            if (!mPaused) {
                mPaused = true;
                mSessionManager.pause();
            }
            return true;
        }
        case KeyEvent.KEYCODE_MEDIA_STOP: {
            Log.d(TAG, "Received Stop event from RemoteControlClient");
            mPaused = false;
            mSessionManager.stop();
            return true;
        }
        default:
            break;
        }
    }
    return false;
}

From source file:android.widget.TiVideoView4.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mIsPrepared && keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_MENU
            && keyCode != KeyEvent.KEYCODE_CALL && keyCode != KeyEvent.KEYCODE_ENDCALL && mMediaPlayer != null
            && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();// w ww .j  a  v a  2 s.c o  m
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP && mMediaPlayer.isPlaying()) {
            pause();
            mMediaController.show();
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.mobilevue.vod.VideoControllerView.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPlayer == null) {
        return true;
    }//from w  w w.jav a 2s . co m

    int keyCode = event.getKeyCode();
    final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN;
    if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
            || keyCode == KeyEvent.KEYCODE_SPACE) {
        if (uniqueDown) {
            doPauseResume();
            show(sDefaultTimeout);
            if (mPauseButton != null) {
                mPauseButton.requestFocus();
            }
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
        if (uniqueDown && !mPlayer.isPlaying()) {
            mPlayer.start();
            updatePausePlay();
            show(sDefaultTimeout);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
        if (uniqueDown && mPlayer.isPlaying()) {
            mPlayer.pause();
            updatePausePlay();
            show(sDefaultTimeout);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP
            || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
        // don't show the controls for volume adjustment
        return super.dispatchKeyEvent(event);
    } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
        if (uniqueDown) {
            hide();
        }
        return true;
    }

    show(sDefaultTimeout);
    return super.dispatchKeyEvent(event);
}