Android Bluetooth development - Avrcp protocol to obtain song information (seventeen)

        Through the study of the previous Avrcp protocol, we know that the control of Bluetooth music is carried out through the media player. When the data of the media player changes, it will notify the client through MediaSeesion. This article mainly analyzes how the song information is transmitted.

Avrcp protocol

        First, if the song information changes, we will receive a callback in onTrackChanged of AvrcpControllerService.

AvrcpControllerService.onTrackChanged()

Source location: /packages/apps/Bluetooth/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerService.java

// 当一个轨道发生变化并且本地AvrcpController注册更新时由JNI调用。
private synchronized void onTrackChanged(byte[] address, byte numAttributes, int[] attributes, String[] attribVals) {
    BluetoothDevice device = getAnonymousDevice(address);
    AvrcpControllerStateMachine stateMachine = getStateMachine(device);
    if (stateMachine != null) {
        AvrcpItem.Builder aib = new AvrcpItem.Builder();
        aib.fromAvrcpAttributeArray(attributes, attribVals);
        aib.setDevice(device);
        aib.setItemType(AvrcpItem.TYPE_MEDIA);
        aib.setUuid(UUID.rando

Guess you like

Origin blog.csdn.net/c19344881x/article/details/128818558