搜索

449

主题

659

帖子

4893

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4893
QQ
发表于 2022-3-12 12:07:35 2404 浏览 0 回复

Android9 蓝牙开发学习(3)——BluetoothAvrcpController


BluetoothAvrcpController         

主要控制蓝牙音乐的播放暂停
AVRCP全名是Audio Video Remote Cortrol Profile音频/视频远程控制配置文件。

BluetoothAvrcpController初始化   

  1. //初始化
  2. bluetoothAdapter.getProfileProxy(context, mAvrcpServiceListener, BluetoothProfile.AVRCP_CONTROLLER);
  3. //还要实现BluetoothProfile.ServiceListener接口,在onServiceConnected中获取BluetoothAvrcpController对象
  4. private BluetoothProfile.ServiceListener mAvrcpServiceListener = new BluetoothProfile.ServiceListener()
  5.     {
  6.             
  7.         @Override
  8.         public void onServiceConnected(int profile, BluetoothProfile proxy)
  9.         {
  10.             
  11.             if (profile == BluetoothProfile.AVRCP_CONTROLLER)
  12.             {
  13.             
  14.                 log.d("AvrcpControllerService connected");
  15.                 mAvrcpController = (BluetoothAvrcpController) proxy;
  16.             }
  17.         }

  18.         @Override
  19.         public void onServiceDisconnected(int profile)
  20.         {
  21.             
  22.             if (profile == BluetoothProfile.AVRCP_CONTROLLER)
  23.             {
  24.             
  25.                 log.d("AvrcpControllerService disconnected");
  26.                 mAvrcpController = null;
  27.             }
  28.         }
  29.     };
  30. //销毁
  31. bluetoothAdapter.closeProfileProxy(BluetoothProfile.AVRCP_CONTROLLER, mAvrcpController);
复制代码


BluetoothAvrcpController控制         
  1. mAvrcpController.sendPassThroughCmd(BluetoothDevice, playAction, BluetoothAvrcp.PASSTHROUGH_STATE_PRESS);
  2. mAvrcpController.sendPassThroughCmd(BluetoothDevice, playAction, BluetoothAvrcp.PASSTHROUGH_STATE_RELEASE);

  3. //常用的playAction在BluetoothAvrcp这个类中
  4.     public static final int PASSTHROUGH_ID_PLAY = 0x44;    /* play */
  5.     public static final int PASSTHROUGH_ID_STOP = 0x45;    /* stop */
  6.     public static final int PASSTHROUGH_ID_PAUSE = 0x46;    /* pause */
复制代码







本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
手机微信同号:13682654092
回复

使用道具 举报

返回列表
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


登录或注册
快速回复 返回顶部 返回列表