问题:蓝牙耳机无法控制音乐播放器的暂停和播放
在解决这个问题之前,请先了解一下https://blog.csdn.net/blackeagle215/article/details/79033781 Avrcp是什么?
在按蓝牙耳机按键后流程都会走到
vendor/qcom/opensource/commonsys/bluetooth_ext/packages_apps_bluetooth_ext/src/avrcp/Avrcp_ext.java
这个文件的handlePassthroughCmd 函数,
if ((deviceFeatures[deviceIndex].mLastPassthroughcmd == KeyEvent.KEYCODE_UNKNOWN) ||
deviceFeatures[deviceIndex].mLastPassthroughcmd == code) {
if (isPlayingState(mCurrentPlayerState) &&
(code == KeyEvent.KEYCODE_MEDIA_PLAY)) {
Log.w(TAG, "Ignoring passthrough command play" + op + " state " + state +
"in music playing");
return;
}
if ((!isPlayingState(mCurrentPlayerState)) &&
(!mAudioManager.isMusicActive()) &&
(mA2dpState == BluetoothA2dp.STATE_NOT_PLAYING) &&
(code == KeyEvent.KEYCODE_MEDIA_PAUSE)) {
Log.w(TAG, "Ignoring passthrough command pause" + op + " state " + state +
"in music playing");
return;
}
}
...
if ((code == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD || code == KeyEvent.KEYCODE_MEDIA_REWIND)
&& (deviceFeatures[deviceIndex].mPlayStatusChangedNT ==
AvrcpConstants_ext.NOTIFICATION_TYPE_INTERIM) && (action == KeyEvent.ACTION_UP)) {
int currentPlayState =
convertPlayStateToPlayStatus(deviceFeatures[deviceIndex].mCurrentPlayState);
Log.d(TAG, "