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


Java KeyEvent.KEYCODE_MEDIA_PAUSE属性代码示例

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


在下文中一共展示了KeyEvent.KEYCODE_MEDIA_PAUSE属性的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;
    }
 
开发者ID:ceji-longquan,项目名称:ceji_android,代码行数:28,代码来源:ReadingFragment.java

示例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);
}
 
开发者ID:TheAndroidMaster,项目名称:MediaNotification,代码行数:30,代码来源:ActionReceiver.java

示例3: onKey

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE && isPlaying()) {
        pause();
        return true;
    }
    return super.onKey(v, keyCode, event);
}
 
开发者ID:googlesamples,项目名称:leanback-assistant,代码行数:8,代码来源:PausePlaybackTransportControlGluePatch.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:wheat7,项目名称:VRPlayer,代码行数:39,代码来源:PlayerView.java

示例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;
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:10,代码来源:PlaybackControlView.java

示例6: 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:TongmingWu,项目名称:BLPlayer,代码行数:40,代码来源:IjkVideoView.java

示例7: 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;
	}
}
 
开发者ID:ultrasonic,项目名称:ultrasonic,代码行数:38,代码来源:DownloadServiceLifecycleSupport.java

示例8: 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);
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:35,代码来源:AudioPreview.java

示例9: 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;
        }
    }
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:34,代码来源:HeadsetNotificationBroadcast.java

示例10: 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

示例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 && 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

示例12: 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

示例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();
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:51,代码来源:MusicPlayerReceiver.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: onReceive

@Override
public void onReceive(final Context context, final Intent intent) {
    LogUtils.i(TAG, "Received intent: " + intent);
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, MusicServiceConstants.CMDPAUSE, System.currentTimeMillis());
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null || event.getAction() != KeyEvent.ACTION_UP) {
            return;
        }

        String command = null;
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_HEADSETHOOK:
                command = MusicServiceConstants.CMDHEADSETHOOK;
                break;
            case KeyEvent.KEYCODE_MEDIA_STOP:
                command = MusicServiceConstants.CMDSTOP;
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                command = MusicServiceConstants.CMDTOGGLEPAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_NEXT:
                command = MusicServiceConstants.CMDNEXT;
                break;
            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                command = MusicServiceConstants.CMDPREVIOUS;
                break;
            case KeyEvent.KEYCODE_MEDIA_PAUSE:
                command = MusicServiceConstants.CMDPAUSE;
                break;
            case KeyEvent.KEYCODE_MEDIA_PLAY:
                command = MusicServiceConstants.CMDPLAY;
                break;
        }
        if (command != null) {
            startService(context, command, event.getEventTime());
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
        }
    }
}
 
开发者ID:komamj,项目名称:KomaMusic,代码行数:44,代码来源:MediaButtonIntentReceiver.java


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