当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.KEYCODE_HEADSETHOOK属性代码示例

本文整理汇总了Java中android.view.KeyEvent.KEYCODE_HEADSETHOOK属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.KEYCODE_HEADSETHOOK属性的具体用法?Java KeyEvent.KEYCODE_HEADSETHOOK怎么用?Java KeyEvent.KEYCODE_HEADSETHOOK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.view.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.KEYCODE_HEADSETHOOK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onKeyDown

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK &&
            keyCode != KeyEvent.KEYCODE_VOLUME_UP &&
            keyCode != KeyEvent.KEYCODE_VOLUME_DOWN &&
            keyCode != KeyEvent.KEYCODE_VOLUME_MUTE &&
            keyCode != KeyEvent.KEYCODE_MENU &&
            keyCode != KeyEvent.KEYCODE_CALL &&
            keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
                keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisibility();
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:IjkVideoView.java

示例2: onKeyDown

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK &&
            keyCode != KeyEvent.KEYCODE_VOLUME_UP &&
            keyCode != KeyEvent.KEYCODE_VOLUME_DOWN &&
            keyCode != KeyEvent.KEYCODE_VOLUME_MUTE &&
            keyCode != KeyEvent.KEYCODE_MENU &&
            keyCode != KeyEvent.KEYCODE_CALL &&
            keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
                keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (isPlaying()) {
                pause();
                //                    mController.setVisibility(VISIBLE);
            } else {
                start();
                //                    mController.setVisibility(GONE);
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!isPlaying()) {
                start();
                //                    mController.setVisibility(GONE);
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (isPlaying()) {
                pause();
                //                    mController.setVisibility(VISIBLE);
            }
            return true;
        } else {
            //                toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
开发者ID:SethWen,项目名称:GestureVideoView,代码行数:40,代码来源:GestureVideoView.java

示例3: onReceive

@Override
public void onReceive(Context context, Intent intent) {
  KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
  Log.d("MediabuttonReciever " + event);

  if (!Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction()) || event == null || event.getAction() != KeyEvent.ACTION_DOWN) {
    return;
  }

  switch (event.getKeyCode()) {
    case KeyEvent.KEYCODE_HEADSETHOOK:
    case KeyEvent.KEYCODE_MEDIA_STOP:
    case KeyEvent.KEYCODE_MEDIA_PAUSE:
      if (App.afspiller.getAfspillerstatus() != Status.STOPPET) {
        App.afspiller.pauseAfspilning();
      }
      break;
    case KeyEvent.KEYCODE_MEDIA_PLAY:
    case KeyEvent.KEYCODE_MEDIA_REWIND:
    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
      if (App.afspiller.getAfspillerstatus() == Status.STOPPET) {
        App.afspiller.startAfspilning();
      }
      break;
    case KeyEvent.KEYCODE_MEDIA_NEXT:
      App.afspiller.næste();
      break;
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
      App.afspiller.forrige();
      break;
    case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
    default:
      if (App.afspiller.getAfspillerstatus() == Status.STOPPET) {
        App.afspiller.startAfspilning();
      } else {
        App.afspiller.pauseAfspilning();
        if (App.afspiller.afspillerlyde) App.afspiller.afspillerlyd.stop.start();
      }
  }
}
 
开发者ID:nordfalk,项目名称:EsperantoRadio,代码行数:40,代码来源:FjernbetjeningReciever.java

示例4: onKeyDown

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK &&
            keyCode != KeyEvent.KEYCODE_VOLUME_UP &&
            keyCode != KeyEvent.KEYCODE_VOLUME_DOWN &&
            keyCode != KeyEvent.KEYCODE_VOLUME_MUTE &&
            keyCode != KeyEvent.KEYCODE_MENU &&
            keyCode != KeyEvent.KEYCODE_CALL &&
            keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
                keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            } else {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!mMediaPlayer.isPlaying()) {
                start();
                mMediaController.hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (mMediaPlayer.isPlaying()) {
                pause();
                mMediaController.show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}
 
开发者ID:lanyan520,项目名称:Idea-ijkplayer,代码行数:40,代码来源:IjkVideoView.java

示例5: onKeyDown

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

  boolean isKeyCodeSupported = 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;
  if (isInPlaybackState() && isKeyCodeSupported
      && mMediaController != null) {
    if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK
        || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
        || keyCode == KeyEvent.KEYCODE_SPACE) {
      if (mMediaPlayer.isPlaying()) {
        pause();
        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);
}
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:33,代码来源:VideoPlayerView.java

示例6: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
        KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

        if (event == null)
            return;
        if (event.getAction() != KeyEvent.ACTION_DOWN)
            return;

        switch (event.getKeyCode())
        {
            case KeyEvent.KEYCODE_MEDIA_STOP:
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY:
                sendMessage(context, PlayerService.PLAY);
                break;
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
                sendMessage(context, PlayerService.PLAY);
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:

                sendMessage(context, PlayerService.PLAY);
                break;
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                sendMessage(context, PlayerService.NEXT);
                break;
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                sendMessage(context, PlayerService.PREV);
                break;
            case KeyEvent.KEYCODE_VOLUME_UP:
                sendMessage(context, PlayerService.VOLUME_UP);
                break;
            case KeyEvent.KEYCODE_VOLUME_DOWN:
                sendMessage(context, PlayerService.VOLUME_DOWN);
                break;
        }
    }

}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:40,代码来源:MediaControlReceiver.java

示例7: dispatchKeyEvent

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPlayerCtrl == null) {
        return true;
    }

    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(DEFTIMEOUT);
            if (mBtnPause != null) {
                mBtnPause.requestFocus();
            }
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
        if (uniqueDown && !mPlayerCtrl.isPlaying()) {
            mPlayerCtrl.start();
            updatePausePlay();
            show(DEFTIMEOUT);
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
            || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
        if (uniqueDown && mPlayerCtrl.isPlaying()) {
            mPlayerCtrl.pause();
            updatePausePlay();
            show(DEFTIMEOUT);
        }
        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(DEFTIMEOUT);
    return super.dispatchKeyEvent(event);
}
 
开发者ID:natjs,项目名称:nat-media-video,代码行数:50,代码来源:Controller.java

示例8: dispatchKeyEvent

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPlayer == null) {
        return true;
    }
    
    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();
        }
        if(mPlayer.isPlaying())
        {
            mPlayer.stop();
        }
        return true;
    }

    show(sDefaultTimeout);
    return super.dispatchKeyEvent(event);
}
 
开发者ID:adarshgumashta,项目名称:Facebook-Video-Downloader,代码行数:55,代码来源:VideoControllerView.java

示例9: dispatchKeyEvent

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPlayer == null) {
        return true;
    }

    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);
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:50,代码来源:VideoControllerView.java

示例10: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
        if (intent.getExtras() == null) {
            return;
        }
        KeyEvent keyEvent = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
        if (keyEvent == null) {
            return;
        }
        if (keyEvent.getAction() != KeyEvent.ACTION_DOWN)
            return;

        switch (keyEvent.getKeyCode()) {
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                if (MediaController.getInstance().isAudioPaused()) {
                    MediaController.getInstance().playAudio(MediaController.getInstance().getPlayingMessageObject());
                } else {
                    MediaController.getInstance().pauseAudio(MediaController.getInstance().getPlayingMessageObject());
                }
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY:
                MediaController.getInstance().playAudio(MediaController.getInstance().getPlayingMessageObject());
                break;
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
                MediaController.getInstance().pauseAudio(MediaController.getInstance().getPlayingMessageObject());
                break;
            case KeyEvent.KEYCODE_MEDIA_STOP:
                break;
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                MediaController.getInstance().playNextMessage();
                break;
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                MediaController.getInstance().playPreviousMessage();
                break;
        }
    } else {
        if (intent.getAction().equals(MusicPlayerService.NOTIFY_PLAY)) {
            MediaController.getInstance().playAudio(MediaController.getInstance().getPlayingMessageObject());
        } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_PAUSE) || intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
            MediaController.getInstance().pauseAudio(MediaController.getInstance().getPlayingMessageObject());
        } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_NEXT)) {
            MediaController.getInstance().playNextMessage();
        } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_CLOSE)) {
            MediaController.getInstance().cleanupPlayer(true, true);
        } else if (intent.getAction().equals(MusicPlayerService.NOTIFY_PREVIOUS)) {
            MediaController.getInstance().playPreviousMessage();
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:51,代码来源:MusicPlayerReceiver.java

示例11: onKeyDown

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP
        && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
        && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL
        && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null)
    {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)
        {
            if (mMediaPlayer.isPlaying())
            {
                pause();
                mMediaController.show();
            }
            else
            {
                start();
                mMediaController.hide();
            }
            return true;
        }
        else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY)
        {
            if (!mMediaPlayer.isPlaying())
            {
                start();
                mMediaController.hide();
            }
            return true;
        }
        else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE)
        {
            if (mMediaPlayer.isPlaying())
            {
                pause();
                mMediaController.show();
            }
            return true;
        }
        else
        {
            toggleMediaControlsVisiblity();
        }
    }
    
    return super.onKeyDown(keyCode, event);
}
 
开发者ID:Dreamxiaoxuan,项目名称:AndroidTvDemo,代码行数:49,代码来源:IjkVideoView.java

示例12: onReceive

@Override
    public void onReceive(Context context, Intent intent) {

        // 获得Action
        String intentAction = intent.getAction();
        // 获得KeyEvent对象
        KeyEvent keyEvent = (KeyEvent) intent
                .getParcelableExtra(Intent.EXTRA_KEY_EVENT);

        Log.i(TAG, "Action ---->" + intentAction + "  KeyEvent----->"
                + keyEvent.toString());
        // 按下 / 松开 按钮
        int keyAction = keyEvent.getAction();

        if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)
                && (KeyEvent.ACTION_DOWN == keyAction)) {
            // 获得按键字节码
            int keyCode = keyEvent.getKeyCode();

            // 获得事件的时间
            // long downtime = keyEvent.getEventTime();

            // 获取按键码 keyCode
//          StringBuilder sb = new StringBuilder();
//          // 这些都是可能的按键码 , 打印出来用户按下的键
//          if (KeyEvent.KEYCODE_MEDIA_NEXT == keyCode) {
//              sb.append("KEYCODE_MEDIA_NEXT");
//          }
            // 说明:当我们按下MEDIA_BUTTON中间按钮时,实际出发的是 KEYCODE_HEADSETHOOK 而不是
            // KEYCODE_MEDIA_PLAY_PAUSE
            if (KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE == keyCode) {
//              sb.append("KEYCODE_MEDIA_PLAY_PAUSE");

            }
            if (KeyEvent.KEYCODE_HEADSETHOOK == keyCode) {
//              sb.append("KEYCODE_HEADSETHOOK");
            }
            if (KeyEvent.KEYCODE_MEDIA_PREVIOUS == keyCode) {
//              sb.append("KEYCODE_MEDIA_PREVIOUS");
            }
            if (KeyEvent.KEYCODE_MEDIA_STOP == keyCode) {
//              sb.append("KEYCODE_MEDIA_STOP");
            }
            // 输出点击的按键码
//          Log.i(TAG, sb.toString());
//          Toast.makeText(context, sb.toString(), Toast.LENGTH_SHORT).show();
        } else if (KeyEvent.ACTION_UP == keyAction) {
            Log.i(TAG, "aaa");
        }
    }
 
开发者ID:zhuangzaiku,项目名称:AndroidCollection,代码行数:50,代码来源:MediaButtonReceiver.java

示例13: dispatchKeyEvent

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (mPlayer == null) {
        return true;
    }

    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);
}
 
开发者ID:mo3rfan,项目名称:syncplayer,代码行数:50,代码来源:VideoControllerView.java

示例14: onReceive

@Override
public void onReceive(Context context, Intent intent) {

    KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (event == null || event.getAction() != KeyEvent.ACTION_UP) {
        return;
    }

    IPlayControl control = MainActivity.getControl();
    if (control == null) {
        return;
    }

    try {

        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_MEDIA_PLAY:
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            case KeyEvent.KEYCODE_HEADSETHOOK:
                // 暂停
                if (control.status() == PlayController.STATUS_PLAYING) {
                    control.pause();
                } else {
                    control.resume();
                }
                break;
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                // 下一曲
                control.next();
                break;
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                // 上一曲
                control.pre();
                break;
        }

    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:41,代码来源:HeadphoneWireControlReceiver.java

示例15: handleIntent

public static boolean handleIntent(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return false;
        }

        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.ACTION_STOP;
                break;
            case KeyEvent.KEYCODE_HEADSETHOOK:
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                command = MusicService.ACTION_TOGGLE_PAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                command = MusicService.ACTION_SKIP;
                break;
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                command = MusicService.ACTION_REWIND;
                break;
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
                command = MusicService.ACTION_PAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY:
                command = MusicService.ACTION_PLAY;
                break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                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++;
                        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);
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:72,代码来源:MediaButtonIntentReceiver.java


注:本文中的android.view.KeyEvent.KEYCODE_HEADSETHOOK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。