# 设备消息

## DeviceListener接口

机器端消息的回调接口，是[com.youzhuan.mqttclient.device.bean.Device](/ctrl-host/yun-dui-jie/chang-yong-shu-ju-lei-jie-shao/device.md)的一个内部接口

### DeviceListener的原型

```
public interface DeviceListener {
    /**
     * 播放信息改变
     * 
     * @param deviceId 设备ID
     * @param cloudStatusUpdateBean 状态信息的Java bean
     */
     void playInfoChanger(String deviceId, CloudStatusUpdateBean cloudStatusUpdateBean);

     /**
     * 播放列表改变
     * 
     * @param deviceId 设备ID
     * @param musicMap 音乐列表
     */
     void musicListChanger(String deviceId, Map<String, List<CloudMusic>> musicMap);
}
```

### 设置监听

使用[com.youzhuan.mqttclient.device.bean.Device](/ctrl-host/yun-dui-jie/chang-yong-shu-ju-lei-jie-shao/device.md)中的方法设置

#### 方法原型

```
/**
 * 设置设备得监听
 * @param deviceListener
 */
public void addDeviceListener(DeviceListener deviceListener);

/**
 * 删除设备的监听
 * @param listener
 */
 public void removeDevieceListener(DeviceListener listener);
```

## DeviceListener接口方法介绍

介绍DeviceListener接口里面的所有方法和参数，可以在拿到消息后做处理

### 播放信息(playInfoChanger)

音乐主机更新重要信息的监听，包含播放信息和一些其他主机信息

#### 方法原型

```
/**
* 播放信息改变
* 
* @param deviceId 设备ID
* @param cloudStatusUpdateBean 状态信息的Java bean
*/
void playInfoChanger(String deviceId, CloudStatusUpdateBean cloudStatusUpdateBean);
```

#### 参数介绍

* deviceId：发送该消息的机器ID，可以用来判断是哪个机器发送该消息
* cloudStatesUpdateBean：一个CloudStatesUpdateBean对象，是机器段发送的所有数据，会保存在com.youzhuan.mqttclient.device.bean.Device中，数据介绍请参考CloudStatesUpdateBean类介绍

### 播放列表(musicListChanger)

音乐主机发送内部歌曲的列表到手机端

#### 方法原型

```
/**
* 播放列表改变
* 
* @param deviceId 设备ID
* @param musicMap 音乐列表
*/
void musicListChanger(String deviceId, Map<String, List<Music>> musicMap);
```

#### 参数介绍

* deviceId：发送该消息的机器ID，可以用来判断是哪个机器发送该消息
* musicMap：包含音乐主机发送过来的所有音乐，Map的key值为下

| 音乐类型 | 值（String）       |
| ---- | --------------- |
| 本地音乐 | LOCAL\_MUSIC    |
| SD音乐 | SD\_MUSIC       |
| 收藏音乐 | FAVORITE\_MUSIC |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.youzhuan.net/ctrl-host/yun-dui-jie/jie-ru-zhi-nan/she-bei-xiao-xi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
