本文整理汇总了Java中android.view.KeyEvent.KEYCODE_MEDIA_PREVIOUS属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.KEYCODE_MEDIA_PREVIOUS属性的具体用法?Java KeyEvent.KEYCODE_MEDIA_PREVIOUS怎么用?Java KeyEvent.KEYCODE_MEDIA_PREVIOUS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.KEYCODE_MEDIA_PREVIOUS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchMediaKeyEvent
public boolean dispatchMediaKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
if ( audioManager.isMusicActive() ) {
return false;
}
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_MEDIA_PAUSE:
return simulateButtonPress(action, R.id.playPauseButton, playPauseButton);
case KeyEvent.KEYCODE_MEDIA_STOP:
return simulateButtonPress(action, R.id.stopButton, stopButton );
case KeyEvent.KEYCODE_MEDIA_NEXT:
return simulateButtonPress(action, R.id.nextButton, nextButton );
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
return simulateButtonPress(action, R.id.prevButton, prevButton );
}
return false;
}
示例2: sendKeyPressBroadcastString
public void sendKeyPressBroadcastString(Context context, int keycode, String packageName) {
Intent intent = new Intent("com.android.music.musicservicecommand");
switch (keycode) {
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
intent.putExtra("command", "previous");
break;
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
intent.putExtra("command", "togglepause");
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
intent.putExtra("command", "pause");
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
intent.putExtra("command", "play");
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
intent.putExtra("command", "next");
break;
case KeyEvent.KEYCODE_MEDIA_STOP:
intent.putExtra("command", "stop");
break;
default:
return;
}
if (packageName != null)
intent.setPackage(packageName);
context.sendOrderedBroadcast(intent, null);
}
示例3: onKeyUp
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean ret = false;
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
// if (isChild() == true) {
// final VideoBrowserActivity parent = (VideoBrowserActivity)
// getParent();
// parent.launchGlobalResume();
// }
ret = true;
}
// if (!ret)
// ret = super.onKeyUp(keyCode, event);
return ret;
}
示例4: dispatchMediaKeyEvent
/**
* Called to process media key events. Any {@link KeyEvent} can be passed but only media key
* events will be handled.
*
* @param event A key event.
* @return Whether the key event was handled.
*/
public boolean dispatchMediaKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
if (player == null || !isHandledMediaKey(keyCode)) {
return false;
}
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) {
fastForward();
} else if (keyCode == KeyEvent.KEYCODE_MEDIA_REWIND) {
rewind();
} else if (event.getRepeatCount() == 0) {
if (player == null) {
return true;
}
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
controlDispatcher.dispatchSetPlayWhenReady(player, !player.getPlayWhenReady());
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
controlDispatcher.dispatchSetPlayWhenReady(player, true);
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
controlDispatcher.dispatchSetPlayWhenReady(player, false);
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
next();
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
previous();
break;
default:
break;
}
}
}
return true;
}
示例5: isHandledMediaKey
@SuppressLint("InlinedApi")
private static boolean isHandledMediaKey(int keyCode) {
return keyCode == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD
|| keyCode == KeyEvent.KEYCODE_MEDIA_REWIND
|| keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
|| keyCode == KeyEvent.KEYCODE_MEDIA_PLAY
|| keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE
|| keyCode == KeyEvent.KEYCODE_MEDIA_NEXT
|| keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS;
}
示例6: handleKeyEvent
private void handleKeyEvent(KeyEvent event)
{
if (event.getAction() != KeyEvent.ACTION_DOWN || event.getRepeatCount() > 0)
{
return;
}
switch (event.getKeyCode())
{
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_HEADSETHOOK:
downloadService.togglePlayPause();
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
downloadService.previous();
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1)
{
downloadService.next();
}
break;
case KeyEvent.KEYCODE_MEDIA_STOP:
downloadService.stop();
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
if (downloadService.getPlayerState() != PlayerState.STARTED)
{
downloadService.start();
}
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
downloadService.pause();
break;
default:
break;
}
}
示例7: handleMediaKey
/**
* Redispatches unhandled media keys. This allows bluetooth headphones with play/pause or
* other buttons to function correctly.
*/
@TargetApi(19)
private void handleMediaKey(KeyEvent e) {
if (Build.VERSION.SDK_INT < 19) return;
switch (e.getKeyCode()) {
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PAUSE:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_REWIND:
case KeyEvent.KEYCODE_MEDIA_RECORD:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
case KeyEvent.KEYCODE_MEDIA_CLOSE:
case KeyEvent.KEYCODE_MEDIA_EJECT:
case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
AudioManager am = (AudioManager) mTab.getApplicationContext().getSystemService(
Context.AUDIO_SERVICE);
am.dispatchMediaKeyEvent(e);
break;
default:
break;
}
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:30,代码来源:TabWebContentsDelegateAndroid.java
示例8: 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;
}
}
}
示例9: 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();
}
}
}
示例10: onReceive
@Override
public void onReceive(Context context, Intent intent) {
mApp = (Common) context.getApplicationContext();
if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) {
KeyEvent keyEvent = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
if (keyEvent.getAction() != KeyEvent.ACTION_DOWN)
return;
switch (keyEvent.getKeyCode()) {
case KeyEvent.KEYCODE_HEADSETHOOK:
mApp.getPlayBackStarter().playSongs();
break;
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
mApp.getPlayBackStarter().pauseSong();
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
mApp.getPlayBackStarter().playSongs();
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
mApp.getPlayBackStarter().pauseSong();
break;
case KeyEvent.KEYCODE_MEDIA_STOP:
mApp.getPlayBackStarter().pauseSong();
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
mApp.getPlayBackStarter().nextSong();
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
mApp.getPlayBackStarter().previousSong();
break;
default:
break;
}
}
}
示例11: onKeyDown
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (mPlayer.isPlaying()) {
mPlayer.pause();
} else {
start();
}
updatePlayPause();
return true;
case KeyEvent.KEYCODE_MEDIA_PLAY:
start();
updatePlayPause();
return true;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
if (mPlayer.isPlaying()) {
mPlayer.pause();
}
updatePlayPause();
return true;
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_REWIND:
return true;
case KeyEvent.KEYCODE_MEDIA_STOP:
case KeyEvent.KEYCODE_BACK:
stopPlayback();
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
示例12: 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 = ACTION_STOP;
break;
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
command = ACTION_TOGGLE_PAUSE;
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
command = ACTION_SKIP;
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
command = ACTION_REWIND;
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
command = ACTION_PAUSE;
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
command = 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 || keycode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
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;
}
示例13: 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();
}
}
}
示例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();
}
}
示例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;
}