1# @ohos.multimedia.avsession (媒体会话管理) 2 3媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。 4 5该模块提供以下媒体会话相关的常用功能: 6 7- [AVSession](#avsession10) : 会话,可用于设置元数据、播放状态信息等操作。 8- [AVSessionController](#avsessioncontroller10): 会话控制器,可用于查看会话ID,完成对会话发送命令及事件,获取会话元数据、播放状态信息等操作。 9- [AVCastController](#avcastcontroller10): 投播控制器,可用于投播场景下,完成播放控制、远端播放状态监听、远端播放状态信息获取等操作。 10 11> **说明:** 12> 13> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14 15## 导入模块 16 17```ts 18import { avSession } from '@kit.AVSessionKit'; 19``` 20 21## avSession.createAVSession<sup>10+</sup> 22 23createAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AVSession> 24 25创建会话对象,一个Ability只能存在一个会话,重复创建会失败,结果通过Promise异步回调方式返回。 26 27**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 28 29**系统能力:** SystemCapability.Multimedia.AVSession.Core 30 31**参数:** 32 33| 参数名 | 类型 | 必填 | 说明 | 34| ------ | ------------------------------- | ---- | ------------------------------ | 35| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | 是| 需要使用UIAbilityContext,用于系统获取应用组件的相关信息。 | 36| tag | string | 是 | 会话的自定义名称。 | 37| type | [AVSessionType](#avsessiontype10) | 是 | 会话类型。 | 38 39**返回值:** 40 41| 类型 | 说明 | 42| --------------------------------- | ------------------------------------------------------------ | 43| Promise<[AVSession](#avsession10)\> | Promise对象。回调返回会话实例对象,可用于获取会话ID,以及设置元数据、播放状态,发送按键事件等操作。| 44 45**错误码:** 46 47以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 48 49| 错误码ID | 错误信息 | 50| -------- | ---------------------------------------- | 51| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 52| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 53 54**示例:** 55 56```ts 57import { BusinessError } from '@kit.BasicServicesKit'; 58import { avSession } from '@kit.AVSessionKit'; 59@Entry 60@Component 61struct Index { 62 @State message: string = 'hello world'; 63 64 build() { 65 Column() { 66 Text(this.message) 67 .onClick(()=>{ 68 let currentAVSession: avSession.AVSession; 69 let tag = "createNewSession"; 70 let context: Context = this.getUIContext().getHostContext() as Context; 71 let sessionId: string; // 供后续函数入参使用。 72 73 avSession.createAVSession(context, tag, "audio").then(async (data: avSession.AVSession) => { 74 currentAVSession = data; 75 sessionId = currentAVSession.sessionId; 76 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 77 }).catch((err: BusinessError) => { 78 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 79 }); 80 }) 81 } 82 .width('100%') 83 .height('100%') 84 } 85} 86``` 87 88## avSession.createAVSession<sup>10+</sup> 89 90createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void 91 92创建会话对象,一个Ability只能存在一个会话,重复创建会失败,结果通过callback异步回调方式返回。 93 94**系统能力:** SystemCapability.Multimedia.AVSession.Core 95 96**参数:** 97 98| 参数名 | 类型 | 必填 | 说明 | 99| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 100| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | 是| 需要使用UIAbilityContext,用于系统获取应用组件的相关信息。 | 101| tag | string | 是 | 会话的自定义名称。 | 102| type | [AVSessionType](#avsessiontype10) | 是 | 会话类型。 | 103| callback | AsyncCallback<[AVSession](#avsession10)\> | 是 | 回调函数。回调返回会话实例对象,可用于获取会话ID,以及设置元数据、播放状态,发送按键事件等操作。 | 104 105**错误码:** 106 107以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 108 109| 错误码ID | 错误信息 | 110| -------- | ---------------------------------------- | 111| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 112| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 113 114**示例:** 115 116```ts 117import { BusinessError } from '@kit.BasicServicesKit'; 118import { avSession } from '@kit.AVSessionKit'; 119@Entry 120@Component 121struct Index { 122 @State message: string = 'hello world'; 123 124 build() { 125 Column() { 126 Text(this.message) 127 .onClick(()=>{ 128 let currentAVSession: avSession.AVSession; 129 let tag = "createNewSession"; 130 let context: Context = this.getUIContext().getHostContext() as Context; 131 let sessionId: string; // 供后续函数入参使用。 132 133 avSession.createAVSession(context, tag, "audio", async (err: BusinessError, data: avSession.AVSession) => { 134 if (err) { 135 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 136 } else { 137 currentAVSession = data; 138 sessionId = currentAVSession.sessionId; 139 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 140 } 141 }); 142 }) 143 } 144 .width('100%') 145 .height('100%') 146 } 147} 148``` 149 150## ProtocolType<sup>11+</sup> 151 152远端设备支持的协议类型的枚举。 153 154**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 155 156| 名称 | 值 | 说明 | 157| --------------------------- | ---- | ----------- | 158| TYPE_LOCAL<sup>11+</sup> | 0 | 本地设备,包括设备本身的内置扬声器或音频插孔、A2DP 设备。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 159| TYPE_CAST_PLUS_STREAM<sup>11+</sup> | 2 | Cast+的Stream模式。表示媒体正在其他设备上展示。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 160| TYPE_DLNA<sup>12+</sup> | 4 | DLNA协议。表示媒体正在其他设备上展示。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 161| TYPE_CAST_PLUS_AUDIO<sup>20+</sup> | 8 | PCM模式。表示媒体正在其他设备上展示。<br>**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 | 162 163## AVSessionType<sup>10+<sup> 164 165type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call' 166 167当前会话支持的会话类型。 168 169该类型可取的值为下表字符串。 170 171**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 172 173**系统能力:** SystemCapability.Multimedia.AVSession.Core 174 175| 类型 | 说明 | 176| ----- | ---- | 177| 'audio' | 音频 | 178| 'video' | 视频 | 179| 'voice_call'<sup>11+<sup> | 音频通话。 | 180| 'video_call'<sup>12+<sup> | 视频通话。 | 181 182## AVSession<sup>10+</sup> 183 184调用[avSession.createAVSession](#avsessioncreateavsession10)后,返回会话的实例,可以获得会话ID,完成设置元数据,播放状态信息等操作。 185 186### 属性 187 188**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 189 190**系统能力:** SystemCapability.Multimedia.AVSession.Core 191 192| 名称 | 类型 | 只读 | 可选 | 说明 | 193| :-------- | :----- | :--- | :--- | :---------------------------- | 194| sessionId | string | 是 | 否 | AVSession对象唯一的会话标识。 | 195| sessionType| [AVSessionType](#avsessiontype10) | 是 | 否 | AVSession会话类型。 | 196 197**示例:** 198 199```ts 200let sessionId: string = currentAVSession.sessionId; 201let sessionType: avSession.AVSessionType = currentAVSession.sessionType; 202``` 203 204### setAVMetadata<sup>10+</sup> 205 206setAVMetadata(data: AVMetadata): Promise\<void> 207 208设置会话元数据。结果通过Promise异步回调方式返回。 209 210**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 211 212**系统能力:** SystemCapability.Multimedia.AVSession.Core 213 214**参数:** 215 216| 参数名 | 类型 | 必填 | 说明 | 217| ------ | ------------------------- | ---- | ------------ | 218| data | [AVMetadata](#avmetadata10) | 是 | 会话元数据。 | 219 220**返回值:** 221 222| 类型 | 说明 | 223| -------------- | ----------------------------- | 224| Promise\<void> | Promise对象。当元数据设置成功,无返回结果,否则返回错误对象。 | 225 226**错误码:** 227 228以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 229 230| 错误码ID | 错误信息 | 231| -------- | ---------------------------------------- | 232| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 233| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 234| 6600102 | The session does not exist. | 235 236**示例:** 237 238```ts 239import { BusinessError } from '@kit.BasicServicesKit'; 240 241let metadata: avSession.AVMetadata = { 242 assetId: "121278", 243 title: "lose yourself", 244 artist: "Eminem", 245 author: "ST", 246 album: "Slim shady", 247 writer: "ST", 248 composer: "ST", 249 duration: 2222, 250 mediaImage: "https://www.example.com/example.jpg", 251 subtitle: "8 Mile", 252 description: "Rap", 253 // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。 254 // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n 255 lyric: "lrc格式歌词内容", 256 // singleLyricText字段存储单条歌词文本,不包含时间戳。 257 // 例如:"单条歌词内容"。 258 singleLyricText: "单条歌词内容", 259 previousAssetId: "121277", 260 nextAssetId: "121279" 261}; 262currentAVSession.setAVMetadata(metadata).then(() => { 263 console.info('SetAVMetadata successfully'); 264}).catch((err: BusinessError) => { 265 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 266}); 267``` 268 269### setAVMetadata<sup>10+</sup> 270 271setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void 272 273设置会话元数据。结果通过callback异步回调方式返回。 274 275**系统能力:** SystemCapability.Multimedia.AVSession.Core 276 277**参数:** 278 279| 参数名 | 类型 | 必填 | 说明 | 280| -------- | ------------------------- | ---- | ------------------------------------- | 281| data | [AVMetadata](#avmetadata10) | 是 | 会话元数据。 | 282| callback | AsyncCallback\<void> | 是 | 回调函数。当元数据设置成功,err为undefined,否则返回错误对象。 | 283 284**错误码:** 285 286以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 287 288| 错误码ID | 错误信息 | 289| -------- | ---------------------------------------- | 290| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 291| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 292| 6600102 | The session does not exist. | 293 294**示例:** 295 296```ts 297import { BusinessError } from '@kit.BasicServicesKit'; 298 299let metadata: avSession.AVMetadata = { 300 assetId: "121278", 301 title: "lose yourself", 302 artist: "Eminem", 303 author: "ST", 304 album: "Slim shady", 305 writer: "ST", 306 composer: "ST", 307 duration: 2222, 308 mediaImage: "https://www.example.com/example.jpg", 309 subtitle: "8 Mile", 310 description: "Rap", 311 // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。 312 // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n 313 lyric: "lrc格式歌词内容", 314 // singleLyricText字段存储单条歌词文本,不包含时间戳。 315 // 例如:"单条歌词内容"。 316 singleLyricText: "单条歌词内容", 317 previousAssetId: "121277", 318 nextAssetId: "121279" 319}; 320currentAVSession.setAVMetadata(metadata, (err: BusinessError) => { 321 if (err) { 322 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 323 } else { 324 console.info('SetAVMetadata successfully'); 325 } 326}); 327``` 328 329### setCallMetadata<sup>11+</sup> 330 331setCallMetadata(data: CallMetadata): Promise\<void> 332 333设置通话会话元数据。结果通过Promise异步回调方式返回。 334 335**系统能力:** SystemCapability.Multimedia.AVSession.Core 336 337**参数:** 338 339| 参数名 | 类型 | 必填 | 说明 | 340| ------ | ------------------------- | ---- | ------------ | 341| data | [CallMetadata](#callmetadata11) | 是 | 通话会话元数据。 | 342 343**返回值:** 344 345| 类型 | 说明 | 346| -------------- | ----------------------------- | 347| Promise\<void> | Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。 | 348 349**错误码:** 350 351以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 352 353| 错误码ID | 错误信息 | 354| -------- | ---------------------------------------- | 355| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 356| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 357| 6600102 | The session does not exist. | 358 359**示例:** 360 361```ts 362import { image } from '@kit.ImageKit'; 363import { resourceManager } from '@kit.LocalizationKit'; 364import { BusinessError } from '@kit.BasicServicesKit'; 365 366let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 367 let imageSource = await image.createImageSource(value.buffer); 368 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 369 let calldata: avSession.CallMetadata = { 370 name: "xiaoming", 371 phoneNumber: "111xxxxxxxx", 372 avatar: imagePixel 373 }; 374currentAVSession.setCallMetadata(calldata).then(() => { 375 console.info('setCallMetadata successfully'); 376}).catch((err: BusinessError) => { 377 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 378}); 379``` 380 381### setCallMetadata<sup>11+</sup> 382 383setCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void 384 385设置通话会话元数据。结果通过callback异步回调方式返回。 386 387**系统能力:** SystemCapability.Multimedia.AVSession.Core 388 389**参数:** 390 391| 参数名 | 类型 | 必填 | 说明 | 392| -------- | ------------------------- | ---- | ------------------------------------- | 393| data | [CallMetadata](#callmetadata11) | 是 | 通话会话元数据。 | 394| callback | AsyncCallback\<void> | 是 | 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。 | 395 396**错误码:** 397 398以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 399 400| 错误码ID | 错误信息 | 401| -------- | ---------------------------------------- | 402| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 403| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 404| 6600102 | The session does not exist. | 405 406**示例:** 407 408```ts 409import { image } from '@kit.ImageKit'; 410import { resourceManager } from '@kit.LocalizationKit'; 411import { BusinessError } from '@kit.BasicServicesKit'; 412 413async function setCallMetadata() { 414 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 415 let imageSource = await image.createImageSource(value.buffer); 416 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 417 let calldata: avSession.CallMetadata = { 418 name: "xiaoming", 419 phoneNumber: "111xxxxxxxx", 420 avatar: imagePixel 421 }; 422 currentAVSession.setCallMetadata(calldata, (err: BusinessError) => { 423 if (err) { 424 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 425 } else { 426 console.info('setCallMetadata successfully'); 427 } 428 }); 429} 430``` 431 432### setAVCallState<sup>11+</sup> 433 434setAVCallState(state: AVCallState): Promise\<void> 435 436设置通话状态。结果通过Promise异步回调方式返回。 437 438**系统能力:** SystemCapability.Multimedia.AVSession.Core 439 440**参数:** 441 442| 参数名 | 类型 | 必填 | 说明 | 443| ------ | ------------------------- | ---- | ------------ | 444| state | [AVCallState](#avcallstate11) | 是 | 通话状态。 | 445 446**返回值:** 447 448| 类型 | 说明 | 449| -------------- | ----------------------------- | 450| Promise\<void> | Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。 | 451 452**错误码:** 453 454以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 455 456| 错误码ID | 错误信息 | 457| -------- | ---------------------------------------- | 458| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 459| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 460| 6600102 | The session does not exist. | 461 462**示例:** 463 464```ts 465import { BusinessError } from '@kit.BasicServicesKit'; 466 467let calldata: avSession.AVCallState = { 468 state: avSession.CallState.CALL_STATE_ACTIVE, 469 muted: false 470}; 471currentAVSession.setAVCallState(calldata).then(() => { 472 console.info('setAVCallState successfully'); 473}).catch((err: BusinessError) => { 474 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 475}); 476``` 477 478### setAVCallState<sup>11+</sup> 479 480setAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void 481 482设置通话状态。结果通过callback异步回调方式返回。 483 484**系统能力:** SystemCapability.Multimedia.AVSession.Core 485 486**参数:** 487 488| 参数名 | 类型 | 必填 | 说明 | 489| -------- | ------------------------- | ---- | ------------------------------------- | 490| state | [AVCallState](#avcallstate11) | 是 | 通话状态。 | 491| callback | AsyncCallback\<void> | 是 | 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。 | 492 493**错误码:** 494 495以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 496 497| 错误码ID | 错误信息 | 498| -------- | ---------------------------------------- | 499| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 500| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 501| 6600102 | The session does not exist. | 502 503**示例:** 504 505```ts 506import { BusinessError } from '@kit.BasicServicesKit'; 507 508let avcalldata: avSession.AVCallState = { 509 state: avSession.CallState.CALL_STATE_ACTIVE, 510 muted: false 511}; 512currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => { 513 if (err) { 514 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 515 } else { 516 console.info('setAVCallState successfully'); 517 } 518}); 519``` 520 521### setAVPlaybackState<sup>10+</sup> 522 523setAVPlaybackState(state: AVPlaybackState): Promise\<void> 524 525设置会话播放状态。结果通过Promise异步回调方式返回。 526 527**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 528 529**系统能力:** SystemCapability.Multimedia.AVSession.Core 530 531**参数:** 532 533| 参数名 | 类型 | 必填 | 说明 | 534| ------ | ----------------------------------- | ---- | ---------------------------------------------- | 535| state | [AVPlaybackState](#avplaybackstate10) | 是 | 会话播放状态,包括状态、倍数、循环模式等信息。 | 536 537**返回值:** 538 539| 类型 | 说明 | 540| -------------- | ----------------------------- | 541| Promise\<void> | Promise对象。当播放状态设置成功,无返回结果,否则返回错误对象。 | 542 543**错误码:** 544 545以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 546 547| 错误码ID | 错误信息 | 548| -------- | ---------------------------------------- | 549| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 550| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 551| 6600102 | The session does not exist. | 552 553**示例:** 554 555```ts 556import { BusinessError } from '@kit.BasicServicesKit'; 557 558let playbackState: avSession.AVPlaybackState = { 559 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 560 speed: 1.0, 561 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 562 bufferedTime:1000, 563 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 564 isFavorite:true 565}; 566currentAVSession.setAVPlaybackState(playbackState).then(() => { 567 console.info('SetAVPlaybackState successfully'); 568}).catch((err: BusinessError) => { 569 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 570}); 571``` 572 573### setAVPlaybackState<sup>10+</sup> 574 575setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void 576 577设置会话播放状态。结果通过callback异步回调方式返回。 578 579**系统能力:** SystemCapability.Multimedia.AVSession.Core 580 581**参数:** 582 583| 参数名 | 类型 | 必填 | 说明 | 584| -------- | ----------------------------------- | ---- | ---------------------------------------------- | 585| state | [AVPlaybackState](#avplaybackstate10) | 是 | 会话播放状态,包括状态、倍数、循环模式等信息。 | 586| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 587 588**错误码:** 589 590以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 591 592| 错误码ID | 错误信息 | 593| -------- | ---------------------------------------- | 594| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 595| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 596| 6600102 | The session does not exist. | 597 598**示例:** 599 600```ts 601import { BusinessError } from '@kit.BasicServicesKit'; 602 603let PlaybackState: avSession.AVPlaybackState = { 604 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 605 speed: 1.0, 606 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 607 bufferedTime:1000, 608 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 609 isFavorite:true 610}; 611currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => { 612 if (err) { 613 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 614 } else { 615 console.info('SetAVPlaybackState successfully'); 616 } 617}); 618``` 619 620### setLaunchAbility<sup>10+</sup> 621 622setLaunchAbility(ability: WantAgent): Promise\<void> 623 624设置一个WantAgent用于拉起会话的Ability。结果通过Promise异步回调方式返回。 625 626**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 627 628**系统能力:** SystemCapability.Multimedia.AVSession.Core 629 630**参数:** 631 632| 参数名 | 类型 | 必填 | 说明 | 633| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 634| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 635 636**返回值:** 637 638| 类型 | 说明 | 639| -------------- | ----------------------------- | 640| Promise\<void> | Promise对象。当Ability设置成功,无返回结果,否则返回错误对象。 | 641 642**错误码:** 643 644以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 645 646| 错误码ID | 错误信息 | 647| -------- | ---------------------------------------- | 648| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 649| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 650| 6600102 | The session does not exist. | 651 652**示例:** 653 654```ts 655import { wantAgent } from '@kit.AbilityKit'; 656import { BusinessError } from '@kit.BasicServicesKit'; 657 658// WantAgentInfo对象。 659let wantAgentInfo: wantAgent.WantAgentInfo = { 660 wants: [ 661 { 662 deviceId: "deviceId", 663 bundleName: "com.example.myapplication", 664 abilityName: "EntryAbility", 665 action: "action1", 666 entities: ["entity1"], 667 type: "MIMETYPE", 668 uri: "key = {true,true,false}", 669 parameters: 670 { 671 mykey0: 2222, 672 mykey1: [1, 2, 3], 673 mykey2: "[1, 2, 3]", 674 mykey3: "ssssssssssssssssssssssssss", 675 mykey4: [false, true, false], 676 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 677 mykey6: true 678 } 679 } 680 ], 681 operationType: wantAgent.OperationType.START_ABILITIES, 682 requestCode: 0, 683 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 684} 685 686wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 687 currentAVSession.setLaunchAbility(agent).then(() => { 688 console.info('SetLaunchAbility successfully'); 689 }).catch((err: BusinessError) => { 690 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 691 }); 692}); 693``` 694 695### setLaunchAbility<sup>10+</sup> 696 697setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void 698 699设置一个WantAgent用于拉起会话的Ability。结果通过callback异步回调方式返回。 700 701**系统能力:** SystemCapability.Multimedia.AVSession.Core 702 703**参数:** 704 705| 参数名 | 类型 | 必填 | 说明 | 706| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 707| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 708| callback | AsyncCallback\<void> | 是 | 回调函数。当Ability设置成功,err为undefined,否则返回错误对象。 | 709 710**错误码:** 711 712以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 713 714| 错误码ID | 错误信息 | 715| -------- | ---------------------------------------- | 716| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 717| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 718| 6600102 | The session does not exist. | 719 720**示例:** 721 722```ts 723import { wantAgent } from '@kit.AbilityKit'; 724import { BusinessError } from '@kit.BasicServicesKit'; 725 726// WantAgentInfo对象。 727let wantAgentInfo: wantAgent.WantAgentInfo = { 728 wants: [ 729 { 730 deviceId: "deviceId", 731 bundleName: "com.example.myapplication", 732 abilityName: "EntryAbility", 733 action: "action1", 734 entities: ["entity1"], 735 type: "MIMETYPE", 736 uri: "key = {true,true,false}", 737 parameters: 738 { 739 mykey0: 2222, 740 mykey1: [1, 2, 3], 741 mykey2: "[1, 2, 3]", 742 mykey3: "ssssssssssssssssssssssssss", 743 mykey4: [false, true, false], 744 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 745 mykey6: true 746 } 747 } 748 ], 749 operationType: wantAgent.OperationType.START_ABILITIES, 750 requestCode: 0, 751 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 752} 753 754wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 755 currentAVSession.setLaunchAbility(agent, (err: BusinessError) => { 756 if (err) { 757 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 758 } else { 759 console.info('SetLaunchAbility successfully'); 760 } 761 }); 762}); 763``` 764 765### dispatchSessionEvent<sup>10+</sup> 766 767dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void> 768 769媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容,结果通过Promise异步回调方式返回。 770 771**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 772 773**系统能力:** SystemCapability.Multimedia.AVSession.Core 774 775**参数:** 776 777| 参数名 | 类型 | 必填 | 说明 | 778| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 779| event | string | 是 | 需要设置的会话事件的名称。 | 780| args | {[key: string]: Object} | 是 | 需要传递的会话事件内容。 | 781 782> **说明:** 783> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 784 785**返回值:** 786 787| 类型 | 说明 | 788| -------------- | ----------------------------- | 789| Promise\<void> | Promise对象。当事件设置成功,无返回结果,否则返回错误对象。 | 790 791**错误码:** 792 793以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 794 795| 错误码ID | 错误信息 | 796| -------- | ---------------------------------------- | 797| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 798| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 799| 6600102 | The session does not exist. | 800 801**示例:** 802 803```ts 804import { BusinessError } from '@kit.BasicServicesKit'; 805import { avSession } from '@kit.AVSessionKit'; 806@Entry 807@Component 808struct Index { 809 @State message: string = 'hello world'; 810 811 build() { 812 Column() { 813 Text(this.message) 814 .onClick(()=>{ 815 let currentAVSession: avSession.AVSession | undefined = undefined; 816 let tag = "createNewSession"; 817 let context: Context = this.getUIContext().getHostContext() as Context; 818 819 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 820 if (err) { 821 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 822 } else { 823 currentAVSession = data; 824 } 825 }); 826 let eventName = "dynamic_lyric"; 827 if (currentAVSession !== undefined) { 828 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => { 829 console.info('dispatchSessionEvent successfully'); 830 }).catch((err: BusinessError) => { 831 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 832 }) 833 } 834 }) 835 } 836 .width('100%') 837 .height('100%') 838 } 839} 840``` 841 842### dispatchSessionEvent<sup>10+</sup> 843 844dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 845 846媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容,结果通过callback异步回调方式返回。 847 848**系统能力:** SystemCapability.Multimedia.AVSession.Core 849 850**参数:** 851 852| 参数名 | 类型 | 必填 | 说明 | 853| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 854| event | string | 是 | 需要设置的会话事件的名称。 | 855| args | {[key: string]: Object} | 是 | 需要传递的会话事件内容。 | 856| callback | AsyncCallback\<void> | 是 | 回调函数。当会话事件设置成功,err为undefined,否则返回错误对象。 | 857 858> **说明:** 859 860> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 861 862**错误码:** 863 864以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 865 866| 错误码ID | 错误信息 | 867| -------- | ---------------------------------------- | 868| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 869| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 870| 6600102 | The session does not exist. | 871 872**示例:** 873 874```ts 875import { BusinessError } from '@kit.BasicServicesKit'; 876import { avSession } from '@kit.AVSessionKit'; 877@Entry 878@Component 879struct Index { 880 @State message: string = 'hello world'; 881 882 build() { 883 Column() { 884 Text(this.message) 885 .onClick(()=>{ 886 let currentAVSession: avSession.AVSession | undefined = undefined; 887 let tag = "createNewSession"; 888 let context: Context = this.getUIContext().getHostContext() as Context; 889 890 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 891 if (err) { 892 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 893 } else { 894 currentAVSession = data; 895 } 896 }); 897 let eventName: string = "dynamic_lyric"; 898 if (currentAVSession !== undefined) { 899 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => { 900 if (err) { 901 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 902 } 903 }) 904 } 905 }) 906 } 907 .width('100%') 908 .height('100%') 909 } 910} 911``` 912 913### setAVQueueItems<sup>10+</sup> 914 915setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void> 916 917设置媒体播放列表。结果通过Promise异步回调方式返回。 918 919**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 920 921**系统能力:** SystemCapability.Multimedia.AVSession.Core 922 923**参数:** 924 925| 参数名 | 类型 | 必填 | 说明 | 926| ------ | ------------------------------------ | ---- | ---------------------------------- | 927| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | 928 929**返回值:** 930 931| 类型 | 说明 | 932| -------------- | ----------------------------- | 933| Promise\<void> | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | 934 935**错误码:** 936 937以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 938 939| 错误码ID | 错误信息 | 940| -------- | ---------------------------------------- | 941| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 942| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 943| 6600102 | The session does not exist. | 944 945**示例:** 946 947```ts 948import { image } from '@kit.ImageKit'; 949import { resourceManager } from '@kit.LocalizationKit'; 950import { BusinessError } from '@kit.BasicServicesKit'; 951 952async function setAVQueueItems() { 953 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 954 let imageSource = await image.createImageSource(value.buffer); 955 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 956 let queueItemDescription_1: avSession.AVMediaDescription = { 957 assetId: '001', 958 title: 'music_name', 959 subtitle: 'music_sub_name', 960 description: 'music_description', 961 mediaImage : imagePixel, 962 extras: {extras:'any'} 963 }; 964 let queueItem_1: avSession.AVQueueItem = { 965 itemId: 1, 966 description: queueItemDescription_1 967 }; 968 let queueItemDescription_2: avSession.AVMediaDescription = { 969 assetId: '002', 970 title: 'music_name', 971 subtitle: 'music_sub_name', 972 description: 'music_description', 973 mediaImage: imagePixel, 974 extras: {extras:'any'} 975 }; 976 let queueItem_2: avSession.AVQueueItem = { 977 itemId: 2, 978 description: queueItemDescription_2 979 }; 980 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 981 currentAVSession.setAVQueueItems(queueItemsArray).then(() => { 982 console.info('SetAVQueueItems successfully'); 983 }).catch((err: BusinessError) => { 984 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 985 }); 986} 987``` 988 989### setAVQueueItems<sup>10+</sup> 990 991setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void 992 993设置媒体播放列表。结果通过callback异步回调方式返回。 994 995**系统能力:** SystemCapability.Multimedia.AVSession.Core 996 997**参数:** 998 999| 参数名 | 类型 | 必填 | 说明 | 1000| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | 1001| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | 1002| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 1003 1004**错误码:** 1005 1006以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1007 1008| 错误码ID | 错误信息 | 1009| -------- | ---------------------------------------- | 1010| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1011| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1012| 6600102 | The session does not exist. | 1013 1014**示例:** 1015 1016```ts 1017import { image } from '@kit.ImageKit'; 1018import { resourceManager } from '@kit.LocalizationKit'; 1019import { BusinessError } from '@kit.BasicServicesKit'; 1020 1021async function setAVQueueItems() { 1022 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 1023 let imageSource = await image.createImageSource(value.buffer); 1024 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 1025 let queueItemDescription_1: avSession.AVMediaDescription = { 1026 assetId: '001', 1027 title: 'music_name', 1028 subtitle: 'music_sub_name', 1029 description: 'music_description', 1030 mediaImage : imagePixel, 1031 extras: {extras:'any'} 1032 }; 1033 let queueItem_1: avSession.AVQueueItem = { 1034 itemId: 1, 1035 description: queueItemDescription_1 1036 }; 1037 let queueItemDescription_2: avSession.AVMediaDescription = { 1038 assetId: '002', 1039 title: 'music_name', 1040 subtitle: 'music_sub_name', 1041 description: 'music_description', 1042 mediaImage: imagePixel, 1043 extras: {extras:'any'} 1044 }; 1045 let queueItem_2: avSession.AVQueueItem = { 1046 itemId: 2, 1047 description: queueItemDescription_2 1048 }; 1049 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 1050 currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => { 1051 if (err) { 1052 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 1053 } else { 1054 console.info('SetAVQueueItems successfully'); 1055 } 1056 }); 1057} 1058``` 1059 1060### setAVQueueTitle<sup>10+</sup> 1061 1062setAVQueueTitle(title: string): Promise\<void> 1063 1064设置媒体播放列表名称。结果通过Promise异步回调方式返回。 1065 1066**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1067 1068**系统能力:** SystemCapability.Multimedia.AVSession.Core 1069 1070**参数:** 1071 1072| 参数名 | 类型 | 必填 | 说明 | 1073| ------ | ------ | ---- | -------------- | 1074| title | string | 是 | 播放列表的名称。 | 1075 1076**返回值:** 1077 1078| 类型 | 说明 | 1079| -------------- | ----------------------------- | 1080| Promise\<void> | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | 1081 1082**错误码:** 1083 1084以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1085 1086| 错误码ID | 错误信息 | 1087| -------- | ---------------------------------------- | 1088| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1089| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1090| 6600102 | The session does not exist. | 1091 1092**示例:** 1093 1094```ts 1095import { BusinessError } from '@kit.BasicServicesKit'; 1096 1097let queueTitle = 'QUEUE_TITLE'; 1098currentAVSession.setAVQueueTitle(queueTitle).then(() => { 1099 console.info('SetAVQueueTitle successfully'); 1100}).catch((err: BusinessError) => { 1101 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1102}); 1103``` 1104 1105### setAVQueueTitle<sup>10+</sup> 1106 1107setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void 1108 1109设置媒体播放列表名称。结果通过callback异步回调方式返回。 1110 1111**系统能力:** SystemCapability.Multimedia.AVSession.Core 1112 1113**参数:** 1114 1115| 参数名 | 类型 | 必填 | 说明 | 1116| -------- | --------------------- | ---- | ----------------------------------------------------------- | 1117| title | string | 是 | 播放列表名称字段。 | 1118| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 1119 1120**错误码:** 1121 1122以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1123 1124| 错误码ID | 错误信息 | 1125| -------- | ---------------------------------------- | 1126| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1127| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1128| 6600102 | The session does not exist. | 1129 1130**示例:** 1131 1132```ts 1133import { BusinessError } from '@kit.BasicServicesKit'; 1134 1135let queueTitle = 'QUEUE_TITLE'; 1136currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => { 1137 if (err) { 1138 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1139 } else { 1140 console.info('SetAVQueueTitle successfully'); 1141 } 1142}); 1143``` 1144 1145### setExtras<sup>10+</sup> 1146 1147setExtras(extras: {[key: string]: Object}): Promise\<void> 1148 1149媒体提供方设置键值对形式的自定义媒体数据包,结果通过Promise异步回调方式返回。 1150 1151**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1152 1153**系统能力:** SystemCapability.Multimedia.AVSession.Core 1154 1155**参数:** 1156 1157| 参数名 | 类型 | 必填 | 说明 | 1158| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1159| extras | {[key: string]: Object} | 是 | 需要传递的自定义媒体数据包键值对。 | 1160 1161> **说明:** 1162 1163> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 1164 1165**返回值:** 1166 1167| 类型 | 说明 | 1168| -------------- | ----------------------------- | 1169| Promise\<void> | Promise对象。当自定义媒体数据包设置成功,无返回结果,否则返回错误对象。 | 1170 1171**错误码:** 1172 1173以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1174 1175| 错误码ID | 错误信息 | 1176| -------- | ---------------------------------------- | 1177| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1178| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1179| 6600102 | The session does not exist. | 1180 1181**示例:** 1182 1183```ts 1184import { BusinessError } from '@kit.BasicServicesKit'; 1185import { avSession } from '@kit.AVSessionKit'; 1186@Entry 1187@Component 1188struct Index { 1189 @State message: string = 'hello world'; 1190 1191 build() { 1192 Column() { 1193 Text(this.message) 1194 .onClick(()=>{ 1195 let currentAVSession: avSession.AVSession | undefined = undefined; 1196 let tag = "createNewSession"; 1197 let context: Context = this.getUIContext().getHostContext() as Context; 1198 1199 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1200 if (err) { 1201 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1202 } else { 1203 currentAVSession = data; 1204 } 1205 }); 1206 if (currentAVSession !== undefined) { 1207 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => { 1208 console.info('setExtras successfully'); 1209 }).catch((err: BusinessError) => { 1210 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1211 }) 1212 } 1213 }) 1214 } 1215 .width('100%') 1216 .height('100%') 1217 } 1218} 1219``` 1220 1221### setExtras<sup>10+</sup> 1222 1223setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void 1224 1225媒体提供方设置键值对形式的自定义媒体数据包,结果通过callback异步回调方式返回。 1226 1227**系统能力:** SystemCapability.Multimedia.AVSession.Core 1228 1229**参数:** 1230 1231| 参数名 | 类型 | 必填 | 说明 | 1232| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1233| extras | {[key: string]: Object} | 是 | 需要传递的自定义媒体数据包键值对。 | 1234| callback | AsyncCallback\<void> | 是 | 回调函数。当自定义媒体数据包设置成功,err为undefined,否则返回错误对象。 | 1235 1236> **说明:** 1237 1238> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 1239 1240**错误码:** 1241 1242以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1243 1244| 错误码ID | 错误信息 | 1245| -------- | ---------------------------------------- | 1246| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1247| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1248| 6600102 | The session does not exist. | 1249 1250**示例:** 1251 1252```ts 1253import { BusinessError } from '@kit.BasicServicesKit'; 1254import { avSession } from '@kit.AVSessionKit'; 1255@Entry 1256@Component 1257struct Index { 1258 @State message: string = 'hello world'; 1259 1260 build() { 1261 Column() { 1262 Text(this.message) 1263 .onClick(()=>{ 1264 let currentAVSession: avSession.AVSession | undefined = undefined; 1265 let tag = "createNewSession"; 1266 let context: Context = this.getUIContext().getHostContext() as Context; 1267 1268 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1269 if (err) { 1270 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1271 } else { 1272 currentAVSession = data; 1273 } 1274 }); 1275 if (currentAVSession !== undefined) { 1276 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => { 1277 if (err) { 1278 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1279 } 1280 }) 1281 } 1282 }) 1283 } 1284 .width('100%') 1285 .height('100%') 1286 } 1287} 1288``` 1289 1290### getController<sup>10+</sup> 1291 1292getController(): Promise\<AVSessionController> 1293 1294获取本会话对应的控制器。结果通过Promise异步回调方式返回。 1295 1296**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1297 1298**系统能力:** SystemCapability.Multimedia.AVSession.Core 1299 1300**返回值:** 1301 1302| 类型 | 说明 | 1303| ---------------------------------------------------- | ----------------------------- | 1304| Promise<[AVSessionController](#avsessioncontroller10)> | Promise对象。返回会话控制器。 | 1305 1306**错误码:** 1307 1308以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1309 1310| 错误码ID | 错误信息 | 1311| -------- | ---------------------------------------- | 1312| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1313| 6600102 | The session does not exist. | 1314 1315**示例:** 1316 1317```ts 1318import { BusinessError } from '@kit.BasicServicesKit'; 1319import { avSession } from '@kit.AVSessionKit'; 1320 1321@Entry 1322@Component 1323struct Index { 1324 @State message: string = 'hello world'; 1325 build() { 1326 Column() { 1327 Text(this.message) 1328 .onClick(async ()=>{ 1329 let context: Context = this.getUIContext().getHostContext() as Context; 1330 let currentAVSession: avSession.AVSession = await avSession.createAVSession(context, 'SESSION_NAME', 'audio'); 1331 let avsessionController: avSession.AVSessionController; 1332 currentAVSession.getController().then(async (avcontroller: avSession.AVSessionController) => { 1333 avsessionController = avcontroller; 1334 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1335 }).catch((err: BusinessError) => { 1336 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1337 }); 1338 }) 1339 } 1340 .width('100%') 1341 .height('100%') 1342 } 1343} 1344``` 1345 1346### getController<sup>10+</sup> 1347 1348getController(callback: AsyncCallback\<AVSessionController>): void 1349 1350获取本会话相应的控制器。结果通过callback异步回调方式返回。 1351 1352**系统能力:** SystemCapability.Multimedia.AVSession.Core 1353 1354**参数:** 1355 1356| 参数名 | 类型 | 必填 | 说明 | 1357| -------- | ----------------------------------------------------------- | ---- | -------------------------- | 1358| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | 是 | 回调函数。返回会话控制器。 | 1359 1360**错误码:** 1361 1362以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1363 1364| 错误码ID | 错误信息 | 1365| -------- | ---------------------------------------- | 1366| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1367| 6600102 | The session does not exist. | 1368 1369**示例:** 1370 1371```ts 1372import { avSession } from '@kit.AVSessionKit'; 1373import { BusinessError } from '@kit.BasicServicesKit'; 1374 1375@Entry 1376@Component 1377struct Index { 1378 @State message: string = 'hello world'; 1379 1380 build() { 1381 Column() { 1382 Text(this.message) 1383 .onClick(async () => { 1384 let context: Context = this.getUIContext().getHostContext() as Context; 1385 let currentAVSession: avSession.AVSession = await avSession.createAVSession(context, 'SESSION_NAME', 'audio'); 1386 let avsessionController: avSession.AVSessionController; 1387 currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => { 1388 if (err) { 1389 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1390 } else { 1391 avsessionController = avcontroller; 1392 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1393 } 1394 }); 1395 }) 1396 } 1397 .width('100%') 1398 .height('100%') 1399 } 1400} 1401``` 1402 1403### getAVCastController<sup>10+</sup> 1404 1405getAVCastController(): Promise\<AVCastController> 1406 1407设备建立连接后,获取投播控制器。结果通过Promise异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。 1408 1409**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1410 1411**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 1412 1413**返回值:** 1414 1415| 类型 | 说明 | 1416| --------- | ------------------------------------------------------------ | 1417| Promise<[AVCastController](#avcastcontroller10)\> | Promise对象。返回投播控制器实例。 | 1418 1419**错误码:** 1420 1421以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1422 1423| 错误码ID | 错误信息 | 1424| -------- | --------------------------------------- | 1425| 6600102| The session does not exist. | 1426| 6600109| The remote connection is not established. | 1427 1428**示例:** 1429 1430```ts 1431import { BusinessError } from '@kit.BasicServicesKit'; 1432 1433let aVCastController: avSession.AVCastController; 1434currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => { 1435 aVCastController = avcontroller; 1436 console.info('getAVCastController : SUCCESS'); 1437}).catch((err: BusinessError) => { 1438 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1439}); 1440``` 1441 1442### getAVCastController<sup>10+</sup> 1443 1444getAVCastController(callback: AsyncCallback\<AVCastController>): void 1445 1446设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。 1447 1448**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 1449 1450**参数:** 1451 1452| 参数名 | 类型 | 必填 | 说明 | 1453| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1454| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | 是 | 回调函数,返回投播控制器实例。 | 1455 1456**错误码:** 1457 1458以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1459 1460| 错误码ID | 错误信息 | 1461| -------- |---------------------------------------| 1462| 6600102| The session does not exist. | 1463| 6600109| The remote connection is not established. | 1464 1465**示例:** 1466 1467```ts 1468import { BusinessError } from '@kit.BasicServicesKit'; 1469 1470let aVCastController: avSession.AVCastController; 1471currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => { 1472 if (err) { 1473 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1474 } else { 1475 aVCastController = avcontroller; 1476 console.info('getAVCastController : SUCCESS'); 1477 } 1478}); 1479``` 1480 1481### getOutputDevice<sup>10+</sup> 1482 1483getOutputDevice(): Promise\<OutputDeviceInfo> 1484 1485通过会话获取播放设备信息。结果通过Promise异步回调方式返回。 1486 1487**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1488 1489**系统能力:** SystemCapability.Multimedia.AVSession.Core 1490 1491**返回值:** 1492 1493| 类型 | 说明 | 1494| ---------------------------------------------- | --------------------------------- | 1495| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise对象。返回播放设备信息。 | 1496 1497**错误码:** 1498 1499以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1500 1501| 错误码ID | 错误信息 | 1502| -------- | ---------------------------------------- | 1503| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1504| 6600102 | The session does not exist. | 1505 1506**示例:** 1507 1508```ts 1509import { BusinessError } from '@kit.BasicServicesKit'; 1510 1511currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => { 1512 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1513}).catch((err: BusinessError) => { 1514 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1515}) 1516``` 1517 1518### getOutputDevice<sup>10+</sup> 1519 1520getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 1521 1522通过会话获取播放设备相关信息。结果通过callback异步回调方式返回。 1523 1524**系统能力:** SystemCapability.Multimedia.AVSession.Core 1525 1526**参数:** 1527 1528| 参数名 | 类型 | 必填 | 说明 | 1529| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 1530| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是 | 回调函数,返回播放设备信息。 | 1531 1532**错误码:** 1533 1534以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1535 1536| 错误码ID | 错误信息 | 1537| -------- | ---------------------------------------- | 1538| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1539| 6600102 | The session does not exist. | 1540 1541**示例:** 1542 1543```ts 1544import { BusinessError } from '@kit.BasicServicesKit'; 1545 1546currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => { 1547 if (err) { 1548 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1549 } else { 1550 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1551 } 1552}); 1553``` 1554 1555### activate<sup>10+</sup> 1556 1557activate(): Promise\<void> 1558 1559激活会话,激活后可正常使用会话。结果通过Promise异步回调方式返回。 1560 1561**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1562 1563**系统能力:** SystemCapability.Multimedia.AVSession.Core 1564 1565**返回值:** 1566 1567| 类型 | 说明 | 1568| -------------- | ----------------------------- | 1569| Promise\<void> | Promise对象。当会话激活成功,无返回结果,否则返回错误对象。 | 1570 1571**错误码:** 1572 1573以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1574 1575| 错误码ID | 错误信息 | 1576| -------- | ---------------------------------------- | 1577| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1578| 6600102 | The session does not exist. | 1579 1580**示例:** 1581 1582```ts 1583import { BusinessError } from '@kit.BasicServicesKit'; 1584 1585currentAVSession.activate().then(() => { 1586 console.info('Activate : SUCCESS '); 1587}).catch((err: BusinessError) => { 1588 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1589}); 1590``` 1591 1592### activate<sup>10+</sup> 1593 1594activate(callback: AsyncCallback\<void>): void 1595 1596激活会话,激活后可正常使用会话。结果通过callback异步回调方式返回。 1597 1598**系统能力:** SystemCapability.Multimedia.AVSession.Core 1599 1600**参数:** 1601 1602| 参数名 | 类型 | 必填 | 说明 | 1603| -------- | -------------------- | ---- | ---------- | 1604| callback | AsyncCallback\<void> | 是 | 回调函数。当会话激活成功,err为undefined,否则返回错误对象。 | 1605 1606**错误码:** 1607 1608以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1609 1610| 错误码ID | 错误信息 | 1611| -------- | ---------------------------------------- | 1612| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1613| 6600102 | The session does not exist. | 1614 1615**示例:** 1616 1617```ts 1618import { BusinessError } from '@kit.BasicServicesKit'; 1619 1620currentAVSession.activate((err: BusinessError) => { 1621 if (err) { 1622 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1623 } else { 1624 console.info('Activate : SUCCESS '); 1625 } 1626}); 1627``` 1628 1629### deactivate<sup>10+</sup> 1630 1631deactivate(): Promise\<void> 1632 1633禁用当前会话的功能,可通过[activate](#activate10)恢复。结果通过Promise异步回调方式返回。 1634 1635**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1636 1637**系统能力:** SystemCapability.Multimedia.AVSession.Core 1638 1639**返回值:** 1640 1641| 类型 | 说明 | 1642| -------------- | ----------------------------- | 1643| Promise\<void> | Promise对象。当禁用会话成功,无返回结果,否则返回错误对象。| 1644 1645**错误码:** 1646 1647以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1648 1649| 错误码ID | 错误信息 | 1650| -------- | ---------------------------------------- | 1651| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1652| 6600102 | The session does not exist. | 1653 1654**示例:** 1655 1656```ts 1657import { BusinessError } from '@kit.BasicServicesKit'; 1658 1659currentAVSession.deactivate().then(() => { 1660 console.info('Deactivate : SUCCESS '); 1661}).catch((err: BusinessError) => { 1662 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1663}); 1664``` 1665 1666### deactivate<sup>10+</sup> 1667 1668deactivate(callback: AsyncCallback\<void>): void 1669 1670禁用当前会话。结果通过callback异步回调方式返回。 1671 1672禁用当前会话的功能,可通过[activate](#activate10)恢复。 1673 1674**系统能力:** SystemCapability.Multimedia.AVSession.Core 1675 1676**参数:** 1677 1678| 参数名 | 类型 | 必填 | 说明 | 1679| -------- | -------------------- | ---- | ---------- | 1680| callback | AsyncCallback\<void> | 是 | 回调函数。当禁用会话成功,err为undefined,否则返回错误对象。| 1681 1682**错误码:** 1683 1684以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1685 1686| 错误码ID | 错误信息 | 1687| -------- | ---------------------------------------- | 1688| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1689| 6600102 | The session does not exist. | 1690 1691**示例:** 1692 1693```ts 1694import { BusinessError } from '@kit.BasicServicesKit'; 1695 1696currentAVSession.deactivate((err: BusinessError) => { 1697 if (err) { 1698 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1699 } else { 1700 console.info('Deactivate : SUCCESS '); 1701 } 1702}); 1703``` 1704 1705### destroy<sup>10+</sup> 1706 1707destroy(): Promise\<void> 1708 1709销毁当前会话,使当前会话完全失效。结果通过Promise异步回调方式返回。 1710 1711**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1712 1713**系统能力:** SystemCapability.Multimedia.AVSession.Core 1714 1715**返回值:** 1716 1717| 类型 | 说明 | 1718| -------------- | ----------------------------- | 1719| Promise\<void> | Promise对象。当会话销毁成功,无返回结果,否则返回错误对象。 | 1720 1721**错误码:** 1722 1723以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1724 1725| 错误码ID | 错误信息 | 1726| -------- | ---------------------------------------- | 1727| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1728| 6600102 | The session does not exist. | 1729 1730**示例:** 1731 1732```ts 1733import { BusinessError } from '@kit.BasicServicesKit'; 1734 1735currentAVSession.destroy().then(() => { 1736 console.info('Destroy : SUCCESS '); 1737}).catch((err: BusinessError) => { 1738 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1739}); 1740``` 1741 1742### destroy<sup>10+</sup> 1743 1744destroy(callback: AsyncCallback\<void>): void 1745 1746销毁当前会话,使当前会话完全失效。结果通过callback异步回调方式返回。 1747 1748**系统能力:** SystemCapability.Multimedia.AVSession.Core 1749 1750**参数:** 1751 1752| 参数名 | 类型 | 必填 | 说明 | 1753| -------- | -------------------- | ---- | ---------- | 1754| callback | AsyncCallback\<void> | 是 | 回调函数。当会话销毁成功,err为undefined,否则返回错误对象。 | 1755 1756**错误码:** 1757 1758以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1759 1760| 错误码ID | 错误信息 | 1761| -------- | ---------------------------------------- | 1762| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1763| 6600102 | The session does not exist. | 1764 1765**示例:** 1766 1767```ts 1768import { BusinessError } from '@kit.BasicServicesKit'; 1769 1770currentAVSession.destroy((err: BusinessError) => { 1771 if (err) { 1772 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1773 } else { 1774 console.info('Destroy : SUCCESS '); 1775 } 1776}); 1777``` 1778 1779### on('play')<sup>10+</sup> 1780 1781on(type: 'play', callback: () => void): void 1782 1783设置播放命令监听事件。注册该监听,说明应用支持播放指令。 1784 1785每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1786 1787**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1788 1789**系统能力:** SystemCapability.Multimedia.AVSession.Core 1790 1791**参数:** 1792 1793| 参数名 | 类型 | 必填 | 说明 | 1794| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1795| type | string | 是 | 事件回调类型,支持的事件为`'play'`,当播放命令被发送到会话时,触发该事件回调。 | 1796| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1797 1798**错误码:** 1799 1800以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1801 1802| 错误码ID | 错误信息 | 1803| -------- | ---------------------------------------- | 1804| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1805| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1806| 6600102 | The session does not exist. | 1807 1808**示例:** 1809 1810```ts 1811currentAVSession.on('play', () => { 1812 console.info('on play entry'); 1813}); 1814``` 1815 1816### on('pause')<sup>10+</sup> 1817 1818on(type: 'pause', callback: () => void): void 1819 1820设置暂停命令监听事件。注册该监听,说明应用支持暂停指令。 1821 1822每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1823 1824**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1825 1826**系统能力:** SystemCapability.Multimedia.AVSession.Core 1827 1828**参数:** 1829 1830| 参数名 | 类型 | 必填 | 说明 | 1831| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1832| type | string | 是 | 事件回调类型,支持的事件为`'pause'`,当暂停命令被发送到会话时,触发该事件回调。 | 1833| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1834 1835**错误码:** 1836 1837以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1838 1839| 错误码ID | 错误信息 | 1840| -------- | ---------------------------------------- | 1841| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1842| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1843| 6600102 | The session does not exist. | 1844 1845**示例:** 1846 1847```ts 1848currentAVSession.on('pause', () => { 1849 console.info('on pause entry'); 1850}); 1851``` 1852 1853### on('stop')<sup>10+</sup> 1854 1855on(type:'stop', callback: () => void): void 1856 1857设置停止命令监听事件。注册该监听,说明应用支持停止指令。 1858 1859每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1860 1861**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1862 1863**系统能力:** SystemCapability.Multimedia.AVSession.Core 1864 1865**参数:** 1866 1867| 参数名 | 类型 | 必填 | 说明 | 1868| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1869| type | string | 是 | 事件回调类型,支持的事件是`'stop'`,当停止命令被发送到会话时,触发该事件回调。 | 1870| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1871 1872**错误码:** 1873 1874以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1875 1876| 错误码ID | 错误信息 | 1877| -------- | ---------------------------------------- | 1878| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1879| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1880| 6600102 | The session does not exist. | 1881 1882**示例:** 1883 1884```ts 1885currentAVSession.on('stop', () => { 1886 console.info('on stop entry'); 1887}); 1888``` 1889 1890### on('playNext')<sup>10+</sup> 1891 1892on(type:'playNext', callback: () => void): void 1893 1894设置播放下一首命令监听事件。注册该监听,说明应用支持下一首指令。 1895 1896每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1897 1898**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1899 1900**系统能力:** SystemCapability.Multimedia.AVSession.Core 1901 1902**参数:** 1903 1904| 参数名 | 类型 | 必填 | 说明 | 1905| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1906| type | string | 是 | 事件回调类型,支持的事件是`'playNext'`,当播放下一首命令被发送到会话时,触发该事件回调。 | 1907| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1908 1909**错误码:** 1910 1911以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1912 1913| 错误码ID | 错误信息 | 1914| -------- | ---------------------------------------- | 1915| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1916| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1917| 6600102 | The session does not exist. | 1918 1919**示例:** 1920 1921```ts 1922currentAVSession.on('playNext', () => { 1923 console.info('on playNext entry'); 1924}); 1925``` 1926 1927### on('playPrevious')<sup>10+</sup> 1928 1929on(type:'playPrevious', callback: () => void): void 1930 1931设置播放上一首命令监听事件。注册该监听,说明应用支持上一首指令。 1932 1933每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1934 1935**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1936 1937**系统能力:** SystemCapability.Multimedia.AVSession.Core 1938 1939**参数:** 1940 1941| 参数名 | 类型 | 必填 | 说明 | 1942| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1943| type | string | 是 | 事件回调类型,支持的事件是`'playPrevious'`,当播放上一首命令被发送到会话时,触发该事件回调。 | 1944| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1945 1946**错误码:** 1947 1948以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1949 1950| 错误码ID | 错误信息 | 1951| -------- | ---------------------------------------- | 1952| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1953| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1954| 6600102 | The session does not exist. | 1955 1956**示例:** 1957 1958```ts 1959currentAVSession.on('playPrevious', () => { 1960 console.info('on playPrevious entry'); 1961}); 1962``` 1963 1964### on('fastForward')<sup>10+</sup> 1965 1966on(type: 'fastForward', callback: (time?: number) => void): void 1967 1968设置快进命令监听事件。注册该监听,说明应用支持快进指令。 1969 1970每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1971 1972**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1973 1974**系统能力:** SystemCapability.Multimedia.AVSession.Core 1975 1976**参数:** 1977 1978| 参数名 | 类型 | 必填 | 说明 | 1979| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1980| type | string | 是 | 事件回调类型,支持的事件是 `'fastForward'`,当快进命令被发送到会话时,触发该事件回调。 | 1981| callback | (time?: number) => void | 是 | 回调函数。参数time是时间节点,单位为秒。 | 1982 1983**错误码:** 1984 1985以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1986 1987| 错误码ID | 错误信息 | 1988| -------- | ---------------------------------------- | 1989| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1990| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1991| 6600102 | The session does not exist. | 1992 1993**示例:** 1994 1995```ts 1996currentAVSession.on('fastForward', (time?: number) => { 1997 console.info('on fastForward entry'); 1998}); 1999``` 2000 2001### on('rewind')<sup>10+</sup> 2002 2003on(type:'rewind', callback: (time?: number) => void): void 2004 2005设置快退命令监听事件。 2006 2007**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2008 2009**系统能力:** SystemCapability.Multimedia.AVSession.Core 2010 2011**参数:** 2012 2013| 参数名 | 类型 | 必填 | 说明 | 2014| -------- | -------------------- | ---- | ------------------------------------------------------------ | 2015| type | string | 是 | 事件回调类型,支持的事件是`'rewind'`,当快退命令被发送到会话时,触发该事件回调。 | 2016| callback | (time?: number) => void | 是 | 回调函数。参数time是时间节点,单位为秒。 | 2017 2018**错误码:** 2019 2020以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2021 2022| 错误码ID | 错误信息 | 2023| -------- | ---------------------------------------- | 2024| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2025| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2026| 6600102 | The session does not exist. | 2027 2028**示例:** 2029 2030```ts 2031currentAVSession.on('rewind', (time?: number) => { 2032 console.info('on rewind entry'); 2033}); 2034``` 2035 2036### on('playFromAssetId')<sup>(deprecated)</sup> 2037 2038on(type:'playFromAssetId', callback: (assetId: number) => void): void 2039 2040设置媒体id播放监听事件。 2041 2042> **说明:** 2043> 从 API version 11 开始支持,从 API version 20 开始废弃。建议使用[on('playWithAssetId')](#onplaywithassetid20)设置媒体id播放监听事件。 2044 2045**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2046 2047**系统能力:** SystemCapability.Multimedia.AVSession.Core 2048 2049**参数:** 2050 2051| 参数名 | 类型 | 必填 | 说明 | 2052| -------- | -------------------- | ---- | ------------------------------------------------------------ | 2053| type | string | 是 | 事件回调类型,支持的事件是`'playFromAssetId'`,当媒体id播放时,触发该事件回调。 | 2054| callback | (assetId: number) => void | 是 | 回调函数。参数assetId是媒体id。 | 2055 2056**错误码:** 2057 2058以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2059 2060| 错误码ID | 错误信息 | 2061| -------- | ---------------------------------------- | 2062| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2063| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2064| 6600102 | The session does not exist. | 2065 2066**示例:** 2067 2068```ts 2069currentAVSession.on('playFromAssetId', (assetId: number) => { 2070 console.info('on playFromAssetId entry'); 2071}); 2072``` 2073 2074### off('playFromAssetId')<sup>(deprecated)</sup> 2075 2076off(type: 'playFromAssetId', callback?: (assetId: number) => void): void 2077 2078取消媒体id播放事件监听,关闭后,不再进行该事件回调。 2079 2080> **说明:** 2081> 从 API version 11 开始支持,从 API version 20 开始废弃。建议使用[off('playWithAssetId')](#offplaywithassetid20)取消媒体id播放事件监听。 2082 2083**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2084 2085**系统能力:** SystemCapability.Multimedia.AVSession.Core 2086 2087**参数:** 2088 2089| 参数名 | 类型 | 必填 | 说明 | 2090| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2091| type | string | 是 | 关闭对应的监听事件,支持的事件是`'playFromAssetId'`。 | 2092| callback | (assetId: number) => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。参数assetId是媒体id。 | 2093 2094**错误码:** 2095 2096以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2097 2098| 错误码ID | 错误信息 | 2099| -------- | ---------------------------------------- | 2100| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2101| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2102| 6600102 | The session does not exist. | 2103 2104**示例:** 2105 2106```ts 2107currentAVSession.off('playFromAssetId'); 2108``` 2109 2110### on('playWithAssetId')<sup>20+</sup> 2111 2112on(type:'playWithAssetId', callback: Callback\<string>): void 2113 2114设置指定资源id进行播放的监听事件。 2115 2116**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 2117 2118**系统能力:** SystemCapability.Multimedia.AVSession.Core 2119 2120**参数:** 2121 2122| 参数名 | 类型 | 必填 | 说明 | 2123| -------- | -------------------- | ---- | ------------------------------------------------------------ | 2124| type | string | 是 | 事件回调类型,支持的事件是`'playWithAssetId'`,当指定资源id进行播放时,触发该事件回调。 | 2125| callback | Callback\<string> | 是 | 回调函数。参数assetId是媒体id。 | 2126 2127**错误码:** 2128 2129以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2130 2131| 错误码ID | 错误信息 | 2132| -------- | ---------------------------------------- | 2133| 6600101 | Session service exception. | 2134| 6600102 | The session does not exist. | 2135 2136**示例:** 2137 2138```ts 2139let playWithAssetIdCallback = (assetId: string) => { 2140 console.info(`on playWithAssetId entry, assetId = ${assetId}`); 2141} 2142currentAVSession.on('playWithAssetId', playWithAssetIdCallback); 2143``` 2144 2145 2146### off('playWithAssetId')<sup>20+</sup> 2147 2148off(type: 'playWithAssetId', callback?: Callback\<string>): void 2149 2150取消指定资源id进行播放的事件监听,关闭后,不再进行该事件回调。 2151 2152**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 2153 2154**系统能力:** SystemCapability.Multimedia.AVSession.Core 2155 2156**参数:** 2157 2158| 参数名 | 类型 | 必填 | 说明 | 2159| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2160| type | string | 是 | 关闭对应的监听事件,支持的事件是`'playWithAssetId'`。 | 2161| callback | Callback\<string> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。参数assetId是媒体id。 | 2162 2163**错误码:** 2164 2165以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2166 2167| 错误码ID | 错误信息 | 2168| -------- | ---------------------------------------- | 2169| 6600101 | Session service exception. | 2170| 6600102 | The session does not exist. | 2171 2172**示例:** 2173 2174```ts 2175currentAVSession.off('playWithAssetId'); 2176``` 2177 2178### on('seek')<sup>10+</sup> 2179 2180on(type: 'seek', callback: (time: number) => void): void 2181 2182设置跳转节点监听事件。 2183 2184**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2185 2186**系统能力:** SystemCapability.Multimedia.AVSession.Core 2187 2188**参数:** 2189 2190| 参数名 | 类型 | 必填 | 说明 | 2191| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2192| type | string | 是 | 事件回调类型,支持事件`'seek'`:当跳转节点命令被发送到会话时,触发该事件。 | 2193| callback | (time: number) => void | 是 | 回调函数。参数time是时间节点,单位为毫秒。 | 2194 2195**错误码:** 2196 2197以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2198 2199| 错误码ID | 错误信息 | 2200| -------- | ---------------------------------------- | 2201| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2202| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2203| 6600102 | The session does not exist. | 2204 2205**示例:** 2206 2207```ts 2208currentAVSession.on('seek', (time: number) => { 2209 console.info(`on seek entry time : ${time}`); 2210}); 2211``` 2212 2213### on('setSpeed')<sup>10+</sup> 2214 2215on(type: 'setSpeed', callback: (speed: number) => void): void 2216 2217设置播放速率的监听事件。 2218 2219**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2220 2221**系统能力:** SystemCapability.Multimedia.AVSession.Core 2222 2223**参数:** 2224 2225| 参数名 | 类型 | 必填 | 说明 | 2226| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 2227| type | string | 是 | 事件回调类型,支持事件`'setSpeed'`:当设置播放速率的命令被发送到会话时,触发该事件。 | 2228| callback | (speed: number) => void | 是 | 回调函数。参数speed是播放倍速。 | 2229 2230**错误码:** 2231 2232以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2233 2234| 错误码ID | 错误信息 | 2235| -------- | ---------------------------------------- | 2236| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2237| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2238| 6600102 | The session does not exist. | 2239 2240**示例:** 2241 2242```ts 2243currentAVSession.on('setSpeed', (speed: number) => { 2244 console.info(`on setSpeed speed : ${speed}`); 2245}); 2246``` 2247 2248### on('setLoopMode')<sup>10+</sup> 2249 2250on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void 2251 2252设置循环模式的监听事件。 2253 2254**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2255 2256**系统能力:** SystemCapability.Multimedia.AVSession.Core 2257 2258**参数:** 2259 2260| 参数名 | 类型 | 必填 | 说明 | 2261| -------- | ------------------------------------- | ---- | ---- | 2262| type | string | 是 | 事件回调类型,支持事件`'setLoopMode'`:当设置循环模式的命令被发送到会话时,触发该事件。 | 2263| callback | (mode: [LoopMode](#loopmode10)) => void | 是 | 回调函数。参数mode是循环模式。 | 2264 2265**错误码:** 2266 2267以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2268 2269| 错误码ID | 错误信息 | 2270| -------- | ---------------------------------------- | 2271| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2272| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2273| 6600102 | The session does not exist. | 2274 2275**示例:** 2276 2277```ts 2278currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => { 2279 console.info(`on setLoopMode mode : ${mode}`); 2280}); 2281``` 2282 2283### on('setTargetLoopMode')<sup>18+</sup> 2284 2285on(type: 'setTargetLoopMode', callback: Callback\<LoopMode>): void 2286 2287设置目标循环模式的监听事件。 2288 2289**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 2290 2291**系统能力:** SystemCapability.Multimedia.AVSession.Core 2292 2293**参数:** 2294 2295| 参数名 | 类型 | 必填 | 说明 | 2296| -------- | ------------------------------------- | ---- | ---- | 2297| type | string | 是 | 事件回调类型,支持事件`'setTargetLoopMode'`。<br>- `'setTargetLoopMode'`:当设置目标循环模式的命令被发送到会话时,触发该事件。 | 2298| callback | Callback<[LoopMode](#loopmode10)> | 是 | 回调函数。参数表示目标循环模式。 | 2299 2300**错误码:** 2301 2302以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。 2303 2304| 错误码ID | 错误信息 | 2305| -------- | ---------------------------------------- | 2306| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2307| 6600102 | The session does not exist. | 2308 2309**示例:** 2310 2311```ts 2312currentAVSession.on('setTargetLoopMode', (mode: avSession.LoopMode) => { 2313 console.info(`on setTargetLoopMode mode : ${mode}`); 2314}); 2315``` 2316 2317### on('toggleFavorite')<sup>10+</sup> 2318 2319on(type: 'toggleFavorite', callback: (assetId: string) => void): void 2320 2321设置是否收藏的监听事件 2322 2323**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2324 2325**系统能力:** SystemCapability.Multimedia.AVSession.Core 2326 2327**参数:** 2328 2329| 参数名 | 类型 | 必填 | 说明 | 2330| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 2331| type | string | 是 | 事件回调类型,支持事件`'toggleFavorite'`:当是否收藏的命令被发送到会话时,触发该事件。 | 2332| callback | (assetId: string) => void | 是 | 回调函数。参数assetId是媒体ID。 | 2333 2334**错误码:** 2335 2336以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2337 2338| 错误码ID | 错误信息 | 2339| -------- | ---------------------------------------- | 2340| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2341| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2342| 6600102 | The session does not exist. | 2343 2344**示例:** 2345 2346```ts 2347currentAVSession.on('toggleFavorite', (assetId: string) => { 2348 console.info(`on toggleFavorite mode : ${assetId}`); 2349}); 2350``` 2351 2352### on('skipToQueueItem')<sup>10+</sup> 2353 2354on(type: 'skipToQueueItem', callback: (itemId: number) => void): void 2355 2356设置播放列表其中某项被选中的监听事件,session端可以选择对这个单项歌曲进行播放。 2357 2358**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2359 2360**系统能力:** SystemCapability.Multimedia.AVSession.Core 2361 2362**参数:** 2363 2364| 参数名 | 类型 | 必填 | 说明 | 2365| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- | 2366| type | string | 是 | 事件回调类型,支持事件`'skipToQueueItem'`:当播放列表选中单项的命令被发送到会话时,触发该事件。 | 2367| callback | (itemId: number) => void | 是 | 回调函数。参数itemId是选中的播放列表项的ID。 | 2368 2369**错误码:** 2370 2371以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2372 2373| 错误码ID | 错误信息 | 2374| -------- | ---------------------------------------- | 2375| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2376| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2377| 6600102 | The session does not exist. | 2378 2379**示例:** 2380 2381```ts 2382currentAVSession.on('skipToQueueItem', (itemId: number) => { 2383 console.info(`on skipToQueueItem id : ${itemId}`); 2384}); 2385``` 2386 2387### on('handleKeyEvent')<sup>10+</sup> 2388 2389on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void 2390 2391设置蓝牙/有线等外设接入的按键输入事件的监听,监听多媒体按键事件中播放、暂停、上下一首、快进、快退的指令。 2392 2393**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2394 2395**系统能力:** SystemCapability.Multimedia.AVSession.Core 2396 2397**参数:** 2398 2399| 参数名 | 类型 | 必填 | 说明 | 2400| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2401| type | string | 是 | 事件回调类型,支持事件`'handleKeyEvent'`:当按键事件被发送到会话时,触发该事件。 | 2402| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | 是 | 回调函数。参数event是按键事件。 | 2403 2404**错误码:** 2405 2406以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2407 2408| 错误码ID | 错误信息 | 2409| -------- | ---------------------------------------- | 2410| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2411| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2412| 6600102 | The session does not exist. | 2413 2414**示例:** 2415 2416```ts 2417import { KeyEvent } from '@kit.InputKit'; 2418 2419currentAVSession.on('handleKeyEvent', (event: KeyEvent) => { 2420 console.info(`on handleKeyEvent event : ${event}`); 2421}); 2422 2423``` 2424 2425### on('outputDeviceChange')<sup>10+</sup> 2426 2427on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 2428 2429设置播放设备变化的监听事件。应用接入[系统投播组件](ohos-multimedia-avcastpicker.md),当用户通过组件切换设备时,会收到设备切换的回调。 2430 2431**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2432 2433**系统能力:** SystemCapability.Multimedia.AVSession.Core 2434 2435**参数:** 2436 2437| 参数名 | 类型 | 必填 | 说明 | 2438| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2439| type | string | 是 | 事件回调类型,支持事件`'outputDeviceChange'`:当播放设备变化时,触发该事件。 | 2440| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是 | 回调函数,参数device是设备相关信息。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2441 2442**错误码:** 2443 2444以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2445 2446| 错误码ID | 错误信息 | 2447| -------- | ---------------------------------------- | 2448| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2449| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2450| 6600102 | The session does not exist. | 2451 2452**示例:** 2453 2454```ts 2455currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 2456 console.info(`on outputDeviceChange device : ${device}`); 2457}); 2458``` 2459 2460### on('commonCommand')<sup>10+</sup> 2461 2462on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void 2463 2464设置自定义控制命令变化的监听器。 2465 2466**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2467 2468**系统能力:** SystemCapability.Multimedia.AVSession.Core 2469 2470**参数:** 2471 2472| 参数名 | 类型 | 必填 | 说明 | 2473| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2474| type | string | 是 | 事件回调类型,支持事件`'commonCommand'`:当自定义控制命令变化时,触发该事件。 | 2475| callback | (command: string, args: {[key: string]: Object}) => void | 是 | 回调函数,command为变化的自定义控制命令名,args为自定义控制命令的参数,参数内容与[sendCommonCommand](#sendcommoncommand10)方法设置的参数内容完全一致。 | 2476 2477**错误码:** 2478 2479以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2480 2481| 错误码ID | 错误信息 | 2482| -------- | ------------------------------ | 2483| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2484| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2485| 6600102 | The session does not exist. | 2486 2487**示例:** 2488 2489```ts 2490import { BusinessError } from '@kit.BasicServicesKit'; 2491import { avSession } from '@kit.AVSessionKit'; 2492@Entry 2493@Component 2494struct Index { 2495 @State message: string = 'hello world'; 2496 2497 build() { 2498 Column() { 2499 Text(this.message) 2500 .onClick(()=>{ 2501 let currentAVSession: avSession.AVSession | undefined = undefined; 2502 let tag = "createNewSession"; 2503 let context: Context = this.getUIContext().getHostContext() as Context; 2504 2505 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 2506 if (err) { 2507 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 2508 } else { 2509 currentAVSession = data; 2510 } 2511 }); 2512 if (currentAVSession !== undefined) { 2513 (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => { 2514 console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); 2515 }); 2516 } 2517 }) 2518 } 2519 .width('100%') 2520 .height('100%') 2521 } 2522} 2523``` 2524 2525### off('play')<sup>10+</sup> 2526 2527off(type: 'play', callback?: () => void): void 2528 2529取消会话播放事件监听,关闭后,不再进行该事件回调。 2530 2531取消回调时,需要更新支持的命令列表。 2532 2533**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2534 2535**系统能力:** SystemCapability.Multimedia.AVSession.Core 2536 2537**参数:** 2538 2539| 参数名 | 类型 | 必填 | 说明 | 2540| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2541| type | string | 是 | 关闭对应的监听事件,支持的事件是`'play'`。| 2542| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2543 2544**错误码:** 2545 2546以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2547 2548| 错误码ID | 错误信息 | 2549| -------- | ---------------------------------------- | 2550| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2551| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2552| 6600102 | The session does not exist. | 2553 2554**示例:** 2555 2556```ts 2557currentAVSession.off('play'); 2558``` 2559 2560### off('pause')<sup>10+</sup> 2561 2562off(type: 'pause', callback?: () => void): void 2563 2564取消会话暂停事件监听,关闭后,不再进行该事件回调。 2565 2566取消回调时,需要更新支持的命令列表。 2567 2568**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2569 2570**系统能力:** SystemCapability.Multimedia.AVSession.Core 2571 2572**参数:** 2573 2574| 参数名 | 类型 | 必填 | 说明 | 2575| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2576| type | string | 是 | 关闭对应的监听事件,支持的事件是`'pause'`。 | 2577| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2578 2579**错误码:** 2580 2581以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2582 2583| 错误码ID | 错误信息 | 2584| -------- | ---------------------------------------- | 2585| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2586| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2587| 6600102 | The session does not exist. | 2588 2589**示例:** 2590 2591```ts 2592currentAVSession.off('pause'); 2593``` 2594 2595### off('stop')<sup>10+</sup> 2596 2597off(type: 'stop', callback?: () => void): void 2598 2599取消会话停止事件监听,关闭后,不再进行该事件回调。 2600 2601取消回调时,需要更新支持的命令列表。 2602 2603**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2604 2605**系统能力:** SystemCapability.Multimedia.AVSession.Core 2606 2607**参数:** 2608 2609| 参数名 | 类型 | 必填 | 说明 | 2610| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2611| type | string | 是 | 关闭对应的监听事件,支持的事件是`'stop'`。 | 2612| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2613 2614**错误码:** 2615 2616以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2617 2618| 错误码ID | 错误信息 | 2619| -------- | ---------------------------------------- | 2620| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2621| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2622| 6600102 | The session does not exist. | 2623 2624**示例:** 2625 2626```ts 2627currentAVSession.off('stop'); 2628``` 2629 2630### off('playNext')<sup>10+</sup> 2631 2632off(type: 'playNext', callback?: () => void): void 2633 2634取消会话播放下一首事件监听,关闭后,不再进行该事件回调。 2635 2636取消回调时,需要更新支持的命令列表。 2637 2638**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2639 2640**系统能力:** SystemCapability.Multimedia.AVSession.Core 2641 2642**参数:** 2643 2644| 参数名 | 类型 | 必填 | 说明 | 2645| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2646| type | string | 是 | 关闭对应的监听事件,支持的事件是 `'playNext'`。 | 2647| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2648 2649**错误码:** 2650 2651以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2652 2653| 错误码ID | 错误信息 | 2654| -------- | ---------------------------------------- | 2655| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2656| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2657| 6600102 | The session does not exist. | 2658 2659**示例:** 2660 2661```ts 2662currentAVSession.off('playNext'); 2663``` 2664 2665### off('playPrevious')<sup>10+</sup> 2666 2667off(type: 'playPrevious', callback?: () => void): void 2668 2669取消会话播放上一首事件监听,关闭后,不再进行该事件回调。 2670 2671取消回调时,需要更新支持的命令列表。 2672 2673**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2674 2675**系统能力:** SystemCapability.Multimedia.AVSession.Core 2676 2677**参数:** 2678 2679| 参数名 | 类型 | 必填 | 说明 | 2680| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2681| type | string | 是 | 关闭对应的监听事件,支持的事件是`'playPrevious'`。 | 2682| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2683 2684**错误码:** 2685 2686以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2687 2688| 错误码ID | 错误信息 | 2689| -------- | ---------------------------------------- | 2690| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2691| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2692| 6600102 | The session does not exist. | 2693 2694**示例:** 2695 2696```ts 2697currentAVSession.off('playPrevious'); 2698``` 2699 2700### off('fastForward')<sup>10+</sup> 2701 2702off(type: 'fastForward', callback?: () => void): void 2703 2704取消会话快进事件监听,关闭后,不再进行该事件回调。 2705 2706取消回调时,需要更新支持的命令列表。 2707 2708**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2709 2710**系统能力:** SystemCapability.Multimedia.AVSession.Core 2711 2712**参数:** 2713 2714| 参数名 | 类型 | 必填 | 说明 | 2715| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2716| type | string | 是 | 关闭对应的监听事件,支持的事件是`'fastForward'`。 | 2717| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2718 2719**错误码:** 2720 2721以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2722 2723| 错误码ID | 错误信息 | 2724| -------- | ---------------------------------------- | 2725| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2726| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2727| 6600102 | The session does not exist. | 2728 2729**示例:** 2730 2731```ts 2732currentAVSession.off('fastForward'); 2733``` 2734 2735### off('rewind')<sup>10+</sup> 2736 2737off(type: 'rewind', callback?: () => void): void 2738 2739取消会话快退事件监听,关闭后,不再进行该事件回调。 2740 2741**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2742 2743**系统能力:** SystemCapability.Multimedia.AVSession.Core 2744 2745**参数:** 2746 2747| 参数名 | 类型 | 必填 | 说明 | 2748| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2749| type | string | 是 | 关闭对应的监听事件,支持的事件是`'rewind'`。 | 2750| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2751 2752**错误码:** 2753 2754以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2755 2756| 错误码ID | 错误信息 | 2757| -------- | ---------------------------------------- | 2758| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2759| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2760| 6600102 | The session does not exist. | 2761 2762**示例:** 2763 2764```ts 2765currentAVSession.off('rewind'); 2766``` 2767 2768### off('seek')<sup>10+</sup> 2769 2770off(type: 'seek', callback?: (time: number) => void): void 2771 2772取消监听跳转节点事件。 2773 2774**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2775 2776**系统能力:** SystemCapability.Multimedia.AVSession.Core 2777 2778**参数:** 2779 2780| 参数名 | 类型 | 必填 | 说明 | 2781| -------- | ---------------------- | ---- | ----------------------------------------- | 2782| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'seek'`。 | 2783| callback | (time: number) => void | 否 | 回调函数,参数time是时间节点,单位为毫秒。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2784 2785**错误码:** 2786 2787以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2788 2789| 错误码ID | 错误信息 | 2790| -------- | ---------------------------------------- | 2791| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2792| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2793| 6600102 | The session does not exist. | 2794 2795**示例:** 2796 2797```ts 2798currentAVSession.off('seek'); 2799``` 2800 2801### off('setSpeed')<sup>10+</sup> 2802 2803off(type: 'setSpeed', callback?: (speed: number) => void): void 2804 2805取消监听播放速率变化事件。 2806 2807**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2808 2809**系统能力:** SystemCapability.Multimedia.AVSession.Core 2810 2811**参数:** 2812 2813| 参数名 | 类型 | 必填 | 说明 | 2814| -------- | ----------------------- | ---- | -------------------------------------------| 2815| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'setSpeed'`。 | 2816| callback | (speed: number) => void | 否 | 回调函数,参数speed是播放倍速。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2817 2818**错误码:** 2819 2820以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2821 2822| 错误码ID | 错误信息 | 2823| -------- | ---------------------------------------- | 2824| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2825| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2826| 6600102 | The session does not exist. | 2827 2828**示例:** 2829 2830```ts 2831currentAVSession.off('setSpeed'); 2832``` 2833 2834### off('setLoopMode')<sup>10+</sup> 2835 2836off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void 2837 2838取消监听循环模式变化事件。 2839 2840**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2841 2842**系统能力:** SystemCapability.Multimedia.AVSession.Core 2843 2844**参数:** 2845 2846| 参数名 | 类型 | 必填 | 说明 | 2847| -------- | ------------------------------------- | ---- | ----- | 2848| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'setLoopMode'`。| 2849| callback | (mode: [LoopMode](#loopmode10)) => void | 否 | 回调函数,参数mode是循环模式。<br>- 当监听事件取消成功,err为undefined,否则返回错误对象。<br>- 该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2850 2851**错误码:** 2852 2853以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2854 2855| 错误码ID | 错误信息 | 2856| -------- | ---------------------------------------- | 2857| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2858| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2859| 6600102 | The session does not exist. | 2860 2861**示例:** 2862 2863```ts 2864currentAVSession.off('setLoopMode'); 2865``` 2866 2867### off('setTargetLoopMode')<sup>18+</sup> 2868 2869off(type: 'setTargetLoopMode', callback?: Callback\<LoopMode>): void 2870 2871取消监听目标循环模式变化事件。 2872 2873**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 2874 2875**系统能力:** SystemCapability.Multimedia.AVSession.Core 2876 2877**参数:** 2878 2879| 参数名 | 类型 | 必填 | 说明 | 2880| -------- | ------------------------------------- | ---- | ----- | 2881| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'setTargetLoopMode'`。| 2882| callback | Callback<[LoopMode](#loopmode10)> | 否 | 回调函数,参数表示目标循环模式。<br>- 当监听事件取消成功,err为undefined,否则返回错误对象。<br>- 该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2883 2884**错误码:** 2885 2886以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。 2887 2888| 错误码ID | 错误信息 | 2889| -------- | ---------------------------------------- | 2890| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2891| 6600102 | The session does not exist. | 2892 2893**示例:** 2894 2895```ts 2896currentAVSession.off('setTargetLoopMode'); 2897``` 2898 2899### off('toggleFavorite')<sup>10+</sup> 2900 2901off(type: 'toggleFavorite', callback?: (assetId: string) => void): void 2902 2903取消监听是否收藏的事件 2904 2905**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2906 2907**系统能力:** SystemCapability.Multimedia.AVSession.Core 2908 2909**参数:** 2910 2911| 参数名 | 类型 | 必填 | 说明 | 2912| -------- | ------------------------- | ---- | -------------------------------------------------------- | 2913| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'toggleFavorite'`。 | 2914| callback | (assetId: string) => void | 否 | 回调函数,参数assetId是媒体ID。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2915 2916**错误码:** 2917 2918以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2919 2920| 错误码ID | 错误信息 | 2921| -------- | ---------------------------------------- | 2922| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2923| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2924| 6600102 | The session does not exist. | 2925 2926**示例:** 2927 2928```ts 2929currentAVSession.off('toggleFavorite'); 2930``` 2931 2932### off('skipToQueueItem')<sup>10+</sup> 2933 2934off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void 2935 2936取消监听播放列表单项选中的事件 2937 2938**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2939 2940**系统能力:** SystemCapability.Multimedia.AVSession.Core 2941 2942**参数:** 2943 2944| 参数名 | 类型 | 必填 | 说明 | 2945| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | 2946| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'skipToQueueItem'`。 | 2947| callback | (itemId: number) => void | 否 | 回调函数,参数itemId是播放列表单项ID。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2948 2949**错误码:** 2950 2951以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2952 2953| 错误码ID | 错误信息 | 2954| -------- | ---------------------------------------- | 2955| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2956| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2957| 6600102 | The session does not exist. | 2958 2959**示例:** 2960 2961```ts 2962currentAVSession.off('skipToQueueItem'); 2963``` 2964 2965### off('handleKeyEvent')<sup>10+</sup> 2966 2967off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void 2968 2969取消监听按键事件。 2970 2971**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2972 2973**系统能力:** SystemCapability.Multimedia.AVSession.Core 2974 2975**参数:** 2976 2977| 参数名 | 类型 | 必填 | 说明 | 2978| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2979| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'handleKeyEvent'`。 | 2980| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | 否 | 回调函数,参数event是按键事件。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2981 2982**错误码:** 2983 2984以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2985 2986| 错误码ID | 错误信息 | 2987| -------- | ---------------------------------------- | 2988| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2989| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2990| 6600102 | The session does not exist. | 2991 2992**示例:** 2993 2994```ts 2995currentAVSession.off('handleKeyEvent'); 2996``` 2997 2998### off('outputDeviceChange')<sup>10+</sup> 2999 3000off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 3001 3002取消监听播放设备变化的事件。 3003 3004**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3005 3006**系统能力:** SystemCapability.Multimedia.AVSession.Core 3007 3008**参数:** 3009 3010| 参数名 | 类型 | 必填 | 说明 | 3011| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 3012| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'outputDeviceChange'`。 | 3013| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否 | 回调函数,参数device是设备相关信息。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 3014 3015**错误码:** 3016 3017以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3018 3019| 错误码ID | 错误信息 | 3020| -------- | ---------------------------------------- | 3021| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3022| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3023| 6600102 | The session does not exist. | 3024 3025**示例:** 3026 3027```ts 3028currentAVSession.off('outputDeviceChange'); 3029``` 3030 3031 3032### off('commonCommand')<sup>10+</sup> 3033 3034off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void 3035 3036取消监听自定义控制命令的变化。 3037 3038**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3039 3040**系统能力:** SystemCapability.Multimedia.AVSession.Core 3041 3042**参数:** 3043 3044| 参数名 | 类型 | 必填 | 说明 | 3045| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 3046| type | string | 是 | 取消对应的监听事件,支持事件`'commonCommand'`。 | 3047| callback | (command: string, args: {[key:string]: Object}) => void | 否 | 回调函数,参数command是变化的自定义控制命令名,args为自定义控制命令的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对command事件的监听。 | 3048 3049**错误码:** 3050 3051以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3052 3053| 错误码ID | 错误信息 | 3054| -------- | ---------------- | 3055| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3056| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3057| 6600102 | The session does not exist. | 3058 3059**示例:** 3060 3061```ts 3062currentAVSession.off('commonCommand'); 3063``` 3064 3065### on('answer')<sup>11+</sup> 3066 3067on(type: 'answer', callback: Callback\<void>): void 3068 3069设置通话接听的监听事件。 3070 3071**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3072 3073**系统能力:** SystemCapability.Multimedia.AVSession.Core 3074 3075**参数:** 3076 3077| 参数名 | 类型 | 必填 | 说明 | 3078| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3079| type | string | 是 | 事件回调类型,支持事件`'answer'`:当通话接听时,触发该事件。 | 3080| callback | Callback\<void> | 是 | 回调函数。 | 3081 3082**错误码:** 3083 3084以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3085 3086| 错误码ID | 错误信息 | 3087| -------- | ------------------------------ | 3088| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3089| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3090| 6600102 | The session does not exist. | 3091 3092**示例:** 3093 3094```ts 3095currentAVSession.on('answer', () => { 3096 console.info('on call answer'); 3097}); 3098``` 3099 3100### off('answer')<sup>11+</sup> 3101 3102off(type: 'answer', callback?: Callback\<void>): void 3103 3104取消通话接听事件的监听。 3105 3106**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3107 3108**系统能力:** SystemCapability.Multimedia.AVSession.Core 3109 3110**参数:** 3111 3112| 参数名 | 类型 | 必填 | 说明 | 3113| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3114| type | string | 是 | 关闭对应的监听事件,支持的事件是`'answer'`。 | 3115| callback | Callback\<void> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 3116 3117**错误码:** 3118 3119以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3120 3121| 错误码ID | 错误信息 | 3122| -------- | ---------------------------------------- | 3123| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3124| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3125| 6600102 | The session does not exist. | 3126 3127**示例:** 3128 3129```ts 3130currentAVSession.off('answer'); 3131``` 3132 3133### on('hangUp')<sup>11+</sup> 3134 3135on(type: 'hangUp', callback: Callback\<void>): void 3136 3137设置通话挂断的监听事件。 3138 3139**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3140 3141**系统能力:** SystemCapability.Multimedia.AVSession.Core 3142 3143**参数:** 3144 3145| 参数名 | 类型 | 必填 | 说明 | 3146| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3147| type | string | 是 | 事件回调类型,支持事件`'hangUp'`:当通话挂断时,触发该事件。 | 3148| callback | Callback\<void> | 是 | 回调函数。 | 3149 3150**错误码:** 3151 3152以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3153 3154| 错误码ID | 错误信息 | 3155| -------- | ------------------------------ | 3156| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3157| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3158| 6600102 | The session does not exist. | 3159 3160**示例:** 3161 3162```ts 3163currentAVSession.on('hangUp', () => { 3164 console.info('on call hangUp'); 3165}); 3166``` 3167 3168### off('hangUp')<sup>11+</sup> 3169 3170off(type: 'hangUp', callback?: Callback\<void>): void 3171 3172取消通话挂断事件的监听。 3173 3174**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3175 3176**系统能力:** SystemCapability.Multimedia.AVSession.Core 3177 3178**参数:** 3179 3180| 参数名 | 类型 | 必填 | 说明 | 3181| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3182| type | string | 是 | 关闭对应的监听事件,支持的事件是`'hangUp'`。 | 3183| callback | Callback\<void> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 3184 3185**错误码:** 3186 3187以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3188 3189| 错误码ID | 错误信息 | 3190| -------- | ---------------------------------------- | 3191| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3192| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3193| 6600102 | The session does not exist. | 3194 3195**示例:** 3196 3197```ts 3198currentAVSession.off('hangUp'); 3199``` 3200 3201### on('toggleCallMute')<sup>11+</sup> 3202 3203on(type: 'toggleCallMute', callback: Callback\<void>): void 3204 3205设置通话静音的监听事件。 3206 3207**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3208 3209**系统能力:** SystemCapability.Multimedia.AVSession.Core 3210 3211**参数:** 3212 3213| 参数名 | 类型 | 必填 | 说明 | 3214| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3215| type | string | 是 | 事件回调类型,支持事件`'toggleCallMute'`:当通话静音或解除静音时,触发该事件。 | 3216| callback | Callback\<void> | 是 | 回调函数。 | 3217 3218**错误码:** 3219 3220以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3221 3222| 错误码ID | 错误信息 | 3223| -------- | ------------------------------ | 3224| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3225| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3226| 6600102 | The session does not exist. | 3227 3228**示例:** 3229 3230```ts 3231currentAVSession.on('toggleCallMute', () => { 3232 console.info('on call toggleCallMute'); 3233}); 3234``` 3235 3236### off('toggleCallMute')<sup>11+</sup> 3237 3238off(type: 'toggleCallMute', callback?: Callback\<void>): void 3239 3240取消通话静音事件的监听。 3241 3242**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3243 3244**系统能力:** SystemCapability.Multimedia.AVSession.Core 3245 3246**参数:** 3247 3248| 参数名 | 类型 | 必填 | 说明 | 3249| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3250| type | string | 是 | 关闭对应的监听事件,支持的事件是`'toggleCallMute'`。 | 3251| callback | Callback\<void> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 3252 3253**错误码:** 3254 3255以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3256 3257| 错误码ID | 错误信息 | 3258| -------- | ---------------------------------------- | 3259| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3260| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3261| 6600102 | The session does not exist. | 3262 3263**示例:** 3264 3265```ts 3266currentAVSession.off('toggleCallMute'); 3267``` 3268 3269### on('castDisplayChange')<sup>12+</sup> 3270 3271on(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void 3272 3273设置扩展屏投播显示设备变化的监听事件。 3274 3275**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3276 3277**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3278 3279**参数:** 3280 3281| 参数名 | 类型 | 必填 | 说明 | 3282| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3283| type | string | 是 | 事件回调类型,支持事件`'castDisplayChange'`:当扩展屏投播显示设备变化时触发事件。 | 3284| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)> | 是 | 回调函数。参数是扩展屏投播显示设备信息。 | 3285 3286**错误码:** 3287 3288以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3289 3290| 错误码ID | 错误信息 | 3291| -------- | ---------------------------------------- | 3292| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3293| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3294| 6600102 | The session does not exist. | 3295 3296**示例:** 3297 3298```ts 3299let castDisplay: avSession.CastDisplayInfo; 3300currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => { 3301 if (display.state === avSession.CastDisplayState.STATE_ON) { 3302 castDisplay = display; 3303 console.info(`Succeeded in castDisplayChange display : ${display.id} ON`); 3304 } else if (display.state === avSession.CastDisplayState.STATE_OFF){ 3305 console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`); 3306 } 3307}); 3308``` 3309### off('castDisplayChange')<sup>12+</sup> 3310 3311 off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void 3312 3313取消扩展屏投播显示设备变化事件监听,关闭后,不再进行该事件回调。 3314 3315**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3316 3317**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3318 3319**参数:** 3320 3321| 参数名 | 类型 | 必填 | 说明 | 3322| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3323| type | string | 是 | 关闭对应的监听事件,支持的事件是`'castDisplayChange'`。 | 3324| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 3325 3326**错误码:** 3327 3328以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3329 3330| 错误码ID | 错误信息 | 3331| -------- | ---------------------------------------- | 3332| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3333| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3334| 6600102 | The session does not exist. | 3335 3336**示例:** 3337 3338```ts 3339currentAVSession.off('castDisplayChange'); 3340``` 3341 3342### stopCasting<sup>10+</sup> 3343 3344stopCasting(callback: AsyncCallback\<void>): void 3345 3346结束投播。结果通过callback异步回调方式返回。 3347 3348**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3349 3350**参数:** 3351 3352| 参数名 | 类型 | 必填 | 说明 | 3353| -------- | ------------------------------------- | ---- | ------------------------------------- | 3354| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3355 3356**错误码:** 3357 3358以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3359 3360| 错误码ID | 错误信息 | 3361| -------- | ---------------------------------------- | 3362| 6600109 | The remote connection is not established. | 3363 3364**示例:** 3365 3366```ts 3367import { BusinessError } from '@kit.BasicServicesKit'; 3368 3369currentAVSession.stopCasting((err: BusinessError) => { 3370 if (err) { 3371 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3372 } else { 3373 console.info('stopCasting successfully'); 3374 } 3375}); 3376``` 3377 3378### stopCasting<sup>10+</sup> 3379 3380stopCasting(): Promise\<void> 3381 3382结束投播。结果通过Promise异步回调方式返回。 3383 3384**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3385 3386**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3387 3388**返回值:** 3389 3390| 类型 | 说明 | 3391| -------------- | ----------------------------- | 3392| Promise\<void> | Promise对象。当成功结束投播,无返回结果,否则返回错误对象。 | 3393 3394**错误码:** 3395 3396以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3397 3398| 错误码ID | 错误信息 | 3399| -------- | ---------------------------------------- | 3400| 6600109 | The remote connection is not established. | 3401 3402**示例:** 3403 3404```ts 3405import { BusinessError } from '@kit.BasicServicesKit'; 3406 3407currentAVSession.stopCasting().then(() => { 3408 console.info('stopCasting successfully'); 3409}).catch((err: BusinessError) => { 3410 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3411}); 3412``` 3413 3414### getOutputDeviceSync<sup>10+</sup> 3415 3416getOutputDeviceSync(): OutputDeviceInfo 3417 3418使用同步方法获取当前输出设备信息。 3419 3420**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3421 3422**系统能力:** SystemCapability.Multimedia.AVSession.Core 3423 3424**返回值:** 3425 3426| 类型 | 说明 | 3427| ----------------------------------------------- | --------------------------------- | 3428| [OutputDeviceInfo](#outputdeviceinfo10) | 当前输出设备信息。 | 3429 3430**错误码:** 3431 3432以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3433 3434| 错误码ID | 错误信息 | 3435|---------| --------------------------------------- | 3436| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3437| 6600102 | The session does not exist. | 3438 3439**示例:** 3440 3441```ts 3442import { BusinessError } from '@kit.BasicServicesKit'; 3443 3444try { 3445 let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync(); 3446} catch (err) { 3447 let error = err as BusinessError; 3448 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 3449} 3450``` 3451### getAllCastDisplays<sup>12+</sup> 3452 3453getAllCastDisplays(): Promise<Array\<CastDisplayInfo>> 3454 3455获取当前系统中所有支持扩展屏投播的显示设备。通过Promise异步回调方式返回。 3456 3457**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3458 3459**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3460 3461**返回值:** 3462 3463| 类型 | 说明 | 3464| ----------------------------------------------- | --------------------------------- | 3465| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise对象,返回当前系统中所有支持扩展屏投播的显示设备。 | 3466 3467**错误码:** 3468 3469以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3470 3471| 错误码ID | 错误信息 | 3472|---------| --------------------------------------- | 3473| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3474| 6600102 | The session does not exist. | 3475 3476**示例:** 3477 3478```ts 3479import { BusinessError } from '@kit.BasicServicesKit'; 3480 3481let castDisplay: avSession.CastDisplayInfo; 3482currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => { 3483 if (data.length >= 1) { 3484 castDisplay = data[0]; 3485 } 3486 }).catch((err: BusinessError) => { 3487 console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`); 3488 }); 3489``` 3490 3491## AVCastControlCommandType<sup>10+</sup> 3492 3493type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 3494 'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute' 3495 3496投播控制器可传递的命令。 3497 3498**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3499 3500**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3501 3502| 类型 | 说明 | 3503| ---------------- | ------------ | 3504| 'play' | 播放。无需传入参数。 | 3505| 'pause' | 暂停。无需传入参数。 | 3506| 'stop' | 停止。无需传入参数。 | 3507| 'playNext' | 下一首。无需传入参数。 | 3508| 'playPrevious' | 上一首。无需传入参数。 | 3509| 'fastForward' | 快进。无需传入参数。 | 3510| 'rewind' | 快退。无需传入参数。 | 3511| 'seek' | 跳转某一节点。对应参数使用number类型。 | 3512| 'setVolume' | 设置音量。对应参数使用number类型, 可通过[AVPlaybackState.maxVolume](#avplaybackstate10)获取系统最大音量 | 3513| 'setSpeed' | 设置播放倍速。对应参数使用[media.PlaybackSpeed](../apis-media-kit/arkts-apis-media-e.md#playbackspeed8)。 | 3514| 'setLoopMode' | 设置循环模式。对应参数使用[LoopMode](#loopmode10)。 | 3515| 'toggleFavorite' | 是否收藏。对应参数使用[AVMetadata.assetId](#avmetadata10)。 | 3516| 'toggleMute' | 设置静音状态。无需传入参数。 | 3517 3518## AVCastControlCommand<sup>10+</sup> 3519 3520投播控制器接受的命令的对象描述。 3521 3522**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3523 3524**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3525 3526| 名称 | 类型 | 必填 | 说明 | 3527| --------- | ------------------------------------------------- | ---- | -------------- | 3528| command | [AVCastControlCommandType](#avcastcontrolcommandtype10) | 是 | 命令。每种命令对应的参数不同,具体的对应关系可查阅[AVCastControlCommandType](#avcastcontrolcommandtype10)里的详细介绍。 | 3529| parameter | [media.PlaybackSpeed](../apis-media-kit/arkts-apis-media-e.md#playbackspeed8) | number | string | [LoopMode](#loopmode10) | 否 | 命令对应的参数。 | 3530 3531## AVCastController<sup>10+</sup> 3532 3533在投播建立后,调用[avSession.getAVCastController](#getavcastcontroller10)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 3534 3535### getAVPlaybackState<sup>10+</sup> 3536 3537getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 3538 3539获取当前的远端播放状态。结果通过callback异步回调方式返回。 3540 3541**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3542 3543**参数:** 3544 3545| 参数名 | 类型 | 必填 | 说明 | 3546| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3547| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | 是 | 回调函数,返回远端播放状态。 | 3548 3549**错误码:** 3550 3551以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3552 3553| 错误码ID | 错误信息 | 3554| -------- | ---------------------------------------- | 3555| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3556 3557**示例:** 3558 3559```ts 3560import { BusinessError } from '@kit.BasicServicesKit'; 3561 3562aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 3563 if (err) { 3564 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3565 } else { 3566 console.info('getAVPlaybackState : SUCCESS'); 3567 } 3568}); 3569``` 3570 3571### getAVPlaybackState<sup>10+</sup> 3572 3573getAVPlaybackState(): Promise\<AVPlaybackState> 3574 3575获取当前的远端播放状态。结果通过Promise异步回调方式返回。 3576 3577**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3578 3579**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3580 3581**返回值:** 3582 3583| 类型 | 说明 | 3584| --------- | ------------------------------------------------------------ | 3585| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise对象。返回远端播放状态。 | 3586 3587**错误码:** 3588 3589以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3590 3591| 错误码ID | 错误信息 | 3592| -------- | ---------------------------------------- | 3593| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3594 3595**示例:** 3596 3597```ts 3598import { BusinessError } from '@kit.BasicServicesKit'; 3599 3600aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 3601 console.info('getAVPlaybackState : SUCCESS'); 3602}).catch((err: BusinessError) => { 3603 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3604}); 3605``` 3606 3607### getSupportedDecoders<sup>19+</sup> 3608 3609getSupportedDecoders(): Promise\<Array\<DecoderType>> 3610 3611获取当前远端设备的解码方式。使用Promise异步回调。 3612 3613**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3614 3615**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3616 3617**返回值:** 3618 3619| 类型 | 说明 | 3620| --------- | ------------------------------------------------------------ | 3621| Promise\<Array\<[DecoderType](#decodertype19)\>\> | Promise对象。返回远端设备所支持的解码能力列表。 | 3622 3623**错误码:** 3624 3625以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3626 3627| 错误码ID | 错误信息 | 3628| -------- | ---------------------------------------- | 3629| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3630 3631**示例:** 3632 3633```ts 3634import { BusinessError } from '@kit.BasicServicesKit'; 3635 3636aVCastController.getSupportedDecoders().then((decoderTypes: avSession.DecoderType[]) => { 3637 console.info(`getSupportedDecoders : SUCCESS : decoderTypes.length : ${decoderTypes.length}`); 3638 if (decoderTypes.length > 0 ) { 3639 console.info(`getSupportedDecoders : SUCCESS : decoderTypes[0] : ${decoderTypes[0]}`); 3640 } 3641}).catch((err: BusinessError) => { 3642 console.error(`getSupportedDecoders BusinessError: code: ${err.code}, message: ${err.message}`); 3643}); 3644``` 3645 3646### getRecommendedResolutionLevel<sup>19+</sup> 3647 3648getRecommendedResolutionLevel(decoderType: DecoderType): Promise\<ResolutionLevel> 3649 3650通过传递解码方式,获取推荐的分辨率。使用Promise异步回调。 3651 3652**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3653 3654**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3655 3656**参数:** 3657| 参数名 | 类型 | 必填 | 说明 | 3658| -------- | ----------------------------------------- | ---- | -------------------------- | 3659| decoderType | [DecoderType](#decodertype19) | 是 | 设备所支持的解码格式。<br>设备所支持的解码格式包括:<br>'OH_AVCODEC_MIMETYPE_VIDEO_AVC':VIDEO AVC,<br>'OH_AVCODEC_MIMETYPE_VIDEO_HEVC':VIDEO HEVC,<br>'OH_AVCODEC_MIMETYPE_AUDIO_VIVID':AUDIO AV3A。 | 3660 3661**返回值:** 3662 3663| 类型 | 说明 | 3664| --------- | ------------------------------------------------------------ | 3665| Promise\<[ResolutionLevel](#resolutionlevel19)\> | Promise对象。返回远端设备推荐的分辨率。 | 3666 3667**错误码:** 3668 3669以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3670 3671| 错误码ID | 错误信息 | 3672| -------- | ---------------------------------------- | 3673| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3674 3675**示例:** 3676 3677```ts 3678import { BusinessError } from '@kit.BasicServicesKit'; 3679 3680let decoderType = avSession.DecoderType.OH_AVCODEC_MIMETYPE_VIDEO_AVC; 3681let resolutionLeve = avSession.ResolutionLevel; 3682aVCastController.getRecommendedResolutionLevel(decoderType).then((resolutionLeve) => { 3683 console.info('getRecommendedResolutionLevel successfully'); 3684}).catch((err: BusinessError) => { 3685 console.error(`getRecommendedResolutionLevel BusinessError: code: ${err.code}, message: ${err.message}`); 3686}); 3687``` 3688 3689### getSupportedHdrCapabilities<sup>19+</sup> 3690 3691getSupportedHdrCapabilities(): Promise\<Array\<hdrCapability.HDRFormat>> 3692 3693获取当前的远端设备所支持的HDR能力。使用Promise异步回调。 3694 3695**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3696 3697**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3698 3699**返回值:** 3700 3701| 类型 | 说明 | 3702| --------- | ------------------------------------------------------------ | 3703| Promise\<Array\<[hdrCapability.HDRFormat](../apis-arkgraphics2d/js-apis-hdrCapability.md#hdrformat)\>\> | Promise对象。返回远端设备所支持的HDR能力。 | 3704 3705**错误码:** 3706 3707以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3708 3709| 错误码ID | 错误信息 | 3710| -------- | ---------------------------------------- | 3711| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3712 3713**示例:** 3714 3715```ts 3716import { BusinessError } from '@kit.BasicServicesKit'; 3717import type hdrCapability from './@ohos.graphics.hdrCapability'; 3718 3719aVCastController.getSupportedHdrCapabilities().then((hdrFormats: hdrCapability.HDRFormat[]) => { 3720 console.info(`getSupportedHdrCapabilities : SUCCESS : hdrFormats.length : ${hdrFormats.length}`); 3721 if (hdrFormats.length > 0 ) { 3722 console.info(`getSupportedHdrCapabilities : SUCCESS : descriptors[0] : ${hdrFormats[0]}`); 3723 } 3724}).catch((err: BusinessError) => { 3725 console.error(`getSupportedHdrCapabilities BusinessError: code: ${err.code}, message: ${err.message}`); 3726}); 3727``` 3728 3729### getSupportedPlaySpeeds<sup>19+</sup> 3730 3731getSupportedPlaySpeeds(): Promise\<Array\<number>> 3732 3733获取当前的远端设备所支持倍速播放列表。使用Promise异步回调。 3734 3735**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 3736 3737**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3738 3739**返回值:** 3740 3741| 类型 | 说明 | 3742| --------- | ------------------------------------------------------------ | 3743| Promise\<Array\<number\>\> | Promise对象。返回远端设备所支持的倍速播放列表。 | 3744 3745**错误码:** 3746 3747以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3748 3749| 错误码ID | 错误信息 | 3750| -------- | ---------------------------------------- | 3751| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3752 3753**示例:** 3754 3755```ts 3756import { BusinessError } from '@kit.BasicServicesKit'; 3757 3758aVCastController.getSupportedPlaySpeeds().then((nums: number[]) => { 3759 console.info(`getSupportedPlaySpeeds : SUCCESS : hdrFormats.length : ${nums.length}`); 3760 if (nums.length > 0 ) { 3761 console.info(`getSupportedPlaySpeeds : SUCCESS : descriptors[0] : ${nums[0]}`); 3762 } 3763}).catch((err: BusinessError) => { 3764 console.error(`getSupportedPlaySpeeds BusinessError: code: ${err.code}, message: ${err.message}`); 3765}); 3766``` 3767 3768### sendControlCommand<sup>10+</sup> 3769 3770sendControlCommand(command: AVCastControlCommand): Promise\<void> 3771 3772通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 3773 3774 3775**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3776 3777**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3778 3779**参数:** 3780 3781| 参数名 | 类型 | 必填 | 说明 | 3782| ------- | ------------------------------------- | ---- | ------------------------------ | 3783| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 3784 3785**返回值:** 3786 3787| 类型 | 说明 | 3788| -------------- | ----------------------------- | 3789| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 3790 3791**错误码:** 3792 3793以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3794 3795| 错误码ID | 错误信息 | 3796| -------- | ---------------------------------------- | 3797| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3798| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3799| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 3800| 6600109 | The remote connection is not established. | 3801 3802**示例:** 3803 3804```ts 3805import { BusinessError } from '@kit.BasicServicesKit'; 3806 3807let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3808aVCastController.sendControlCommand(avCommand).then(() => { 3809 console.info('SendControlCommand successfully'); 3810}).catch((err: BusinessError) => { 3811 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3812}); 3813``` 3814 3815### sendControlCommand<sup>10+</sup> 3816 3817sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void 3818 3819通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 3820 3821 3822**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3823 3824**参数:** 3825 3826| 参数名 | 类型 | 必填 | 说明 | 3827| -------- | ------------------------------------- | ---- | ------------------------------ | 3828| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 3829| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3830 3831**错误码:** 3832 3833以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3834 3835| 错误码ID | 错误信息 | 3836| -------- | ------------------------------- | 3837| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3838| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3839| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 3840| 6600109 | The remote connection is not established. | 3841 3842**示例:** 3843 3844```ts 3845import { BusinessError } from '@kit.BasicServicesKit'; 3846 3847let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3848aVCastController.sendControlCommand(avCommand, (err: BusinessError) => { 3849 if (err) { 3850 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3851 } else { 3852 console.info('SendControlCommand successfully'); 3853 } 3854}); 3855``` 3856 3857### prepare<sup>10+</sup> 3858 3859prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void 3860 3861准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过callback异步回调方式返回。 3862 3863**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3864 3865**参数:** 3866 3867| 参数名 | 类型 | 必填 | 说明 | 3868| ------- | ------------------------------------- | ---- | ------------------------------ | 3869| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 3870| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3871 3872**错误码:** 3873 3874以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3875 3876| 错误码ID | 错误信息 | 3877| -------- | ---------------------------------------- | 3878| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3879| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3880| 6600109 | The remote connection is not established. | 3881 3882**示例:** 3883 3884```ts 3885import { BusinessError } from '@kit.BasicServicesKit'; 3886 3887// 设置播放参数,开始播放。 3888let playItem: avSession.AVQueueItem = { 3889 itemId: 0, 3890 description: { 3891 assetId: '12345', 3892 mediaType: 'AUDIO', 3893 mediaUri: 'http://resource1_address', 3894 mediaSize: 12345, 3895 startPosition: 0, 3896 duration: 0, 3897 artist: 'mysong', 3898 albumTitle: 'song1_title', 3899 albumCoverUri: "http://resource1_album_address", 3900 lyricUri: "http://resource1_lyric_address", 3901 appName: 'MyMusic' 3902 } 3903}; 3904// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。 3905aVCastController.prepare(playItem, (err: BusinessError) => { 3906 if (err) { 3907 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3908 } else { 3909 console.info('prepare successfully'); 3910 } 3911}); 3912``` 3913 3914 3915### prepare<sup>10+</sup> 3916 3917prepare(item: AVQueueItem): Promise\<void> 3918 3919准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过Promise异步回调方式返回。 3920 3921 3922**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3923 3924**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3925 3926**参数:** 3927 3928| 参数名 | 类型 | 必填 | 说明 | 3929| ------- | ------------------------------------- | ---- | ------------------------------ | 3930| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 3931 3932**返回值:** 3933 3934| 类型 | 说明 | 3935| -------------- | ----------------------------- | 3936| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 3937 3938**错误码:** 3939 3940以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3941 3942| 错误码ID | 错误信息 | 3943| -------- | ---------------------------------------- | 3944| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3945| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3946| 6600109 | The remote connection is not established. | 3947 3948 3949**示例:** 3950 3951```ts 3952import { BusinessError } from '@kit.BasicServicesKit'; 3953 3954// 设置播放参数,开始播放。 3955let playItem: avSession.AVQueueItem = { 3956 itemId: 0, 3957 description: { 3958 assetId: '12345', 3959 mediaType: 'AUDIO', 3960 mediaUri: 'http://resource1_address', 3961 mediaSize: 12345, 3962 startPosition: 0, 3963 duration: 0, 3964 artist: 'mysong', 3965 albumTitle: 'song1_title', 3966 albumCoverUri: "http://resource1_album_address", 3967 lyricUri: "http://resource1_lyric_address", 3968 appName: 'MyMusic' 3969 } 3970}; 3971// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。 3972aVCastController.prepare(playItem).then(() => { 3973 console.info('prepare successfully'); 3974}).catch((err: BusinessError) => { 3975 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3976}); 3977``` 3978 3979### start<sup>10+</sup> 3980 3981start(item: AVQueueItem, callback: AsyncCallback\<void>): void 3982 3983启动播放某个媒体资源。结果通过callback异步回调方式返回。 3984 3985**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3986 3987**参数:** 3988 3989| 参数名 | 类型 | 必填 | 说明 | 3990| ------- | ------------------------------------- | ---- | ------------------------------ | 3991| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 3992| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3993 3994**错误码:** 3995 3996以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3997 3998| 错误码ID | 错误信息 | 3999| -------- | ---------------------------------------- | 4000| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 4001| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4002| 6600109 | The remote connection is not established. | 4003 4004**示例:** 4005 4006```ts 4007import { BusinessError } from '@kit.BasicServicesKit'; 4008 4009// 设置播放参数,开始播放。 4010let playItem: avSession.AVQueueItem = { 4011 itemId: 0, 4012 description: { 4013 assetId: '12345', 4014 mediaType: 'AUDIO', 4015 mediaUri: 'http://resource1_address', 4016 mediaSize: 12345, 4017 startPosition: 0, 4018 duration: 0, 4019 artist: 'mysong', 4020 albumTitle: 'song1_title', 4021 albumCoverUri: "http://resource1_album_address", 4022 lyricUri: "http://resource1_lyric_address", 4023 appName: 'MyMusic' 4024 } 4025}; 4026 4027// 启动播放。 4028aVCastController.start(playItem, (err: BusinessError) => { 4029 if (err) { 4030 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 4031 } else { 4032 console.info('start successfully'); 4033 } 4034}); 4035``` 4036 4037### start<sup>10+</sup> 4038 4039start(item: AVQueueItem): Promise\<void> 4040 4041启动播放某个媒体资源。结果通过Promise异步回调方式返回。 4042 4043 4044**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4045 4046**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4047 4048**参数:** 4049 4050| 参数名 | 类型 | 必填 | 说明 | 4051| ------- | ------------------------------------- | ---- | ------------------------------ | 4052| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 4053 4054**返回值:** 4055 4056| 类型 | 说明 | 4057| -------------- | ----------------------------- | 4058| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 4059 4060**错误码:** 4061 4062以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4063 4064| 错误码ID | 错误信息 | 4065| -------- | ---------------------------------------- | 4066| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 4067| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4068| 6600109 | The remote connection is not established. | 4069 4070 4071**示例:** 4072 4073```ts 4074import { BusinessError } from '@kit.BasicServicesKit'; 4075 4076// 设置播放参数,开始播放。 4077let playItem: avSession.AVQueueItem = { 4078 itemId: 0, 4079 description: { 4080 assetId: '12345', 4081 mediaType: 'AUDIO', 4082 mediaUri: 'http://resource1_address', 4083 mediaSize: 12345, 4084 startPosition: 0, 4085 duration: 0, 4086 artist: 'mysong', 4087 albumTitle: 'song1_title', 4088 albumCoverUri: "http://resource1_album_address", 4089 lyricUri: "http://resource1_lyric_address", 4090 appName: 'MyMusic' 4091 } 4092}; 4093// 启动播放。 4094aVCastController.start(playItem).then(() => { 4095 console.info('start successfully'); 4096}).catch((err: BusinessError) => { 4097 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 4098}); 4099``` 4100 4101### getCurrentItem<sup>10+</sup> 4102 4103getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void 4104 4105获取当前投播的资源信息。结果通过callback异步回调方式返回。 4106 4107**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4108 4109**参数:** 4110 4111| 参数名 | 类型 | 必填 | 说明 | 4112| -------- | ------------------------------------- | ---- | ------------------------------------- | 4113| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 4114 4115**错误码:** 4116 4117以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4118 4119| 错误码ID | 错误信息 | 4120| -------- | ---------------------------------------- | 4121| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4122 4123**示例:** 4124 4125```ts 4126import { BusinessError } from '@kit.BasicServicesKit'; 4127 4128aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => { 4129 if (err) { 4130 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 4131 } else { 4132 console.info('getCurrentItem successfully'); 4133 } 4134}); 4135``` 4136 4137### getCurrentItem<sup>10+</sup> 4138 4139getCurrentItem(): Promise\<AVQueueItem> 4140 4141获取当前投播的资源信息。结果通过Promise异步回调方式返回。 4142 4143**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4144 4145**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4146 4147**返回值:** 4148 4149| 类型 | 说明 | 4150| -------------- | ----------------------------- | 4151| Promise\<[AVQueueItem](#avqueueitem10)> | Promise对象,返回当前的播放资源,否则返回错误对象。 | 4152 4153**错误码:** 4154 4155以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4156 4157| 错误码ID | 错误信息 | 4158| -------- | ---------------------------------------- | 4159| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4160 4161**示例:** 4162 4163```ts 4164import { BusinessError } from '@kit.BasicServicesKit'; 4165 4166aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => { 4167 console.info('getCurrentItem successfully'); 4168}).catch((err: BusinessError) => { 4169 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 4170}); 4171``` 4172 4173### getValidCommands<sup>11+</sup> 4174 4175getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void 4176 4177获取当前支持的命令。结果通过callback异步回调方式返回。 4178 4179**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4180 4181**参数:** 4182 4183| 参数名 | 类型 | 必填 | 说明 | 4184| -------- | ------------------------------------- | ---- | ------------------------------------- | 4185| callback | AsyncCallback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | 是 | 回调函数。返回当前支持的命令。 | 4186 4187**错误码:** 4188 4189以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4190 4191| 错误码ID | 错误信息 | 4192| -------- | ---------------------------------------- | 4193| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4194 4195**示例:** 4196 4197```ts 4198import { BusinessError } from '@kit.BasicServicesKit'; 4199 4200aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType[]) => { 4201 if (err) { 4202 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 4203 } else { 4204 console.info('getValidCommands successfully'); 4205 } 4206}); 4207``` 4208 4209### getValidCommands<sup>11+</sup> 4210 4211getValidCommands(): Promise<Array\<AVCastControlCommandType>> 4212 4213获取当前支持的命令。结果通过Promise异步回调方式返回。 4214 4215**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4216 4217**返回值:** 4218 4219| 类型 | 说明 | 4220| -------------- | ----------------------------- | 4221| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise对象,返回当前支持的命令。 | 4222 4223**错误码:** 4224 4225以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4226 4227| 错误码ID | 错误信息 | 4228| -------- | ---------------------------------------- | 4229| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4230 4231**示例:** 4232 4233```ts 4234import { BusinessError } from '@kit.BasicServicesKit'; 4235 4236aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType[]) => { 4237 console.info('getValidCommands successfully'); 4238}).catch((err: BusinessError) => { 4239 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 4240}); 4241``` 4242 4243### processMediaKeyResponse<sup>12+</sup> 4244 4245processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void> 4246 4247在线DRM资源投播时,处理许可证响应。结果通过Promise异步回调方式返回。 4248 4249**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4250 4251**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4252 4253**参数:** 4254 4255| 参数名 | 类型 | 必填 | 说明 | 4256| -------- | ------------------------------------- | ---- | ------------------------------------- | 4257| assetId | string | 是 | 媒体ID。 | 4258| response | Uint8Array | 是 | 许可证响应。 | 4259 4260**返回值:** 4261 4262| 类型 | 说明 | 4263| -------------- | ----------------------------- | 4264| Promise\<void> | Promise对象,当处理许可证响应成功,无返回结果,否则返回错误对象。 | 4265 4266**错误码:** 4267 4268以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4269 4270| 错误码ID | 错误信息 | 4271| -------- | ---------------------------------------- | 4272| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 4273| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4274 4275**示例:** 4276 4277```ts 4278let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 4279 // 根据assetId获取对应的DRM url。 4280 let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense'; 4281 // 从服务器获取许可证,需要开发者根据实际情况进行赋值。 4282 let licenseResponseData: Uint8Array = new Uint8Array(); 4283 console.info(`Succeeded in get license by ${drmUrl}.`); 4284 aVCastController.processMediaKeyResponse(assetId, licenseResponseData); 4285} 4286``` 4287 4288### release<sup>11+</sup> 4289 4290release(callback: AsyncCallback\<void>): void 4291 4292销毁当前controller,结果通过callback异步回调方式返回。 4293 4294**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4295 4296**参数:** 4297 4298| 参数名 | 类型 | 必填 | 说明 | 4299| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 4300| callback | AsyncCallback\<void> | 是 | 回调函数。当命令执行成功,err为undefined,否则返回错误对象。 | 4301 4302**错误码:** 4303 4304以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4305 4306| 错误码ID | 错误信息 | 4307| -------- | -------------------------- | 4308| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4309 4310**示例:** 4311 4312```ts 4313import { BusinessError } from '@kit.BasicServicesKit'; 4314 4315aVCastController.release((err: BusinessError) => { 4316 if (err) { 4317 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 4318 } else { 4319 console.info('release successfully'); 4320 } 4321}); 4322``` 4323 4324### release<sup>11+</sup> 4325 4326release(): Promise\<void> 4327 4328销毁当前controller。结果通过Promise异步回调方式返回。 4329 4330**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4331 4332**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4333 4334**返回值:** 4335 4336| 类型 | 说明 | 4337| -------------- | ----------------------------- | 4338| Promise\<void> | Promise对象,controller销毁成功,无结果返回,否则返回错误对象。 | 4339 4340**错误码:** 4341 4342以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4343 4344| 错误码ID | 错误信息 | 4345| -------- | ------------------------------ | 4346| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4347 4348**示例:** 4349 4350```ts 4351import { BusinessError } from '@kit.BasicServicesKit'; 4352 4353aVCastController.release().then(() => { 4354 console.info('release successfully'); 4355}).catch((err: BusinessError) => { 4356 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 4357}); 4358 4359``` 4360 4361### on('playbackStateChange')<sup>10+</sup> 4362 4363on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void 4364 4365设置播放状态变化的监听事件。 4366 4367**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4368 4369**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4370 4371**参数:** 4372 4373| 参数名 | 类型 | 必填 | 说明 | 4374| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4375| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | 4376| filter | Array\<keyof [AVPlaybackState](#avplaybackstate10)\> | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array<keyof [AVPlaybackState](#avplaybackstate10)\> 表示关注Array中的字段变化。 | 4377| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。 | 4378 4379**错误码:** 4380 4381以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4382 4383| 错误码ID | 错误信息 | 4384| -------- | ------------------------------ | 4385| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4386| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4387 4388**示例:** 4389 4390```ts 4391aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 4392 console.info(`on playbackStateChange state : ${playbackState.state}`); 4393}); 4394 4395let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode']; 4396aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => { 4397 console.info(`on playbackStateChange state : ${playbackState.state}`); 4398}); 4399``` 4400 4401### off('playbackStateChange')<sup>10+</sup> 4402 4403off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void 4404 4405媒体控制器取消监听播放状态变化的事件。 4406 4407**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4408 4409**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4410 4411**参数:** 4412 4413| 参数名 | 类型 | 必填 | 说明 | 4414| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4415| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | 4416| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4417 4418**错误码:** 4419 4420以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4421 4422| 错误码ID | 错误信息 | 4423| -------- | ---------------- | 4424| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4425| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4426 4427**示例:** 4428 4429```ts 4430aVCastController.off('playbackStateChange'); 4431``` 4432 4433### on('mediaItemChange')<sup>10+</sup> 4434 4435on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void 4436 4437设置投播当前播放媒体内容的监听事件。 4438 4439**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4440 4441**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4442 4443**参数:** 4444 4445| 参数名 | 类型 | 必填 | 说明 | 4446| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4447| type | string | 是 | 事件回调类型,支持事件`'mediaItemChange'`:当播放的媒体内容变化时,触发该事件。 | 4448| callback | Callback<[AVQueueItem](#avqueueitem10)> | 是 | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。 | 4449 4450**错误码:** 4451 4452以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4453 4454| 错误码ID | 错误信息 | 4455| -------- | ------------------------------ | 4456| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4457| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4458 4459**示例:** 4460 4461```ts 4462aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => { 4463 console.info(`on mediaItemChange state : ${item.itemId}`); 4464}); 4465``` 4466 4467### off('mediaItemChange')<sup>10+</sup> 4468 4469off(type: 'mediaItemChange'): void 4470 4471取消设置投播当前播放媒体内容的监听事件。 4472 4473**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4474 4475**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4476 4477**参数:** 4478 4479| 参数名 | 类型 | 必填 | 说明 | 4480| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4481| type | string | 是 | 取消对应的监听事件,支持事件`'mediaItemChange'`。 | 4482 4483**错误码:** 4484 4485以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4486 4487| 错误码ID | 错误信息 | 4488| -------- | ---------------- | 4489| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4490| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4491 4492**示例:** 4493 4494```ts 4495aVCastController.off('mediaItemChange'); 4496``` 4497 4498### on('playNext')<sup>10+</sup> 4499 4500on(type: 'playNext', callback: Callback\<void>): void 4501 4502设置播放下一首资源的监听事件。 4503 4504**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4505 4506**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4507 4508**参数:** 4509 4510| 参数名 | 类型 | 必填 | 说明 | 4511| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4512| type | string | 是 | 事件回调类型,支持事件`'playNext'`:当播放下一首状态变化时,触发该事件。 | 4513| callback | Callback\<void\> | 是 | 回调函数。 | 4514 4515**错误码:** 4516 4517以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4518 4519| 错误码ID | 错误信息 | 4520| -------- | ------------------------------ | 4521| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4522| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4523 4524**示例:** 4525 4526```ts 4527aVCastController.on('playNext', () => { 4528 console.info('on playNext'); 4529}); 4530``` 4531 4532### off('playNext')<sup>10+</sup> 4533 4534off(type: 'playNext'): void 4535 4536取消设置播放下一首资源的监听事件。 4537 4538**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4539 4540**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4541 4542**参数:** 4543 4544| 参数名 | 类型 | 必填 | 说明 | 4545| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4546| type | string | 是 | 取消对应的监听事件,支持事件`'playNext'`。 | 4547 4548**错误码:** 4549 4550以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4551 4552| 错误码ID | 错误信息 | 4553| -------- | ---------------- | 4554| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4555| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4556 4557**示例:** 4558 4559```ts 4560aVCastController.off('playNext'); 4561``` 4562 4563### on('playPrevious')<sup>10+</sup> 4564 4565on(type: 'playPrevious', callback: Callback\<void>): void 4566 4567设置播放上一首资源的监听事件。 4568 4569**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4570 4571**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4572 4573**参数:** 4574 4575| 参数名 | 类型 | 必填 | 说明 | 4576| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4577| type | string | 是 | 事件回调类型,支持事件`'playPrevious'`:当播放上一首状态变化时,触发该事件。 | 4578| callback | Callback\<void\> | 是 | 回调函数。 | 4579 4580**错误码:** 4581 4582以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4583 4584| 错误码ID | 错误信息 | 4585| -------- | ------------------------------ | 4586| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4587| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4588 4589**示例:** 4590 4591```ts 4592aVCastController.on('playPrevious', () => { 4593 console.info('on playPrevious'); 4594}); 4595``` 4596 4597### off('playPrevious')<sup>10+</sup> 4598 4599off(type: 'playPrevious'): void 4600 4601取消设置播放上一首资源的监听事件。 4602 4603**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4604 4605**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4606 4607**参数:** 4608 4609| 参数名 | 类型 | 必填 | 说明 | 4610| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4611| type | string | 是 | 取消对应的监听事件,支持事件`'playPrevious'`。 | 4612 4613**错误码:** 4614 4615以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4616 4617| 错误码ID | 错误信息 | 4618| -------- | ---------------- | 4619| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4620| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4621 4622**示例:** 4623 4624```ts 4625aVCastController.off('playPrevious'); 4626``` 4627 4628### on('requestPlay')<sup>11+</sup> 4629 4630on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void 4631 4632设置请求播放的监听事件。 4633 4634**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4635 4636**参数:** 4637 4638| 参数名 | 类型 | 必填 | 说明 | 4639| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4640| type | string | 是 | 事件回调类型,支持事件`'requestPlay'`:当请求播放状态变化时,触发该事件。 | 4641| callback | Callback\<[AVQueueItem](#avqueueitem10)> | 是 | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件注册成功,err为undefined,否则返回错误对象。 | 4642 4643**错误码:** 4644 4645以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4646 4647| 错误码ID | 错误信息 | 4648| -------- | ------------------------------ | 4649| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4650| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4651 4652**示例:** 4653 4654```ts 4655aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => { 4656 console.info(`on requestPlay state : ${item.itemId}`); 4657}); 4658``` 4659 4660### off('requestPlay')<sup>11+</sup> 4661 4662off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void 4663 4664取消设置请求播放的监听事件。 4665 4666**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4667 4668**参数:** 4669 4670| 参数名 | 类型 | 必填 | 说明 | 4671| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4672| type | string | 是 | 取消对应的监听事件,支持事件`'requestPlay'`。 | 4673| callback | Callback\<[AVQueueItem](#avqueueitem10)> | 否 | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。| 4674 4675**错误码:** 4676 4677以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4678 4679| 错误码ID | 错误信息 | 4680| -------- | ---------------- | 4681| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4682| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4683 4684**示例:** 4685 4686```ts 4687aVCastController.off('requestPlay'); 4688``` 4689 4690### on('endOfStream')<sup>11+</sup> 4691 4692on(type: 'endOfStream', callback: Callback\<void>): void 4693 4694设置播放结束的监听事件。 4695 4696**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4697 4698**参数:** 4699 4700| 参数名 | 类型 | 必填 | 说明 | 4701| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ | 4702| type | string | 是 | 事件回调类型,支持事件`'endOfStream'`:当资源播放结束时,触发该事件。 | 4703| callback | Callback\<void\> | 是 | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。 | 4704 4705**错误码:** 4706 4707以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4708 4709| 错误码ID | 错误信息 | 4710| -------- | ------------------------------ | 4711| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4712| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4713 4714**示例:** 4715 4716```ts 4717aVCastController.on('endOfStream', () => { 4718 console.info('on endOfStream'); 4719}); 4720``` 4721 4722### off('endOfStream')<sup>11+</sup> 4723 4724off(type: 'endOfStream', callback?: Callback\<void>): void 4725 4726取消设置播放结束的监听事件。 4727 4728**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4729 4730**参数:** 4731 4732| 参数名 | 类型 | 必填 | 说明 | 4733| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4734| type | string | 是 | 取消对应的监听事件,支持事件`'endOfStream'`。 | 4735| callback | Callback\<void\> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4736 4737**错误码:** 4738 4739以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4740 4741| 错误码ID | 错误信息 | 4742| -------- | ---------------- | 4743| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4744| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4745 4746**示例:** 4747 4748```ts 4749aVCastController.off('endOfStream'); 4750``` 4751 4752### on('seekDone')<sup>10+</sup> 4753 4754on(type: 'seekDone', callback: Callback\<number>): void 4755 4756设置seek结束的监听事件。 4757 4758**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4759 4760**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4761 4762**参数:** 4763 4764| 参数名 | 类型 | 必填 | 说明 | 4765| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4766| type | string | 是 | 事件回调类型,支持事件`'seekDone'`:当seek结束时,触发该事件。 | 4767| callback | Callback\<number\> | 是 | 回调函数,返回seek后播放的位置。 | 4768 4769**错误码:** 4770 4771以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4772 4773| 错误码ID | 错误信息 | 4774| -------- | ------------------------------ | 4775| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4776| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4777 4778**示例:** 4779 4780```ts 4781aVCastController.on('seekDone', (pos: number) => { 4782 console.info(`on seekDone pos:${pos} `); 4783}); 4784``` 4785 4786### off('seekDone')<sup>10+</sup> 4787 4788off(type: 'seekDone'): void 4789 4790取消设置seek结束的监听事件。 4791 4792**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4793 4794**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4795 4796**参数:** 4797 4798| 参数名 | 类型 | 必填 | 说明 | 4799| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4800| type | string | 是 | 取消对应的监听事件,支持事件`'seekDone'`。 | 4801 4802**错误码:** 4803 4804以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4805 4806| 错误码ID | 错误信息 | 4807| -------- | ---------------- | 4808| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4809| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4810 4811**示例:** 4812 4813```ts 4814aVCastController.off('seekDone'); 4815``` 4816 4817### on('validCommandChange')<sup>11+</sup> 4818 4819on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>) 4820 4821会话支持的有效命令变化监听事件。 4822 4823**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4824 4825**参数:** 4826 4827| 参数名 | 类型 | 必填 | 说明 | 4828| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4829| type | string | 是 | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 | 4830| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | 是 | 回调函数。参数commands是有效命令的集合。 | 4831 4832**错误码:** 4833 4834以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4835 4836| 错误码ID | 错误信息 | 4837| -------- | ------------------------------ | 4838| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4839| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4840| 6600103 | The session controller does not exist. | 4841 4842**示例:** 4843 4844```ts 4845aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => { 4846 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 4847 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 4848}); 4849``` 4850 4851### off('validCommandChange')<sup>11+</sup> 4852 4853off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>) 4854 4855媒体控制器取消监听会话有效命令变化的事件。 4856 4857**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4858 4859**参数:** 4860 4861| 参数名 | 类型 | 必填 | 说明 | 4862| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 4863| type | string | 是 | 取消对应的监听事件,支持事件`'validCommandChange'`。 | 4864| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | 否 | 回调函数。参数commands是有效命令的集合。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4865 4866**错误码:** 4867 4868以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4869 4870| 错误码ID | 错误信息 | 4871| -------- | ---------------- | 4872| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4873| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4874| 6600103 | The session controller does not exist. | 4875 4876**示例:** 4877 4878```ts 4879aVCastController.off('validCommandChange'); 4880``` 4881 4882### on('error')<sup>10+</sup> 4883 4884on(type: 'error', callback: ErrorCallback): void 4885 4886监听远端播放器的错误事件,该事件仅用于错误提示,不需要用户停止播控动作。 4887 4888**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4889 4890**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4891 4892**参数:** 4893 4894| 参数名 | 类型 | 必填 | 说明 | 4895| -------- | -------- | ---- | ------------------------------------------------------------ | 4896| type | string | 是 | 错误事件回调类型,支持的事件:'error',用户操作和系统都会触发此事件。 | 4897| callback | ErrorCallback | 是 | 错误事件回调方法:远端播放过程中发生的错误,会提供错误码ID和错误信息。 | 4898 4899**错误码:** 4900 4901以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。 4902 4903| 错误码ID | 错误信息 | 4904| -------- | --------------------- | 4905| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4906| 5400101 | No memory. | 4907| 5400102 | Operation not allowed. | 4908| 5400103 | I/O error. | 4909| 5400104 | Time out. | 4910| 5400105 | Service died. | 4911| 5400106 | Unsupport format. | 4912| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4913 4914**示例:** 4915 4916```ts 4917import { BusinessError } from '@kit.BasicServicesKit'; 4918 4919aVCastController.on('error', (error: BusinessError) => { 4920 console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`) 4921}) 4922``` 4923 4924### off('error')<sup>10+</sup> 4925 4926off(type: 'error'): void 4927 4928取消监听播放的错误事件。 4929 4930**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4931 4932**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4933 4934**参数:** 4935 4936| 参数名 | 类型 | 必填 | 说明 | 4937| ------ | ------ | ---- | ----------------------------------------- | 4938| type | string | 是 | 错误事件回调类型,取消注册的事件:'error'。 | 4939 4940**错误码:** 4941 4942以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。 4943 4944| 错误码ID | 错误信息 | 4945| -------- | --------------------- | 4946| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4947| 5400101 | No memory. | 4948| 5400102 | Operation not allowed. | 4949| 5400103 | I/O error. | 4950| 5400104 | Time out. | 4951| 5400105 | Service died. | 4952| 5400106 | Unsupport format. | 4953| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4954 4955**示例:** 4956 4957```ts 4958aVCastController.off('error') 4959``` 4960 4961### on('keyRequest')<sup>12+</sup> 4962 4963on(type: 'keyRequest', callback: KeyRequestCallback): void 4964 4965在线DRM资源投播时,设置许可证请求的事件监听。 4966 4967**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4968 4969**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4970 4971**参数:** 4972 4973| 参数名 | 类型 | 必填 | 说明 | 4974| ------ | ------ | ---- | ----------------------------------------- | 4975| type | string | 是 | 事件回调类型,支持事件`'keyRequest'`:当DRM资源播放需要许可证时,触发该事件。 | 4976| callback | [KeyRequestCallback](#keyrequestcallback12) | 是 | 回调函数,媒体资源及许可证请求数据。| 4977 4978 4979**错误码:** 4980 4981以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4982 4983| 错误码ID | 错误信息 | 4984| -------- | ---------------- | 4985| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4986| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4987 4988**示例:** 4989 4990```ts 4991let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 4992 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 4993} 4994aVCastController.on('keyRequest', keyRequestCallback); 4995``` 4996### off('keyRequest')<sup>12+</sup> 4997 4998off(type: 'keyRequest', callback?: KeyRequestCallback): void 4999 5000取消监听许可证请求的事件。 5001 5002**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5003 5004**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5005 5006**参数:** 5007 5008| 参数名 | 类型 | 必填 | 说明 | 5009| ------ | ------ | ---- | ----------------------------------------- | 5010| type | string | 是 | 取消对应的监听事件,支持的事件是`'keyRequest'`。 | 5011| callback | [KeyRequestCallback](#keyrequestcallback12) | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5012 5013**错误码:** 5014 5015以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5016 5017| 错误码ID | 错误信息 | 5018| -------- | ---------------- | 5019| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 5020| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5021 5022**示例:** 5023 5024```ts 5025aVCastController.off('keyRequest'); 5026``` 5027 5028### on('castControlGenericError')<sup>13+</sup> 5029 5030on(type: 'castControlGenericError', callback: ErrorCallback): void 5031 5032监听投播通用错误事件。 5033 5034**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5035 5036**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5037 5038**参数:** 5039 5040| 参数名 | 类型 | 必填 | 说明 | 5041| -------- | -------- | ---- | ------------------------------------------------------------ | 5042| type | string | 是 | 错误事件回调类型,支持的事件:'castControlGenericError'。 | 5043| callback | ErrorCallback | 是 | 投播通用错误事件回调方法。 | 5044 5045**错误码:** 5046 5047| 错误码ID | 错误信息 | 5048| -------- | --------------------- | 5049| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5050| 6611000 | The error code for cast control is unspecified. | 5051| 6611001 | An unspecified error occurs in the remote player. | 5052| 6611002 | The playback position falls behind the live window. | 5053| 6611003 | The process of cast control times out. | 5054| 6611004 | The runtime check failed. | 5055| 6611100 | Cross-device data transmission is locked. | 5056| 6611101 | The specified seek mode is not supported. | 5057| 6611102 | The position to seek to is out of the range of the media asset or the specified seek mode is not supported. | 5058| 6611103 | The specified playback mode is not supported. | 5059| 6611104 | The specified playback speed is not supported. | 5060| 6611105 | The action failed because either the media source device or the media sink device has been revoked. | 5061| 6611106 | The parameter is invalid, for example, the url is illegal to play. | 5062| 6611107 | Allocation of memory failed. | 5063| 6611108 | Operation is not allowed. | 5064 5065**示例:** 5066 5067```ts 5068aVCastController.on('castControlGenericError', (error: BusinessError) => { 5069 console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`) 5070}) 5071``` 5072 5073### off('castControlGenericError')<sup>13+</sup> 5074 5075off(type: 'castControlGenericError', callback?: ErrorCallback): void 5076 5077取消监听投播通用的错误事件。 5078 5079**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5080 5081**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5082 5083**参数:** 5084 5085| 参数名 | 类型 | 必填 | 说明 | 5086| -------- | -------- | ---- | ------------------------------------------------------------ | 5087| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlGenericError'。 | 5088| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5089 5090**错误码:** 5091 5092| 错误码ID | 错误信息 | 5093| -------- | --------------------- | 5094| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5095 5096**示例:** 5097 5098```ts 5099aVCastController.off('castControlGenericError'); 5100``` 5101 5102### on('castControlIoError')<sup>13+</sup> 5103 5104on(type: 'castControlIoError', callback: ErrorCallback): void 5105 5106监听投播输入/输出的错误事件。 5107 5108**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5109 5110**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5111 5112**参数:** 5113 5114| 参数名 | 类型 | 必填 | 说明 | 5115| -------- | -------- | ---- | ------------------------------------------------------------ | 5116| type | string | 是 | 错误事件回调类型,支持的事件:'castControlIoError'。 | 5117| callback | ErrorCallback | 是 | 投播输入/输出的错误事件回调方法。 | 5118 5119**错误码:** 5120 5121| 错误码ID | 错误信息 | 5122| -------- | --------------------- | 5123| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5124| 6612000 | An unspecified input/output error occurs. | 5125| 6612001 | Network connection failure. | 5126| 6612002 | Network timeout. | 5127| 6612003 | Invalid "Content-Type" HTTP header. | 5128| 6612004 | The HTTP server returns an unexpected HTTP response status code. | 5129| 6612005 | The file does not exist. | 5130| 6612006 | No permission is granted to perform the IO operation. | 5131| 6612007 | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. | 5132| 6612008 | Reading data out of the data bound. | 5133| 6612100 | The media does not contain any contents that can be played. | 5134| 6612101 | The media cannot be read, for example, because of dust or scratches. | 5135| 6612102 | This resource is already in use. | 5136| 6612103 | The content using the validity interval has expired. | 5137| 6612104 | Using the requested content to play is not allowed. | 5138| 6612105 | The use of the allowed content cannot be verified. | 5139| 6612106 | The number of times this content has been used as requested has reached the maximum allowed number of uses. | 5140| 6612107 | An error occurs when sending packet from source device to sink device. | 5141 5142**示例:** 5143 5144```ts 5145aVCastController.on('castControlIoError', (error: BusinessError) => { 5146 console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`) 5147}) 5148``` 5149 5150### off('castControlIoError')<sup>13+</sup> 5151 5152off(type: 'castControlIoError', callback?: ErrorCallback): void 5153 5154取消监听投播输入/输出的错误事件。 5155 5156**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5157 5158**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5159 5160**参数:** 5161 5162| 参数名 | 类型 | 必填 | 说明 | 5163| -------- | -------- | ---- | ------------------------------------------------------------ | 5164| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlIoError'。 | 5165| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5166 5167**错误码:** 5168 5169| 错误码ID | 错误信息 | 5170| -------- | --------------------- | 5171| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5172 5173**示例:** 5174 5175```ts 5176aVCastController.off('castControlIoError'); 5177``` 5178 5179### on('castControlParsingError')<sup>13+</sup> 5180 5181on(type: 'castControlParsingError', callback: ErrorCallback): void 5182 5183监听投播解析的错误事件。 5184 5185**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5186 5187**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5188 5189**参数:** 5190 5191| 参数名 | 类型 | 必填 | 说明 | 5192| -------- | -------- | ---- | ------------------------------------------------------------ | 5193| type | string | 是 | 错误事件回调类型,支持的事件:'castControlParsingError'。 | 5194| callback | ErrorCallback | 是 | 投播解析的错误事件回调方法。 | 5195 5196**错误码:** 5197 5198| 错误码ID | 错误信息 | 5199| -------- | --------------------- | 5200| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5201| 6613000 | Unspecified error related to content parsing. | 5202| 6613001 | Parsing error associated with media container format bit streams. | 5203| 6613002 | Parsing error associated with the media manifest. | 5204| 6613003 | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature. | 5205| 6613004 | Unsupported feature in the media manifest. | 5206 5207**示例:** 5208 5209```ts 5210aVCastController.on('castControlParsingError', (error: BusinessError) => { 5211 console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`) 5212}) 5213``` 5214 5215### off('castControlParsingError')<sup>13+</sup> 5216 5217off(type: 'castControlParsingError', callback?: ErrorCallback): void 5218 5219取消监听投播解析的错误事件。 5220 5221**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5222 5223**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5224 5225**参数:** 5226 5227| 参数名 | 类型 | 必填 | 说明 | 5228| -------- | -------- | ---- | ------------------------------------------------------------ | 5229| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlParsingError'。 | 5230| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5231 5232**错误码:** 5233 5234| 错误码ID | 错误信息 | 5235| -------- | --------------------- | 5236| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5237 5238**示例:** 5239 5240```ts 5241aVCastController.off('castControlParsingError'); 5242``` 5243 5244### on('castControlDecodingError')<sup>13+</sup> 5245 5246on(type: 'castControlDecodingError', callback: ErrorCallback): void 5247 5248监听投播解码的错误事件。 5249 5250**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5251 5252**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5253 5254**参数:** 5255 5256| 参数名 | 类型 | 必填 | 说明 | 5257| -------- | -------- | ---- | ------------------------------------------------------------ | 5258| type | string | 是 | 错误事件回调类型,支持的事件:'castControlDecodingError'。 | 5259| callback | ErrorCallback | 是 | 投播解码的错误事件回调方法。 | 5260 5261**错误码:** 5262 5263| 错误码ID | 错误信息 | 5264| -------- | --------------------- | 5265| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5266| 6614000 | Unspecified decoding error. | 5267| 6614001 | Decoder initialization failed. | 5268| 6614002 | Decoder query failed. | 5269| 6614003 | Decoding the media samples failed. | 5270| 6614004 | The format of the content to decode exceeds the capabilities of the device. | 5271| 6614005 | The format of the content to decode is not supported. | 5272 5273**示例:** 5274 5275```ts 5276aVCastController.on('castControlDecodingError', (error: BusinessError) => { 5277 console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`) 5278}) 5279``` 5280### off('castControlDecodingError')<sup>13+</sup> 5281 5282off(type: 'castControlDecodingError', callback?: ErrorCallback): void 5283 5284取消监听投播解码的错误事件。 5285 5286**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5287 5288**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5289 5290**参数:** 5291 5292| 参数名 | 类型 | 必填 | 说明 | 5293| -------- | -------- | ---- | ------------------------------------------------------------ | 5294| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlDecodingError'。 | 5295| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5296 5297**错误码:** 5298 5299| 错误码ID | 错误信息 | 5300| -------- | --------------------- | 5301| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5302 5303**示例:** 5304 5305```ts 5306aVCastController.off('castControlDecodingError'); 5307``` 5308 5309### on('castControlAudioRendererError')<sup>13+</sup> 5310 5311on(type: 'castControlAudioRendererError', callback: ErrorCallback): void 5312 5313监听投播音频渲染器的错误事件。 5314 5315**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5316 5317**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5318 5319**参数:** 5320 5321| 参数名 | 类型 | 必填 | 说明 | 5322| -------- | -------- | ---- | ------------------------------------------------------------ | 5323| type | string | 是 | 错误事件回调类型,支持的事件:'castControlAudioRendererError'。 | 5324| callback | ErrorCallback | 是 | 投播音频渲染器的错误事件回调方法。 | 5325 5326**错误码:** 5327 5328以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。 5329 5330| 错误码ID | 错误信息 | 5331| -------- | --------------------- | 5332| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5333| 6615000 | Unspecified errors related to the audio renderer. | 5334| 6615001 | Initializing the audio renderer failed. | 5335| 6615002 | The audio renderer fails to write data. | 5336 5337**示例:** 5338 5339```ts 5340aVCastController.on('castControlAudioRendererError', (error: BusinessError) => { 5341 console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`) 5342}) 5343``` 5344### off('castControlAudioRendererError')<sup>13+</sup> 5345 5346off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void 5347 5348取消监听投播音频渲染器的错误事件。 5349 5350**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5351 5352**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5353 5354**参数:** 5355 5356| 参数名 | 类型 | 必填 | 说明 | 5357| -------- | -------- | ---- | ------------------------------------------------------------ | 5358| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlAudioRendererError'。 | 5359| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5360 5361**错误码:** 5362 5363| 错误码ID | 错误信息 | 5364| -------- | --------------------- | 5365| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 5366 5367**示例:** 5368 5369```ts 5370aVCastController.off('castControlAudioRendererError'); 5371``` 5372 5373### on('castControlDrmError')<sup>13+</sup> 5374 5375on(type: 'castControlDrmError', callback: ErrorCallback): void 5376 5377监听投播drm的错误事件。 5378 5379**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5380 5381**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5382 5383**参数:** 5384 5385| 参数名 | 类型 | 必填 | 说明 | 5386| -------- | -------- | ---- | ------------------------------------------------------------ | 5387| type | string | 是 | 错误事件回调类型,支持的事件:'castControlDrmError'。 | 5388| callback | ErrorCallback | 是 | 投播drm的错误事件回调方法。 | 5389 5390**错误码:** 5391 5392| 错误码ID | 错误信息 | 5393| -------- | --------------------- | 5394| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5395| 6616000 | Unspecified error related to DRM. | 5396| 6616001 | The chosen DRM protection scheme is not supported by the device. | 5397| 6616002 | Device provisioning failed. | 5398| 6616003 | The DRM-protected content to play is incompatible. | 5399| 6616004 | Failed to obtain a license. | 5400| 6616005 | The operation is disallowed by the license policy. | 5401| 6616006 | An error occurs in the DRM system. | 5402| 6616007 | The device has revoked DRM privileges. | 5403| 6616008 | The DRM license being loaded into the open DRM session has expired. | 5404| 6616100 | An error occurs when the DRM processes the key response. | 5405 5406**示例:** 5407 5408```ts 5409aVCastController.on('castControlDrmError', (error: BusinessError) => { 5410 console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`) 5411}) 5412``` 5413 5414### off('castControlDrmError')<sup>13+</sup> 5415 5416off(type: 'castControlDrmError', callback?: ErrorCallback): void 5417 5418取消监听投播drm的错误事件。 5419 5420**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 5421 5422**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5423 5424**参数:** 5425 5426| 参数名 | 类型 | 必填 | 说明 | 5427| -------- | -------- | ---- | ------------------------------------------------------------ | 5428| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlDrmError'。 | 5429| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5430 5431**错误码:** 5432 5433| 错误码ID | 错误信息 | 5434| -------- | --------------------- | 5435| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5436 5437**示例:** 5438 5439```ts 5440aVCastController.off('castControlDrmError'); 5441``` 5442 5443## ExtraInfo<sup>18+</sup> 5444type ExtraInfo = { [key: string]: Object; } 5445 5446媒体提供方设置的自定义媒体数据包对象。 5447 5448**系统能力:** SystemCapability.Multimedia.AVSession.Core 5449 5450| 类型 | 说明 | 5451| ----------------------------------- | ----------------------------- | 5452| [key: string]: Object | key为远端分布式事件类型。当前支持的事件类型包括:<br>'AUDIO_GET_VOLUME':获取远端设备音量。<br>'AUDIO_GET_AVAILABLE_DEVICES':获取远端所有可连接设备。<br>'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO':获取远端实际发声设备。<br>媒体提供方根据不同的远端分布式事件类型,返回对应的媒体数据包Object对象。 | 5453 5454## KeyRequestCallback<sup>12+</sup> 5455type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void 5456 5457许可证请求事件的回调函数。 5458 5459**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5460 5461**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5462 5463**参数:** 5464 5465| 参数名 | 类型 | 必填 | 说明 | 5466| ------ | ------ | ---- | ----------------------------------------- | 5467| assetId | string | 是 | 媒体ID。 | 5468| requestData | Uint8Array | 是 | 媒体许可证请求数据。 | 5469 5470**示例:** 5471<!--code_no_check--> 5472```ts 5473let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 5474 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 5475} 5476``` 5477 5478## CastDisplayState<sup>12+</sup> 5479 5480投播显示设备状态的枚举。 5481 5482**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5483 5484**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5485 5486| 名称 | 值 | 说明 | 5487| --------------------------- | ---- | ----------- | 5488| STATE_OFF | 1 | 设备断开,扩展屏不再显示内容。 | 5489| STATE_ON | 2 | 设备连接成功,扩展屏可用。 | 5490 5491 5492## CastDisplayInfo<sup>12+</sup> 5493 5494扩展屏投播显示设备相关属性。 5495 5496**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5497 5498**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5499 5500| 名称 | 类型 | 只读 | 可选 | 说明 | 5501| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 5502| id | number | 否 | 否 | 投播显示设备的ID,该参数应为整数。 | 5503| name | string | 否 | 否 | 投播显示设备的名称。 | 5504| state | [CastDisplayState](#castdisplaystate12) | 否 | 否 |投播显示设备状态。 | 5505| width | number | 否 | 否 | 投播显示设备的屏幕宽度,单位为px,该参数应为整数。 | 5506| height | number | 否 | 否 | 投播显示设备的屏幕高度,单位为px,该参数应为整数。 | 5507 5508## ConnectionState<sup>10+</sup> 5509 5510连接状态枚举。 5511 5512**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5513 5514**系统能力:** SystemCapability.Multimedia.AVSession.Core 5515 5516| 名称 | 值 | 说明 | 5517| --------------------------- | ---- | ----------- | 5518| STATE_CONNECTING | 0 | 设备连接中。 | 5519| STATE_CONNECTED | 1 | 设备连接成功。 | 5520| STATE_DISCONNECTED | 6 | 设备断开连接。 | 5521 5522## AVMetadata<sup>10+</sup> 5523 5524媒体元数据的相关属性。 5525 5526**系统能力:** SystemCapability.Multimedia.AVSession.Core 5527 5528| 名称 | 类型 | 只读 | 可选 | 说明 | 5529| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 5530| assetId | string | 否 | 否 | 媒体ID。歌曲的唯一标识,由应用自定义。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5531| title | string | 否 | 是 | 标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5532| artist | string | 否 | 是 | 艺术家。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5533| author | string | 否 | 是 | 专辑作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5534| avQueueName<sup>12+</sup> | string | 否 | 是 | 歌单(歌曲列表)名称。 | 5535| avQueueId<sup>11+</sup> | string | 否 | 是 | 歌单(歌曲列表)唯一标识Id。 | 5536| avQueueImage<sup>11+</sup> | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | string | 否 | 是 | 歌单(歌曲列表)封面图。<br>图片的像素数据或者图片路径地址(本地路径或网络路径)。应用通过setAVMetadata设置图片数据。<br>- 设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。<br>- 设置为url图片路径,获取的为url图片路径。 | 5537| album | string | 否 | 是 | 专辑名称。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5538| writer | string | 否 | 是 | 词作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5539| composer | string | 否 | 是 | 作曲者。 | 5540| duration | number | 否 | 是 | 媒体时长,单位毫秒(ms)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5541| mediaImage | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | string | 否 | 是 | 图片的像素数据或者图片路径地址(本地路径或网络路径)。应用通过setAVMetadata设置图片数据。<br>- 设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。<br>- 设置为url图片路径,获取的为url图片路径。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5542| bundleIcon<sup>18+</sup> | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | 是 | 是 | 应用图标图片的像素数据。只读类型,不从应用侧设置。| 5543| publishDate | Date | 否 | 是 | 发行日期。 | 5544| subtitle | string | 否 | 是 | 子标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5545| description | string | 否 | 是 | 媒体描述。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5546| lyric | string | 否 | 是 | 媒体歌词内容。应用需将歌词内容拼接为一个字符串传入。<br>字符串长度需<40960字节。<br>**说明:** 系统支持简单版的LRC格式(Simple LRC format)的歌词文本内容。当传入的歌词内容不规范(例如:出现重复的时间戳等),将导致解析失败,并在系统中显示异常。 | 5547| singleLyricText<sup>17+</sup> | string | 否 | 是 | 单条媒体歌词内容。应用需将歌词内容拼接为一个字符串传入(不包含时间戳)。<br>字符串长度<40960字节。<br>**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。| 5548| previousAssetId | string | 否 | 是 | 上一首媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5549| nextAssetId | string | 否 | 是 | 下一首媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5550| filter<sup>11+</sup> | number | 否 | 是 | 当前session支持的协议,默认为TYPE_CAST_PLUS_STREAM。具体取值参考[ProtocolType](#protocoltype11)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5551| drmSchemes<sup>12+</sup> | Array\<string> | 否 | 是 | 当前session支持的DRM方案,取值为DRM方案uuid。| 5552| skipIntervals<sup>11+</sup> | [SkipIntervals](#skipintervals11) | 否 | 是 | 快进快退支持的时间间隔。默认为SECONDS_15,即15秒。 | 5553|displayTags<sup>11+</sup> | number | 否 | 是 | 媒体资源的金标类型,取值参考[DisplayTag](#displaytag11)。 | 5554 5555## AVMediaDescription<sup>10+</sup> 5556 5557播放列表媒体元数据的相关属性。 5558 5559**系统能力:** SystemCapability.Multimedia.AVSession.Core 5560 5561| 名称 | 类型 | 只读 | 可选 | 说明 | 5562| ------------ | ----------------------- | ---- | ---- | ----------------------- | 5563| assetId | string | 否 | 否 | 播放列表媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5564| title | string | 否 | 是 | 播放列表媒体标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5565| subtitle | string | 否 | 是 | 播放列表媒体子标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5566| description | string | 否 | 是 | 播放列表媒体描述的文本。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5567| mediaImage | image.PixelMap \| string | 否 | 是 | 播放列表媒体图片像素数据。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5568| extras | {[key: string]: Object} | 否 | 是 | 播放列表媒体额外字段。 | 5569| mediaUri | string | 否 | 是 | 播放列表媒体URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5570| mediaType | string | 否 | 是 | 播放列表媒体类型。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5571| mediaSize | number | 否 | 是 | 播放列表媒体的大小。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5572| albumTitle | string | 否 | 是 | 播放列表媒体专辑标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5573| albumCoverUri | string | 否 | 是 | 播放列表媒体专辑标题URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5574| lyricContent | string | 否 | 是 | 播放列表媒体歌词内容。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5575| lyricUri | string | 否 | 是 | 播放列表媒体歌词URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5576| artist | string | 否 | 是 | 播放列表媒体专辑作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5577| fdSrc | media.AVFileDescriptor | 否 | 是 | 播放列表媒体本地文件的句柄。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5578| dataSrc<sup>12+</sup> | media.AVDataSrcDescriptor | 否 | 是 | 播放列表数据源描述。 | 5579| pcmSrc<sup>20+</sup> | boolean | 否 | 是 | 播放列表是否使用PCM数据源。true表示使用PCM数据源,false表示不使用PCM数据源。<br>由于设备限制,暂时无法使用,将在后续版本提供支持。 | 5580| drmScheme<sup>12+</sup> | string | 否 | 是 | 播放列表媒体支持的DRM方案,由uuid表示。 | 5581| duration | number | 否 | 是 | 播放列表媒体播放时长。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5582| startPosition | number | 否 | 是 | 播放列表媒体起始播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5583| creditsPosition | number | 否 | 是 | 播放列表媒体的片尾播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5584| appName | string | 否 | 是 | 播放列表提供的应用的名字。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5585|displayTags<sup>11+</sup> | number | 否 | 是 | 媒体资源的金标类型,取值参考[DisplayTag](#displaytag11)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5586 5587## AVQueueItem<sup>10+</sup> 5588 5589播放列表中单项的相关属性。 5590 5591**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5592 5593**系统能力:** SystemCapability.Multimedia.AVSession.Core 5594 5595| 名称 | 类型 | 必填 | 说明 | 5596| ------------ | ------------------------------------------ | ---- | --------------------------- | 5597| itemId | number | 是 | 播放列表中单项的ID。 | 5598| description | [AVMediaDescription](#avmediadescription10) | 否 | 播放列表中单项的媒体元数据。 | 5599 5600## AVPlaybackState<sup>10+</sup> 5601 5602媒体播放状态的相关属性。 5603 5604**系统能力:** SystemCapability.Multimedia.AVSession.Core 5605 5606| 名称 | 类型 | 必填 | 说明 | 5607| ------------ | ------------------------------------- | ---- | ------- | 5608| state | [PlaybackState](#playbackstate10) | 否 | 播放状态。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5609| speed | number | 否 | 播放倍速。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5610| position | [PlaybackPosition](#playbackposition10) | 否 | 播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5611| bufferedTime | number | 否 | 缓冲时间。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5612| loopMode | [LoopMode](#loopmode10) | 否 | 循环模式。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5613| isFavorite | boolean | 否 | 是否收藏,true表示收藏。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5614| activeItemId<sup>10+</sup> | number | 否 | 正在播放的媒体Id。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5615| volume<sup>10+</sup> | number | 否 | 正在播放的媒体音量。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5616| maxVolume<sup>11+</sup> | number | 否 | 最大音量。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5617| muted<sup>11+</sup> | boolean | 否 | 当前静音状态,true表示静音。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5618| duration<sup>11+</sup> | number | 否 | 当前媒体资源的时长。 | 5619| videoWidth<sup>11+</sup> | number | 否 | 媒体资源的视频宽度,单位为像素(px)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5620| videoHeight<sup>11+</sup> | number | 否 | 媒体资源的视频高度,单位为像素(px)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5621| extras<sup>10+</sup> | {[key: string]: Object} | 否 | 自定义媒体数据。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5622 5623## PlaybackPosition<sup>10+</sup> 5624 5625媒体播放位置的相关属性。 5626 5627**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5628 5629**系统能力:** SystemCapability.Multimedia.AVSession.Core 5630 5631| 名称 | 类型 | 必填 | 说明 | 5632| ----------- | ------ | ---- | ------------------ | 5633| elapsedTime | number | 是 | 已用时间,单位毫秒(ms)。 | 5634| updateTime | number | 是 | 更新时间,单位毫秒(ms)。 | 5635 5636## CallMetadata<sup>11+</sup> 5637 5638通话会话元数据相关属性。 5639 5640**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5641 5642**系统能力:** SystemCapability.Multimedia.AVSession.Core 5643 5644| 名称 | 类型 | 必填 | 说明 | 5645| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 5646| name | string | 否 | 来电人姓名(别名)。 | 5647| phoneNumber | string | 否 | 来电电话号码。 | 5648| avatar | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | 否 | 来电人头像。 | 5649 5650## AVCallState<sup>11+</sup> 5651 5652通话状态相关属性。 5653 5654**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5655 5656**系统能力:** SystemCapability.Multimedia.AVSession.Core 5657 5658| 名称 | 类型 | 必填 | 说明 | 5659| --------------- |------------------------- | ---- |---------------------------------------------------------------------| 5660| state | [CallState](#callstate11) | 是 | 当前通话状态。 | 5661| muted | boolean | 是 | 通话mic是否静音。 <br>true:静音。 <br>false:不是静音。| 5662 5663## CallState<sup>11+</sup> 5664 5665表示通话状态的枚举。 5666 5667**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5668 5669**系统能力:** SystemCapability.Multimedia.AVSession.Core 5670 5671| 名称 | 值 | 说明 | 5672| -------------------------- | ---- | -------- | 5673| CALL_STATE_IDLE | 0 | 空闲状态。 | 5674| CALL_STATE_INCOMING | 1 | 来电。 | 5675| CALL_STATE_ACTIVE | 2 | 接通。 | 5676| CALL_STATE_DIALING | 3 | 响铃。 | 5677| CALL_STATE_WAITING | 4 | 等待接通。 | 5678| CALL_STATE_HOLDING | 5 | 保持。 | 5679| CALL_STATE_DISCONNECTING | 6 | 挂断。 | 5680 5681## DisplayTag<sup>11+</sup> 5682 5683枚举,表示当前媒体资源的金标,即应用媒体音源的特殊类型标识。 5684 5685**系统能力:** SystemCapability.Multimedia.AVSession.Core 5686 5687| 名称 | 值 | 说明 | 5688| -------------------------- | ---- | ------------ | 5689| TAG_AUDIO_VIVID | 1 | AUDIO VIVID | 5690 5691## DecoderType<sup>19+</sup> 5692 5693枚举,设备所支持的解码格式。 5694 5695**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5696 5697**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5698 5699| 名称 | 值 | 说明 | 5700| -------------------------- | ---- | ------------ | 5701| OH_AVCODEC_MIMETYPE_VIDEO_AVC | "video/avc" | VIDEO AVC | 5702| OH_AVCODEC_MIMETYPE_VIDEO_HEVC | "video/hevc" | VIDEO HEVC | 5703| OH_AVCODEC_MIMETYPE_AUDIO_VIVID | "audio/av3a" | AUDIO AV3A | 5704 5705 5706## ResolutionLevel<sup>19+</sup> 5707 5708枚举,设备所支持的分辨率。 5709 5710**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 5711 5712**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5713 5714| 名称 | 值 | 说明 | 5715| -------------------------- | ---- | ------------ | 5716| RESOLUTION_480P | 0 | 分辨率为480P(640*480 dpi)。 | 5717| RESOLUTION_720P | 1 | 分辨率为720P(1280*720 dpi)。 | 5718| RESOLUTION_1080P | 2 | 分辨率为1080P(1920*1080 dpi)。 | 5719| RESOLUTION_2K | 3 | 分辨率为2k(2560*1440 dpi)。 | 5720| RESOLUTION_4K | 4 | 分辨率为4k(4096*3840 dpi)。 | 5721 5722## AVCastCategory<sup>10+</sup> 5723 5724投播的类别枚举。 5725 5726**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5727 5728**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5729 5730| 名称 | 值 | 说明 | 5731| --------------------------- | ---- | ----------- | 5732| CATEGORY_LOCAL | 0 | 本地播放,默认播放设备,声音从本机或者连接的蓝牙耳机设备出声。 | 5733| CATEGORY_REMOTE | 1 | 远端播放,远端播放设备,声音从其他设备发出声音或者画面。 | 5734 5735## DeviceType<sup>10+</sup> 5736 5737播放设备的类型枚举。 5738 5739**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5740 5741| 名称 | 值 | 说明 | 5742| --------------------------- | ---- | ----------- | 5743| DEVICE_TYPE_LOCAL | 0 | 本地播放类型。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core| 5744| DEVICE_TYPE_BLUETOOTH | 10 | 蓝牙设备。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core | 5745| DEVICE_TYPE_TV | 2 | 电视。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast | 5746| DEVICE_TYPE_SMART_SPEAKER | 3 | 音箱设备。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast | 5747 5748## DeviceInfo<sup>10+</sup> 5749 5750播放设备的相关信息。 5751 5752| 名称 | 类型 | 必填 | 说明 | 5753| ---------- | -------------- | ---- | ---------------------- | 5754| castCategory | AVCastCategory | 是 | 投播的类别。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5755| deviceId | string | 是 | 播放设备的ID。<br> **系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5756| deviceName | string | 是 | 播放设备的名称。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5757| deviceType | DeviceType | 是 | 播放设备的类型。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5758| supportedProtocols<sup>11+</sup> | number | 否 | 播放设备支持的协议。默认为TYPE_LOCAL。具体取值参考[ProtocolType](#protocoltype11)。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5759| supportedDrmCapabilities<sup>12+</sup> | Array\<string> | 否 | 播放设备支持的DRM能力。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5760| manufacturer<sup>13+</sup> | string | 否 | 播放设备生产厂家。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。| 5761| modelName<sup>13+</sup> | string | 否 | 播放设备型号名称。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。| 5762| audioCapabilities<sup>20+</sup> | [AudioCapabilities](#audiocapabilities20) | 否 | 播放设备支持的音频能力。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast | 5763 5764## OutputDeviceInfo<sup>10+</sup> 5765 5766播放设备的相关信息。 5767 5768**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5769 5770**系统能力:** SystemCapability.Multimedia.AVSession.Core 5771 5772| 名称 | 类型 | 必填 | 说明 | 5773| ---------- | -------------- | ---- | ---------------------- | 5774| devices | Array\<DeviceInfo\> | 是 | 播放设备的集合。 | 5775 5776## LoopMode<sup>10+</sup> 5777 5778表示媒体播放循环模式的枚举。 5779 5780**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5781 5782**系统能力:** SystemCapability.Multimedia.AVSession.Core 5783 5784| 名称 | 值 | 说明 | 5785| ------------------ | ---- | -------- | 5786| LOOP_MODE_SEQUENCE | 0 | 顺序播放。 | 5787| LOOP_MODE_SINGLE | 1 | 单曲循环。 | 5788| LOOP_MODE_LIST | 2 | 表单循环。 | 5789| LOOP_MODE_SHUFFLE | 3 | 随机播放。 | 5790| LOOP_MODE_CUSTOM<sup>11+</sup> | 4 | 自定义播放。 | 5791 5792## PlaybackState<sup>10+</sup> 5793 5794表示媒体播放状态的枚举。 5795 5796**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5797 5798**系统能力:** SystemCapability.Multimedia.AVSession.Core 5799 5800| 名称 | 值 | 说明 | 5801| --------------------------- | ---- | ----------- | 5802| PLAYBACK_STATE_INITIAL | 0 | 初始状态。 | 5803| PLAYBACK_STATE_PREPARE | 1 | 播放准备状态。 | 5804| PLAYBACK_STATE_PLAY | 2 | 正在播放。 | 5805| PLAYBACK_STATE_PAUSE | 3 | 暂停。 | 5806| PLAYBACK_STATE_FAST_FORWARD | 4 | 快进。 | 5807| PLAYBACK_STATE_REWIND | 5 | 快退。 | 5808| PLAYBACK_STATE_STOP | 6 | 停止。 | 5809| PLAYBACK_STATE_COMPLETED | 7 | 播放完成。 | 5810| PLAYBACK_STATE_RELEASED | 8 | 释放。 | 5811| PLAYBACK_STATE_ERROR | 9 | 错误。 | 5812| PLAYBACK_STATE_IDLE<sup>11+</sup> | 10 | 空闲。 | 5813| PLAYBACK_STATE_BUFFERING<sup>11+</sup> | 11 | 缓冲。 | 5814 5815## AVSessionController<sup>10+</sup> 5816 5817AVSessionController控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 5818 5819### 属性 5820 5821**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5822 5823**系统能力:** SystemCapability.Multimedia.AVSession.Core 5824 5825| 名称 | 类型 | 只读 | 可选 | 说明 | 5826| :-------- | :----- | :--- | :--- | :-------------------------------------- | 5827| sessionId | string | 是 | 否 | AVSessionController对象唯一的会话标识。 | 5828 5829 5830**示例:** 5831 5832```ts 5833import { BusinessError } from '@kit.BasicServicesKit'; 5834import { avSession } from '@kit.AVSessionKit'; 5835 5836let tag: string = "createNewSession"; 5837let sessionId: string = ""; 5838let AVSessionController: avSession.AVSessionController; 5839avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 5840 currentAVSession = data; 5841 sessionId = currentAVSession.sessionId; 5842 AVSessionController = await currentAVSession.getController(); 5843 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 5844}).catch((err: BusinessError) => { 5845 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 5846}); 5847``` 5848 5849### getAVPlaybackState<sup>10+</sup> 5850 5851getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 5852 5853获取当前的远端播放状态。结果通过callback异步回调方式返回。 5854 5855**系统能力:** SystemCapability.Multimedia.AVSession.Core 5856 5857**参数:** 5858 5859| 参数名 | 类型 | 必填 | 说明 | 5860| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 5861| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | 是 | 回调函数,返回远端播放状态。 | 5862 5863**错误码:** 5864 5865以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5866 5867| 错误码ID | 错误信息 | 5868| -------- | ---------------------------------------- | 5869| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5870| 6600102 | The session does not exist. | 5871| 6600103 | The session controller does not exist. | 5872 5873**示例:** 5874 5875```ts 5876import { BusinessError } from '@kit.BasicServicesKit'; 5877 5878avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 5879 if (err) { 5880 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5881 } else { 5882 console.info('getAVPlaybackState : SUCCESS'); 5883 } 5884}); 5885``` 5886 5887### getAVPlaybackState<sup>10+</sup> 5888 5889getAVPlaybackState(): Promise\<AVPlaybackState> 5890 5891获取当前的远端播放状态。结果通过Promise异步回调方式返回。 5892 5893**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5894 5895**系统能力:** SystemCapability.Multimedia.AVSession.Core 5896 5897**返回值:** 5898 5899| 类型 | 说明 | 5900| --------- | ------------------------------------------------------------ | 5901| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise对象。返回远端播放状态。 | 5902 5903**错误码:** 5904 5905以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5906 5907| 错误码ID | 错误信息 | 5908| -------- | ---------------------------------------- | 5909| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5910| 6600102 | The session does not exist. | 5911| 6600103 | The session controller does not exist. | 5912 5913**示例:** 5914 5915```ts 5916import { BusinessError } from '@kit.BasicServicesKit'; 5917 5918avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 5919 console.info('getAVPlaybackState : SUCCESS'); 5920}).catch((err: BusinessError) => { 5921 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5922}); 5923``` 5924 5925### getAVMetadata<sup>10+</sup> 5926 5927getAVMetadata(): Promise\<AVMetadata> 5928 5929获取会话元数据。结果通过Promise异步回调方式返回。 5930 5931**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5932 5933**系统能力:** SystemCapability.Multimedia.AVSession.Core 5934 5935**返回值:** 5936 5937| 类型 | 说明 | 5938| ----------------------------------- | ----------------------------- | 5939| Promise<[AVMetadata](#avmetadata10)\> | Promise对象,返回会话元数据。 | 5940 5941**错误码:** 5942 5943以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5944 5945| 错误码ID | 错误信息 | 5946| -------- | ---------------------------------------- | 5947| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5948| 6600102 | The session does not exist. | 5949| 6600103 | The session controller does not exist. | 5950 5951**示例:** 5952 5953```ts 5954import { BusinessError } from '@kit.BasicServicesKit'; 5955 5956avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => { 5957 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5958}).catch((err: BusinessError) => { 5959 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5960}); 5961``` 5962 5963### getAVMetadata<sup>10+</sup> 5964 5965getAVMetadata(callback: AsyncCallback\<AVMetadata>): void 5966 5967获取会话元数据。结果通过callback异步回调方式返回。 5968 5969**系统能力:** SystemCapability.Multimedia.AVSession.Core 5970 5971**参数:** 5972 5973| 参数名 | 类型 | 必填 | 说明 | 5974| -------- | ----------------------------------------- | ---- | -------------------------- | 5975| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | 是 | 回调函数,返回会话元数据。 | 5976 5977**错误码:** 5978 5979以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5980 5981| 错误码ID | 错误信息 | 5982| -------- | ---------------------------------------- | 5983| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5984| 6600102 | The session does not exist. | 5985| 6600103 | The session controller does not exist. | 5986 5987**示例:** 5988 5989```ts 5990import { BusinessError } from '@kit.BasicServicesKit'; 5991 5992avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => { 5993 if (err) { 5994 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5995 } else { 5996 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5997 } 5998}); 5999``` 6000 6001### getAVQueueTitle<sup>10+</sup> 6002 6003getAVQueueTitle(): Promise\<string> 6004 6005获取当前会话播放列表的名称。结果通过Promise异步回调方式返回。 6006 6007**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6008 6009**系统能力:** SystemCapability.Multimedia.AVSession.Core 6010 6011**返回值:** 6012 6013| 类型 | 说明 | 6014| ---------------- | ----------------------------- | 6015| Promise<string\> | Promise对象。返回播放列表名称。 | 6016 6017**错误码:** 6018 6019以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6020 6021| 错误码ID | 错误信息 | 6022| -------- | ---------------------------------------- | 6023| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6024| 6600102 | The session does not exist. | 6025| 6600103 | The session controller does not exist. | 6026 6027**示例:** 6028 6029```ts 6030import { BusinessError } from '@kit.BasicServicesKit'; 6031 6032avsessionController.getAVQueueTitle().then((title: string) => { 6033 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 6034}).catch((err: BusinessError) => { 6035 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 6036}); 6037``` 6038 6039### getAVQueueTitle<sup>10+</sup> 6040 6041getAVQueueTitle(callback: AsyncCallback\<string>): void 6042 6043获取当前播放列表的名称。结果通过callback异步回调方式返回。 6044 6045**系统能力:** SystemCapability.Multimedia.AVSession.Core 6046 6047**参数:** 6048 6049| 参数名 | 类型 | 必填 | 说明 | 6050| -------- | ---------------------- | ---- | ------------------------- | 6051| callback | AsyncCallback<string\> | 是 | 回调函数,返回播放列表名称。 | 6052 6053**错误码:** 6054 6055以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6056 6057| 错误码ID | 错误信息 | 6058| -------- | ---------------------------------------- | 6059| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6060| 6600102 | The session does not exist. | 6061| 6600103 | The session controller does not exist. | 6062 6063**示例:** 6064 6065```ts 6066import { BusinessError } from '@kit.BasicServicesKit'; 6067 6068avsessionController.getAVQueueTitle((err: BusinessError, title: string) => { 6069 if (err) { 6070 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 6071 } else { 6072 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 6073 } 6074}); 6075``` 6076 6077### getAVQueueItems<sup>10+</sup> 6078 6079getAVQueueItems(): Promise\<Array\<AVQueueItem>> 6080 6081获取当前会话播放列表相关信息。结果通过Promise异步回调方式返回。 6082 6083**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6084 6085**系统能力:** SystemCapability.Multimedia.AVSession.Core 6086 6087**返回值:** 6088 6089| 类型 | 说明 | 6090| --------------------------------------------- | ----------------------------- | 6091| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise对象。返回播放列表队列。 | 6092 6093**错误码:** 6094 6095以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6096 6097| 错误码ID | 错误信息 | 6098| -------- | ---------------------------------------- | 6099| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6100| 6600102 | The session does not exist. | 6101| 6600103 | The session controller does not exist. | 6102 6103**示例:** 6104 6105```ts 6106import { BusinessError } from '@kit.BasicServicesKit'; 6107 6108avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => { 6109 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 6110}).catch((err: BusinessError) => { 6111 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 6112}); 6113``` 6114 6115### getAVQueueItems<sup>10+</sup> 6116 6117getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void 6118 6119获取当前播放列表相关信息。结果通过callback异步回调方式返回。 6120 6121**系统能力:** SystemCapability.Multimedia.AVSession.Core 6122 6123**参数:** 6124 6125| 参数名 | 类型 | 必填 | 说明 | 6126| -------- | --------------------------------------------------- | ---- | ------------------------- | 6127| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | 是 | 回调函数,返回播放列表队列。 | 6128 6129**错误码:** 6130 6131以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6132 6133| 错误码ID | 错误信息 | 6134| -------- | ---------------------------------------- | 6135| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6136| 6600102 | The session does not exist. | 6137| 6600103 | The session controller does not exist. | 6138 6139**示例:** 6140 6141```ts 6142import { BusinessError } from '@kit.BasicServicesKit'; 6143 6144avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => { 6145 if (err) { 6146 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 6147 } else { 6148 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 6149 } 6150}); 6151``` 6152 6153### skipToQueueItem<sup>10+</sup> 6154 6155skipToQueueItem(itemId: number): Promise\<void> 6156 6157设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过Promise异步回调方式返回。 6158 6159**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6160 6161**系统能力:** SystemCapability.Multimedia.AVSession.Core 6162 6163**参数:** 6164 6165| 参数名 | 类型 | 必填 | 说明 | 6166| ------ | ------- | ---- | ------------------------------------------- | 6167| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | 6168 6169**返回值:** 6170 6171| 类型 | 说明 | 6172| -------------- | --------------------------------------------------------------- | 6173| Promise\<void> | Promise对象。当播放列表单项ID设置成功,无返回结果,否则返回错误对象。 | 6174 6175**错误码:** 6176 6177以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6178 6179| 错误码ID | 错误信息 | 6180| -------- | ---------------------------------------- | 6181| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6182| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6183| 6600102 | The session does not exist. | 6184| 6600103 | The session controller does not exist. | 6185 6186**示例:** 6187 6188```ts 6189import { BusinessError } from '@kit.BasicServicesKit'; 6190 6191let queueItemId = 0; 6192avsessionController.skipToQueueItem(queueItemId).then(() => { 6193 console.info('SkipToQueueItem successfully'); 6194}).catch((err: BusinessError) => { 6195 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 6196}); 6197``` 6198 6199### skipToQueueItem<sup>10+</sup> 6200 6201skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void 6202 6203设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过callback异步回调方式返回。 6204 6205**系统能力:** SystemCapability.Multimedia.AVSession.Core 6206 6207**参数:** 6208 6209| 参数名 | 类型 | 必填 | 说明 | 6210| -------- | --------------------- | ---- | ----------------------------------------------------------- | 6211| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | 6212| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 6213 6214**错误码:** 6215 6216以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6217 6218| 错误码ID | 错误信息 | 6219| -------- | ---------------------------------------- | 6220| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6221| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6222| 6600102 | The session does not exist. | 6223| 6600103 | The session controller does not exist. | 6224 6225**示例:** 6226 6227```ts 6228import { BusinessError } from '@kit.BasicServicesKit'; 6229 6230let queueItemId = 0; 6231avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => { 6232 if (err) { 6233 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 6234 } else { 6235 console.info('SkipToQueueItem successfully'); 6236 } 6237}); 6238``` 6239 6240### getOutputDevice<sup>10+</sup> 6241 6242getOutputDevice(): Promise\<OutputDeviceInfo> 6243 6244获取播放设备信息。结果通过Promise异步回调方式返回。 6245 6246**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6247 6248**系统能力:** SystemCapability.Multimedia.AVSession.Core 6249 6250**返回值:** 6251 6252| 类型 | 说明 | 6253| ----------------------------------------------- | --------------------------------- | 6254| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise对象,返回播放设备信息。 | 6255 6256**错误码:** 6257 6258以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6259 6260| 错误码ID | 错误信息 | 6261| -------- | ---------------------------------------- | 6262| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6263| 600103 | The session controller does not exist. | 6264 6265**示例:** 6266 6267```ts 6268import { BusinessError } from '@kit.BasicServicesKit'; 6269 6270avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => { 6271 console.info('GetOutputDevice : SUCCESS'); 6272}).catch((err: BusinessError) => { 6273 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 6274}); 6275``` 6276 6277### getOutputDevice<sup>10+</sup> 6278 6279getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 6280 6281获取播放设备信息。结果通过callback异步回调方式返回。 6282 6283**系统能力:** SystemCapability.Multimedia.AVSession.Core 6284 6285**参数:** 6286 6287| 参数名 | 类型 | 必填 | 说明 | 6288| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 6289| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是 | 回调函数,返回播放设备信息。 | 6290 6291**错误码:** 6292 6293以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6294 6295| 错误码ID | 错误信息 | 6296| -------- | ---------------------------------------- | 6297| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6298| 600103 | The session controller does not exist. | 6299 6300**示例:** 6301 6302```ts 6303import { BusinessError } from '@kit.BasicServicesKit'; 6304 6305avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => { 6306 if (err) { 6307 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 6308 } else { 6309 console.info('GetOutputDevice : SUCCESS'); 6310 } 6311}); 6312``` 6313 6314### sendAVKeyEvent<sup>10+</sup> 6315 6316sendAVKeyEvent(event: KeyEvent): Promise\<void> 6317 6318发送按键事件到控制器对应的会话。结果通过Promise异步回调方式返回。 6319 6320**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6321 6322**系统能力:** SystemCapability.Multimedia.AVSession.Core 6323 6324**参数:** 6325 6326| 参数名 | 类型 | 必填 | 说明 | 6327| ------ | ------------------------------------------------------------ | ---- | ---------- | 6328| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | 是 | 按键事件。 | 6329 6330**错误码:** 6331 6332以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6333 6334| 错误码ID | 错误信息 | 6335| -------- | ---------------------------------------- | 6336| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6337| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6338| 600102 | The session does not exist. | 6339| 600103 | The session controller does not exist. | 6340| 600105 | Invalid session command. | 6341| 600106 | The session is not activated. | 6342 6343**返回值:** 6344 6345| 类型 | 说明 | 6346| -------------- | ----------------------------- | 6347| Promise\<void> | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 | 6348 6349**示例:** 6350 6351```ts 6352import { Key, KeyEvent } from '@kit.InputKit'; 6353import { BusinessError } from '@kit.BasicServicesKit'; 6354 6355let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 6356let event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; 6357 6358 6359avsessionController.sendAVKeyEvent(event).then(() => { 6360 console.info('SendAVKeyEvent Successfully'); 6361}).catch((err: BusinessError) => { 6362 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 6363}); 6364``` 6365 6366### sendAVKeyEvent<sup>10+</sup> 6367 6368sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void 6369 6370发送按键事件到会话。结果通过callback异步回调方式返回。 6371 6372**系统能力:** SystemCapability.Multimedia.AVSession.Core 6373 6374**参数:** 6375 6376| 参数名 | 类型 | 必填 | 说明 | 6377| -------- | ------------------------------------------------------------ | ---- | ---------- | 6378| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | 是 | 按键事件。 | 6379| callback | AsyncCallback\<void> | 是 | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 | 6380 6381**错误码:** 6382 6383以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6384 6385| 错误码ID | 错误信息 | 6386| -------- | ---------------------------------------- | 6387| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6388| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6389| 600102 | The session does not exist. | 6390| 600103 | The session controller does not exist. | 6391| 600105 | Invalid session command. | 6392| 600106 | The session is not activated. | 6393 6394**示例:** 6395 6396```ts 6397import { Key, KeyEvent } from '@kit.InputKit'; 6398import { BusinessError } from '@kit.BasicServicesKit'; 6399 6400let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 6401let event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; 6402avsessionController.sendAVKeyEvent(event, (err: BusinessError) => { 6403 if (err) { 6404 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 6405 } else { 6406 console.info('SendAVKeyEvent Successfully'); 6407 } 6408}); 6409``` 6410 6411### getLaunchAbility<sup>10+</sup> 6412 6413getLaunchAbility(): Promise\<WantAgent> 6414 6415获取应用在会话中保存的WantAgent对象。结果通过Promise异步回调方式返回。 6416 6417**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6418 6419**系统能力:** SystemCapability.Multimedia.AVSession.Core 6420 6421**返回值:** 6422 6423| 类型 | 说明 | 6424| ------------------------------------------------------- | ------------------------------------------------------------ | 6425| Promise<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | Promise对象,返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 6426 6427**错误码:** 6428 6429以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6430 6431| 错误码ID | 错误信息 | 6432| -------- | ---------------------------------------- | 6433| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6434| 6600102 | The session does not exist. | 6435| 6600103 | The session controller does not exist. | 6436 6437**示例:** 6438 6439```ts 6440import { BusinessError } from '@kit.BasicServicesKit'; 6441 6442avsessionController.getLaunchAbility().then((agent: object) => { 6443 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 6444}).catch((err: BusinessError) => { 6445 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 6446}); 6447``` 6448 6449### getLaunchAbility<sup>10+</sup> 6450 6451getLaunchAbility(callback: AsyncCallback\<WantAgent>): void 6452 6453获取应用在会话中保存的WantAgent对象。结果通过callback异步回调方式返回。 6454 6455**系统能力:** SystemCapability.Multimedia.AVSession.Core 6456 6457**参数:** 6458 6459| 参数名 | 类型 | 必填 | 说明 | 6460| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6461| callback | AsyncCallback<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | 是 | 回调函数。返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 6462 6463**错误码:** 6464 6465以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6466 6467| 错误码ID | 错误信息 | 6468| -------- | ---------------------------------------- | 6469| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6470| 6600102 | The session does not exist. | 6471| 6600103 | The session controller does not exist. | 6472 6473**示例:** 6474 6475```ts 6476import { BusinessError } from '@kit.BasicServicesKit'; 6477 6478avsessionController.getLaunchAbility((err: BusinessError, agent: object) => { 6479 if (err) { 6480 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 6481 } else { 6482 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 6483 } 6484}); 6485``` 6486 6487### getRealPlaybackPositionSync<sup>10+</sup> 6488 6489getRealPlaybackPositionSync(): number 6490 6491获取当前播放位置。 6492 6493**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6494 6495**系统能力:** SystemCapability.Multimedia.AVSession.Core 6496 6497**返回值:** 6498 6499| 类型 | 说明 | 6500| ------ | ------------------ | 6501| number | 时间节点,毫秒数。 | 6502 6503**错误码:** 6504 6505以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6506 6507| 错误码ID | 错误信息 | 6508| -------- | ---------------------------------------- | 6509| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6510| 6600103 | The session controller does not exist. | 6511 6512**示例:** 6513 6514```ts 6515let time: number = avsessionController.getRealPlaybackPositionSync(); 6516``` 6517 6518### isActive<sup>10+</sup> 6519 6520isActive(): Promise\<boolean> 6521 6522获取会话是否被激活。结果通过Promise异步回调方式返回。 6523 6524**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6525 6526**系统能力:** SystemCapability.Multimedia.AVSession.Core 6527 6528**返回值:** 6529 6530| 类型 | 说明 | 6531| ----------------- | ------------------------------------------------------------ | 6532| Promise<boolean\> | Promise对象,返回会话是否为激活状态,true表示被激活,false表示禁用。 | 6533 6534**错误码:** 6535 6536以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6537 6538| 错误码ID | 错误信息 | 6539| -------- | ---------------------------------------- | 6540| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6541| 6600102 | The session does not exist. | 6542| 6600103 | The session controller does not exist. | 6543 6544**示例:** 6545 6546```ts 6547import { BusinessError } from '@kit.BasicServicesKit'; 6548 6549avsessionController.isActive().then((isActive: boolean) => { 6550 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6551}).catch((err: BusinessError) => { 6552 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6553}); 6554``` 6555 6556### isActive<sup>10+</sup> 6557 6558isActive(callback: AsyncCallback\<boolean>): void 6559 6560判断会话是否被激活。结果通过callback异步回调方式返回。 6561 6562**系统能力:** SystemCapability.Multimedia.AVSession.Core 6563 6564**参数:** 6565 6566| 参数名 | 类型 | 必填 | 说明 | 6567| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 6568| callback | AsyncCallback<boolean\> | 是 | 回调函数。返回会话是否为激活状态,true表示被激活,false表示禁用。 | 6569 6570**错误码:** 6571 6572以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6573 6574| 错误码ID | 错误信息 | 6575| -------- | ---------------------------------------- | 6576| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6577| 6600102 | The session does not exist. | 6578| 6600103 | The session controller does not exist. | 6579 6580**示例:** 6581 6582```ts 6583import { BusinessError } from '@kit.BasicServicesKit'; 6584 6585avsessionController.isActive((err: BusinessError, isActive: boolean) => { 6586 if (err) { 6587 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6588 } else { 6589 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6590 } 6591}); 6592``` 6593 6594### destroy<sup>10+</sup> 6595 6596destroy(): Promise\<void> 6597 6598销毁当前控制器,销毁后当前控制器不可再用。结果通过Promise异步回调方式返回。 6599 6600**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6601 6602**系统能力:** SystemCapability.Multimedia.AVSession.Core 6603 6604**返回值:** 6605 6606| 类型 | 说明 | 6607| -------------- | ----------------------------- | 6608| Promise\<void> | Promise对象。当控制器销毁成功,无返回结果,否则返回错误对象。 | 6609 6610**错误码:** 6611 6612以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6613 6614| 错误码ID | 错误信息 | 6615| -------- | ---------------------------------------- | 6616| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6617| 6600103 | The session controller does not exist. | 6618 6619**示例:** 6620 6621```ts 6622import { BusinessError } from '@kit.BasicServicesKit'; 6623 6624avsessionController.destroy().then(() => { 6625 console.info('Destroy : SUCCESS '); 6626}).catch((err: BusinessError) => { 6627 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6628}); 6629``` 6630 6631### destroy<sup>10+</sup> 6632 6633destroy(callback: AsyncCallback\<void>): void 6634 6635销毁当前控制器,销毁后当前控制器不可再用。结果通过callback异步回调方式返回。 6636 6637**系统能力:** SystemCapability.Multimedia.AVSession.Core 6638 6639**参数:** 6640 6641| 参数名 | 类型 | 必填 | 说明 | 6642| -------- | -------------------- | ---- | ---------- | 6643| callback | AsyncCallback\<void> | 是 | 回调函数。当控制器销毁成功,err为undefined,否则返回错误对象。 | 6644 6645**错误码:** 6646 6647以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6648 6649| 错误码ID | 错误信息 | 6650| -------- | ---------------------------------------- | 6651| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6652| 6600103 | The session controller does not exist. | 6653 6654**示例:** 6655 6656```ts 6657import { BusinessError } from '@kit.BasicServicesKit'; 6658 6659avsessionController.destroy((err: BusinessError) => { 6660 if (err) { 6661 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6662 } else { 6663 console.info('Destroy : SUCCESS '); 6664 } 6665}); 6666``` 6667 6668### getValidCommands<sup>10+</sup> 6669 6670getValidCommands(): Promise\<Array\<AVControlCommandType>> 6671 6672获取会话支持的有效命令。结果通过Promise异步回调方式返回。 6673 6674**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6675 6676**系统能力:** SystemCapability.Multimedia.AVSession.Core 6677 6678**返回值:** 6679 6680| 类型 | 说明 | 6681| ------------------------------------------------------------ | --------------------------------- | 6682| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise对象。返回有效命令的集合。 | 6683 6684**错误码:** 6685 6686以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6687 6688| 错误码ID | 错误信息 | 6689| -------- | ---------------------------------------- | 6690| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6691| 6600102 | The session does not exist. | 6692| 6600103 | The session controller does not exist. | 6693 6694**示例:** 6695 6696```ts 6697import { BusinessError } from '@kit.BasicServicesKit'; 6698 6699avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => { 6700 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6701}).catch((err: BusinessError) => { 6702 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6703}); 6704``` 6705 6706### getValidCommands<sup>10+</sup> 6707 6708getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void 6709 6710获取会话支持的有效命令。结果通过callback异步回调方式返回。 6711 6712**系统能力:** SystemCapability.Multimedia.AVSession.Core 6713 6714**参数:** 6715 6716| 参数名 | 类型 | 必填 | 说明 | 6717| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 6718| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | 是 | 回调函数,返回有效命令的集合。 | 6719 6720**错误码:** 6721 6722以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6723 6724| 错误码ID | 错误信息 | 6725| -------- | ---------------------------------------- | 6726| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6727| 6600102 | The session does not exist. | 6728| 6600103 | The session controller does not exist. | 6729 6730**示例:** 6731 6732```ts 6733import { BusinessError } from '@kit.BasicServicesKit'; 6734 6735avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => { 6736 if (err) { 6737 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6738 } else { 6739 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6740 } 6741}); 6742``` 6743 6744### sendControlCommand<sup>10+</sup> 6745 6746sendControlCommand(command: AVControlCommand): Promise\<void> 6747 6748通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 6749 6750> **说明:** 6751> 6752> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。 6753 6754**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6755 6756**系统能力:** SystemCapability.Multimedia.AVSession.Core 6757 6758**参数:** 6759 6760| 参数名 | 类型 | 必填 | 说明 | 6761| ------- | ------------------------------------- | ---- | ------------------------------ | 6762| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 6763 6764**返回值:** 6765 6766| 类型 | 说明 | 6767| -------------- | ----------------------------- | 6768| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 6769 6770**错误码:** 6771 6772以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6773 6774| 错误码ID | 错误信息 | 6775| -------- | ---------------------------------------- | 6776| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6777| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6778| 6600102 | The session does not exist. | 6779| 6600103 | The session controller does not exist. | 6780| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6781| 6600106 | The session is not activated. | 6782| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6783 6784**示例:** 6785 6786```ts 6787import { BusinessError } from '@kit.BasicServicesKit'; 6788 6789let avCommand: avSession.AVControlCommand = {command:'play'}; 6790avsessionController.sendControlCommand(avCommand).then(() => { 6791 console.info('SendControlCommand successfully'); 6792}).catch((err: BusinessError) => { 6793 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6794}); 6795``` 6796 6797### sendControlCommand<sup>10+</sup> 6798 6799sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void 6800 6801通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 6802 6803> **说明:** 6804> 6805> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。 6806 6807**系统能力:** SystemCapability.Multimedia.AVSession.Core 6808 6809**参数:** 6810 6811| 参数名 | 类型 | 必填 | 说明 | 6812| -------- | ------------------------------------- | ---- | ------------------------------ | 6813| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 6814| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 6815 6816**错误码:** 6817 6818以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6819 6820| 错误码ID | 错误信息 | 6821| -------- | ------------------------------- | 6822| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6823| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6824| 6600102 | The session does not exist. | 6825| 6600103 | The session controller does not exist. | 6826| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6827| 6600106 | The session is not activated. | 6828| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6829 6830**示例:** 6831 6832```ts 6833import { BusinessError } from '@kit.BasicServicesKit'; 6834 6835let avCommand: avSession.AVControlCommand = {command:'play'}; 6836avsessionController.sendControlCommand(avCommand, (err: BusinessError) => { 6837 if (err) { 6838 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6839 } else { 6840 console.info('SendControlCommand successfully'); 6841 } 6842}); 6843``` 6844 6845### sendCommonCommand<sup>10+</sup> 6846 6847sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void> 6848 6849通过会话控制器发送自定义控制命令到其对应的会话。结果通过Promise异步回调方式返回。 6850 6851**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6852 6853**系统能力:** SystemCapability.Multimedia.AVSession.Core 6854 6855**参数:** 6856 6857| 参数名 | 类型 | 必填 | 说明 | 6858| ------- | ------------------------------------- | ---- | ------------------------------ | 6859| command | string | 是 | 需要设置的自定义控制命令的名称。 | 6860| args | {[key: string]: Object} | 是 | 需要传递的控制命令键值对。 | 6861 6862> **说明:** 6863> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 6864 6865**返回值:** 6866 6867| 类型 | 说明 | 6868| -------------- | ----------------------------- | 6869| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 6870 6871**错误码:** 6872 6873以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6874 6875| 错误码ID | 错误信息 | 6876| -------- | ---------------------------------------- | 6877| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6878| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6879| 6600102 | The session does not exist. | 6880| 6600103 | The session controller does not exist. | 6881| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6882| 6600106 | The session is not activated. | 6883| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6884 6885**示例:** 6886 6887```ts 6888import { BusinessError } from '@kit.BasicServicesKit'; 6889import { avSession } from '@kit.AVSessionKit'; 6890 6891let tag: string = "createNewSession"; 6892let sessionId: string = ""; 6893let controller:avSession.AVSessionController | undefined = undefined; 6894avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 6895 currentAVSession = data; 6896 sessionId = currentAVSession.sessionId; 6897 controller = await currentAVSession.getController(); 6898 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 6899}).catch((err: BusinessError) => { 6900 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 6901}); 6902let commandName = "my_command"; 6903if (controller !== undefined) { 6904 (controller as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => { 6905 console.info('SendCommonCommand successfully'); 6906 }).catch((err: BusinessError) => { 6907 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6908 }) 6909} 6910``` 6911 6912### sendCommonCommand<sup>10+</sup> 6913 6914sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 6915 6916通过会话控制器发送自定义命令到其对应的会话。结果通过callback异步回调方式返回。 6917 6918**系统能力:** SystemCapability.Multimedia.AVSession.Core 6919 6920**参数:** 6921 6922| 参数名 | 类型 | 必填 | 说明 | 6923| ------- | ------------------------------------- | ---- | ------------------------------ | 6924| command | string | 是 | 需要设置的自定义控制命令的名称。 | 6925| args | {[key: string]: Object} | 是 | 需要传递的控制命令键值对。 | 6926| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 6927 6928> **说明:** 6929> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 6930 6931**错误码:** 6932 6933以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6934 6935| 错误码ID | 错误信息 | 6936| -------- | ------------------------------- | 6937| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.| 6938| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6939| 6600102 | The session does not exist. | 6940| 6600103 | The session controller does not exist. | 6941| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6942| 6600106 | The session is not activated. | 6943| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6944 6945**示例:** 6946 6947```ts 6948import { BusinessError } from '@kit.BasicServicesKit'; 6949import { avSession } from '@kit.AVSessionKit'; 6950 6951let tag: string = "createNewSession"; 6952let sessionId: string = ""; 6953let controller:avSession.AVSessionController | undefined = undefined; 6954avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 6955 currentAVSession = data; 6956 sessionId = currentAVSession.sessionId; 6957 controller = await currentAVSession.getController(); 6958 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 6959}).catch((err: BusinessError) => { 6960 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 6961}); 6962let commandName = "my_command"; 6963if (controller !== undefined) { 6964 (controller as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => { 6965 if (err) { 6966 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6967 } 6968 }) 6969} 6970``` 6971 6972### getExtras<sup>10+</sup> 6973 6974getExtras(): Promise\<{[key: string]: Object}> 6975 6976获取媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。 6977 6978**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6979 6980**系统能力:** SystemCapability.Multimedia.AVSession.Core 6981 6982**返回值:** 6983 6984| 类型 | 说明 | 6985| ----------------------------------- | ----------------------------- | 6986| Promise<{[key: string]: Object}\> | Promise对象,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | 6987 6988**错误码:** 6989 6990以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6991 6992| 错误码ID | 错误信息 | 6993| -------- | ---------------------------------------- | 6994| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6995| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6996| 6600102 | The session does not exist. | 6997| 6600103 | The session controller does not exist. | 6998| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6999| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 7000 7001**示例:** 7002 7003```ts 7004import { BusinessError } from '@kit.BasicServicesKit'; 7005import { avSession } from '@kit.AVSessionKit'; 7006 7007let tag: string = "createNewSession"; 7008let sessionId: string = ""; 7009let controller:avSession.AVSessionController | undefined = undefined; 7010avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7011 currentAVSession = data; 7012 sessionId = currentAVSession.sessionId; 7013 controller = await currentAVSession.getController(); 7014 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7015}).catch((err: BusinessError) => { 7016 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7017}); 7018if (controller !== undefined) { 7019 (controller as avSession.AVSessionController).getExtras().then((extras) => { 7020 console.info(`getExtras : SUCCESS : ${extras}`); 7021 }).catch((err: BusinessError) => { 7022 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 7023 }); 7024} 7025 7026``` 7027 7028### getExtras<sup>10+</sup> 7029 7030getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void 7031 7032获取媒体提供方设置的自定义媒体数据包,结果通过callback异步回调方式返回。 7033 7034**系统能力:** SystemCapability.Multimedia.AVSession.Core 7035 7036**参数:** 7037 7038| 参数名 | 类型 | 必填 | 说明 | 7039| -------- | ----------------------------------------- | ---- | -------------------------- | 7040| callback | AsyncCallback<{[key: string]: Object}\> | 是 | 回调函数,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | 7041 7042**错误码:** 7043 7044以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7045 7046| 错误码ID | 错误信息 | 7047| -------- | ---------------------------------------- | 7048| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 7049| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7050| 6600102 | The session does not exist. | 7051| 6600103 | The session controller does not exist. | 7052| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 7053| 6600107 |Too many commands or events.Controls the frequency of sending self-query and control commands. | 7054 7055**示例:** 7056 7057```ts 7058import { BusinessError } from '@kit.BasicServicesKit'; 7059import { avSession } from '@kit.AVSessionKit'; 7060 7061let tag: string = "createNewSession"; 7062let sessionId: string = ""; 7063let controller:avSession.AVSessionController | undefined = undefined; 7064avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7065 currentAVSession = data; 7066 sessionId = currentAVSession.sessionId; 7067 controller = await currentAVSession.getController(); 7068 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7069}).catch((err: BusinessError) => { 7070 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7071}); 7072if (controller !== undefined) { 7073 (controller as avSession.AVSessionController).getExtras((err, extras) => { 7074 if (err) { 7075 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 7076 } else { 7077 console.info(`getExtras : SUCCESS : ${extras}`); 7078 } 7079 }); 7080} 7081``` 7082 7083### getExtrasWithEvent<sup>18+</sup> 7084 7085getExtrasWithEvent(extraEvent: string): Promise\<ExtraInfo> 7086 7087根据远端分布式事件类型,获取远端分布式媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。 7088 7089**系统能力:** SystemCapability.Multimedia.AVSession.Core 7090 7091**参数:** 7092 7093| 参数名 | 类型 | 必填 | 说明 | 7094| -------- | ----------------------------------------- | ---- | -------------------------- | 7095| extraEvent | string | 是 | 远端分布式事件类型。<br>当前支持的事件类型包括:<br>'AUDIO_GET_VOLUME':获取远端设备音量,<br>'AUDIO_GET_AVAILABLE_DEVICES':获取远端所有可连接设备,<br>'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO':获取远端实际发声设备。 | 7096 7097**返回值:** 7098 7099| 类型 | 说明 | 7100| ----------------------------------- | ----------------------------- | 7101| Promise<[ExtraInfo](#extrainfo18)\> | Promise对象,返回远端分布式媒体提供方设置的自定义媒体数据包。<br>参数ExtraInfo支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 | 7102 7103**错误码:** 7104 7105以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7106 7107| 错误码ID | 错误信息 | 7108| -------- | ---------------------------------------- | 7109| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7110| 6600102 | The session does not exist. | 7111| 6600103 | The session controller does not exist. | 7112| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 7113 7114**示例:** 7115 7116```ts 7117import { BusinessError } from '@kit.BasicServicesKit'; 7118 7119let controller: avSession.AVSessionController | ESObject; 7120const COMMON_COMMAND_STRING_1 = 'AUDIO_GET_VOLUME'; 7121const COMMON_COMMAND_STRING_2 = 'AUDIO_GET_AVAILABLE_DEVICES'; 7122const COMMON_COMMAND_STRING_3 = 'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO'; 7123if (controller !== undefined) { 7124 controller.getExtrasWithEvent(COMMON_COMMAND_STRING_1).then(() => { 7125 console.info(`${[COMMON_COMMAND_STRING_1]}`); 7126 }).catch((err: BusinessError) => { 7127 console.error(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`); 7128 }) 7129 7130 controller.getExtrasWithEvent(COMMON_COMMAND_STRING_2).then(() => { 7131 console.info(`${[COMMON_COMMAND_STRING_2]}`); 7132 }).catch((err: BusinessError) => { 7133 console.error(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`); 7134 }) 7135 7136 controller.getExtrasWithEvent(COMMON_COMMAND_STRING_3).then(() => { 7137 console.info(`${[COMMON_COMMAND_STRING_3]}`); 7138 }).catch((err: BusinessError) => { 7139 console.error(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`); 7140 }) 7141} 7142``` 7143 7144### on('metadataChange')<sup>10+</sup> 7145 7146on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void) 7147 7148设置元数据变化的监听事件。 7149 7150**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7151 7152**系统能力:** SystemCapability.Multimedia.AVSession.Core 7153 7154**参数:** 7155 7156| 参数名 | 类型 | 必填 | 说明 | 7157| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7158| type | string | 是 | 事件回调类型,支持事件`'metadataChange'`:当元数据变化时,触发该事件。 | 7159| filter | Array\<keyof [AVMetadata](#avmetadata10)\> | 'all' | 是 | 'all' 表示关注元数据所有字段变化;Array<keyof [AVMetadata](#avmetadata10)\> 表示关注Array中的字段变化。 | 7160| callback | (data: [AVMetadata](#avmetadata10)) => void | 是 | 回调函数,参数data是变化后的元数据。 | 7161 7162**错误码:** 7163 7164以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7165 7166| 错误码ID | 错误信息 | 7167| -------- | ------------------------------ | 7168| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7169| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7170| 6600103 | The session controller does not exist. | 7171 7172**示例:** 7173 7174```ts 7175avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => { 7176 console.info(`on metadataChange assetId : ${metadata.assetId}`); 7177}); 7178 7179avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => { 7180 console.info(`on metadataChange assetId : ${metadata.assetId}`); 7181}); 7182 7183``` 7184 7185### off('metadataChange')<sup>10+</sup> 7186 7187off(type: 'metadataChange', callback?: (data: AVMetadata) => void) 7188 7189媒体控制器取消监听元数据变化的事件。 7190 7191**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7192 7193**系统能力:** SystemCapability.Multimedia.AVSession.Core 7194 7195**参数:** 7196 7197| 参数名 | 类型 | 必填 | 说明 | 7198| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | 7199| type | string | 是 | 取消对应的监听事件,支持事件`'metadataChange'`。 | 7200| callback | (data: [AVMetadata](#avmetadata10)) => void | 否 | 回调函数,参数data是变化后的元数据。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7201 7202**错误码:** 7203 7204以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7205 7206| 错误码ID | 错误信息 | 7207| -------- | ---------------- | 7208| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7209| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7210| 6600103 | The session controller does not exist. | 7211 7212**示例:** 7213 7214```ts 7215avsessionController.off('metadataChange'); 7216``` 7217 7218### on('playbackStateChange')<sup>10+</sup> 7219 7220on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void) 7221 7222设置播放状态变化的监听事件。 7223 7224**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7225 7226**系统能力:** SystemCapability.Multimedia.AVSession.Core 7227 7228**参数:** 7229 7230| 参数名 | 类型 | 必填 | 说明 | 7231| --------| -----------|-----|------------| 7232| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | 7233| filter | Array\<keyof [AVPlaybackState](#avplaybackstate10)\> | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array<keyof [AVPlaybackState](#avplaybackstate10)\> 表示关注Array中的字段变化。 | 7234| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。| 7235 7236**错误码:** 7237 7238以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7239 7240| 错误码ID | 错误信息 | 7241| -------- | ------------------------------ | 7242| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7243| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7244| 6600103 | The session controller does not exist. | 7245 7246**示例:** 7247 7248```ts 7249avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 7250 console.info(`on playbackStateChange state : ${playbackState.state}`); 7251}); 7252 7253avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => { 7254 console.info(`on playbackStateChange state : ${playbackState.state}`); 7255}); 7256``` 7257 7258### off('playbackStateChange')<sup>10+</sup> 7259 7260off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) 7261 7262媒体控制器取消监听播放状态变化的事件。 7263 7264**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7265 7266**系统能力:** SystemCapability.Multimedia.AVSession.Core 7267 7268**参数:** 7269 7270| 参数名 | 类型 | 必填 | 说明 | 7271| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7272| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | 7273| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7274 7275**错误码:** 7276 7277以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7278 7279| 错误码ID | 错误信息 | 7280| -------- | ---------------- | 7281| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7282| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7283| 6600103 | The session controller does not exist. | 7284 7285**示例:** 7286 7287```ts 7288avsessionController.off('playbackStateChange'); 7289``` 7290 7291### on('callMetadataChange')<sup>11+</sup> 7292 7293on(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void 7294 7295设置通话元数据变化的监听事件。 7296 7297**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7298 7299**系统能力:** SystemCapability.Multimedia.AVSession.Core 7300 7301**参数:** 7302 7303| 参数名 | 类型 | 必填 | 说明 | 7304| --------| -----------|-----|------------| 7305| type | string | 是 | 事件回调类型,支持事件`'callMetadataChange'`:当通话元数据变化时,触发该事件。 | 7306| filter | Array\<keyof [CallMetadata](#callmetadata11)\> | 'all' | 是 | 'all' 表示关注通话元数据所有字段变化;Array<keyof [CallMetadata](#callmetadata11)\> 表示关注Array中的字段变化。 | 7307| callback | Callback<[CallMetadata](#callmetadata11)\> | 是 | 回调函数,参数callmetadata是变化后的通话元数据。| 7308 7309**错误码:** 7310 7311以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7312 7313| 错误码ID | 错误信息 | 7314| -------- | ------------------------------ | 7315| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7316| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7317| 6600103 | The session controller does not exist. | 7318 7319**示例:** 7320 7321```ts 7322avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => { 7323 console.info(`on callMetadataChange state : ${callmetadata.name}`); 7324}); 7325 7326avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => { 7327 console.info(`on callMetadataChange state : ${callmetadata.name}`); 7328}); 7329``` 7330 7331### off('callMetadataChange')<sup>11+</sup> 7332 7333off(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void 7334 7335取消设置通话元数据变化的监听事件。 7336 7337**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7338 7339**系统能力:** SystemCapability.Multimedia.AVSession.Core 7340 7341**参数:** 7342 7343| 参数名 | 类型 | 必填 | 说明 | 7344| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7345| type | string | 是 | 取消对应的监听事件,支持事件`'callMetadataChange'`。 | 7346| callback | Callback<[CallMetadata](#callmetadata11)\> | 否 | 回调函数,参数calldata是变化后的通话原数据。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7347 7348**错误码:** 7349 7350以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7351 7352| 错误码ID | 错误信息 | 7353| -------- | ---------------- | 7354| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7355| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7356| 6600103 | The session controller does not exist. | 7357 7358**示例:** 7359 7360```ts 7361avsessionController.off('callMetadataChange'); 7362``` 7363 7364### on('callStateChange')<sup>11+</sup> 7365 7366on(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void 7367 7368设置通话状态变化的监听事件。 7369 7370**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7371 7372**系统能力:** SystemCapability.Multimedia.AVSession.Core 7373 7374**参数:** 7375 7376| 参数名 | 类型 | 必填 | 说明 | 7377| --------| -----------|-----|------------| 7378| type | string | 是 | 事件回调类型,支持事件`'callStateChange'`:当通话状态变化时,触发该事件。 | 7379| filter | Array<keyof [AVCallState](#avcallstate11)\> | 'all' | 是 | 'all' 表示关注通话状态所有字段变化;Array<keyof [AVCallState](#avcallstate11)\> 表示关注Array中的字段变化。 | 7380| callback | Callback<[AVCallState](#avcallstate11)\> | 是 | 回调函数,参数callstate是变化后的通话状态。| 7381 7382**错误码:** 7383 7384以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7385 7386| 错误码ID | 错误信息 | 7387| -------- | ------------------------------ | 7388| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7389| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7390| 6600103 | The session controller does not exist. | 7391 7392**示例:** 7393 7394```ts 7395avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => { 7396 console.info(`on callStateChange state : ${callstate.state}`); 7397}); 7398 7399avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => { 7400 console.info(`on callStateChange state : ${callstate.state}`); 7401}); 7402``` 7403 7404### off('callStateChange')<sup>11+</sup> 7405 7406off(type: 'callStateChange', callback?: Callback\<AVCallState>): void 7407 7408取消设置通话状态变化的监听事件。 7409 7410**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7411 7412**系统能力:** SystemCapability.Multimedia.AVSession.Core 7413 7414**参数:** 7415 7416| 参数名 | 类型 | 必填 | 说明 | 7417| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7418| type | string | 是 | 取消对应的监听事件,支持事件`'callStateChange'`。 | 7419| callback | Callback<[AVCallState](#avcallstate11)\> | 否 | 回调函数,参数callstate是变化后的通话状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7420 7421**错误码:** 7422 7423以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7424 7425| 错误码ID | 错误信息 | 7426| -------- | ---------------- | 7427| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7428| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7429| 6600103 | The session controller does not exist. | 7430 7431**示例:** 7432 7433```ts 7434avsessionController.off('callMetadataChange'); 7435``` 7436 7437### on('sessionDestroy')<sup>10+</sup> 7438 7439on(type: 'sessionDestroy', callback: () => void) 7440 7441会话销毁的监听事件。 7442 7443**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7444 7445**系统能力:** SystemCapability.Multimedia.AVSession.Core 7446 7447**参数:** 7448 7449| 参数名 | 类型 | 必填 | 说明 | 7450| -------- | ---------- | ---- | ------------------------------------------------------------ | 7451| type | string | 是 | 事件回调类型,支持事件`'sessionDestroy'`:当检测到会话销毁时,触发该事件)。 | 7452| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 7453 7454**错误码:** 7455 7456以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7457 7458| 错误码ID | 错误信息 | 7459| -------- | ------------------------------ | 7460| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7461| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7462| 6600103 | The session controller does not exist. | 7463 7464**示例:** 7465 7466```ts 7467avsessionController.on('sessionDestroy', () => { 7468 console.info('on sessionDestroy : SUCCESS '); 7469}); 7470``` 7471 7472### off('sessionDestroy')<sup>10+</sup> 7473 7474off(type: 'sessionDestroy', callback?: () => void) 7475 7476媒体控制器取消监听会话的销毁事件。 7477 7478**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7479 7480**系统能力:** SystemCapability.Multimedia.AVSession.Core 7481 7482**参数:** 7483 7484| 参数名 | 类型 | 必填 | 说明 | 7485| -------- | ---------- | ---- | ----------------------------------------------------- | 7486| type | string | 是 | 取消对应的监听事件,支持事件`'sessionDestroy'`。 | 7487| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7488 7489**错误码:** 7490 7491以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7492 7493| 错误码ID | 错误信息 | 7494| -------- | ---------------- | 7495| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7496| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7497| 6600103 | The session controller does not exist. | 7498 7499**示例:** 7500 7501```ts 7502avsessionController.off('sessionDestroy'); 7503``` 7504 7505### on('activeStateChange')<sup>10+</sup> 7506 7507on(type: 'activeStateChange', callback: (isActive: boolean) => void) 7508 7509会话的激活状态的监听事件。 7510 7511**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7512 7513**系统能力:** SystemCapability.Multimedia.AVSession.Core 7514 7515**参数:** 7516 7517| 参数名 | 类型 | 必填 | 说明 | 7518| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 7519| type | string | 是 | 事件回调类型,支持事件`'activeStateChange'`:当检测到会话的激活状态发生改变时,触发该事件。 | 7520| callback | (isActive: boolean) => void | 是 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。 | 7521 7522**错误码:** 7523 7524以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7525 7526| 错误码ID | 错误信息 | 7527| -------- | ----------------------------- | 7528| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7529| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7530| 6600103 |The session controller does not exist. | 7531 7532**示例:** 7533 7534```ts 7535avsessionController.on('activeStateChange', (isActive: boolean) => { 7536 console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); 7537}); 7538``` 7539 7540### off('activeStateChange')<sup>10+</sup> 7541 7542off(type: 'activeStateChange', callback?: (isActive: boolean) => void) 7543 7544媒体控制器取消监听会话激活状态变化的事件。 7545 7546**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7547 7548**系统能力:** SystemCapability.Multimedia.AVSession.Core 7549 7550**参数:** 7551 7552| 参数名 | 类型 | 必填 | 说明 | 7553| -------- | --------------------------- | ---- | ----------------------------------------------------- | 7554| type | string | 是 | 取消对应的监听事件,支持事件`'activeStateChange'`。 | 7555| callback | (isActive: boolean) => void | 否 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7556 7557**错误码:** 7558 7559以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7560 7561| 错误码ID | 错误信息 | 7562| -------- | ---------------- | 7563| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7564| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7565| 6600103 | The session controller does not exist. | 7566 7567**示例:** 7568 7569```ts 7570avsessionController.off('activeStateChange'); 7571``` 7572 7573### on('validCommandChange')<sup>10+</sup> 7574 7575on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void) 7576 7577会话支持的有效命令变化监听事件。 7578 7579**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7580 7581**系统能力:** SystemCapability.Multimedia.AVSession.Core 7582 7583**参数:** 7584 7585| 参数名 | 类型 | 必填 | 说明 | 7586| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7587| type | string | 是 | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 | 7588| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 是 | 回调函数。参数commands是有效命令的集合。 | 7589 7590**错误码:** 7591 7592以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7593 7594| 错误码ID | 错误信息 | 7595| -------- | ------------------------------ | 7596| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7597| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7598| 6600103 | The session controller does not exist. | 7599 7600**示例:** 7601 7602```ts 7603avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => { 7604 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 7605 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 7606}); 7607``` 7608 7609### off('validCommandChange')<sup>10+</sup> 7610 7611off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void) 7612 7613媒体控制器取消监听会话有效命令变化的事件。 7614 7615**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7616 7617**系统能力:** SystemCapability.Multimedia.AVSession.Core 7618 7619**参数:** 7620 7621| 参数名 | 类型 | 必填 | 说明 | 7622| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 7623| type | string | 是 | 取消对应的监听事件,支持事件`'validCommandChange'`。 | 7624| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 否 | 回调函数。参数commands是有效命令的集合。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7625 7626**错误码:** 7627 7628以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7629 7630| 错误码ID | 错误信息 | 7631| -------- | ---------------- | 7632| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7633| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7634| 6600103 | The session controller does not exist. | 7635 7636**示例:** 7637 7638```ts 7639avsessionController.off('validCommandChange'); 7640``` 7641 7642### on('outputDeviceChange')<sup>10+</sup> 7643 7644on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7645 7646设置播放设备变化的监听事件。 7647 7648**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7649 7650**系统能力:** SystemCapability.Multimedia.AVSession.Core 7651 7652**参数:** 7653 7654| 参数名 | 类型 | 必填 | 说明 | 7655| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 7656| type | string | 是 | 事件回调类型,支持事件为`'outputDeviceChange'`:当播放设备变化时,触发该事件)。 | 7657| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是 | 回调函数,参数device是设备相关信息。 | 7658 7659**错误码:** 7660 7661以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7662 7663| 错误码ID | 错误信息 | 7664| -------- | ----------------------- | 7665| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7666| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7667| 6600103 | The session controller does not exist. | 7668 7669**示例:** 7670 7671```ts 7672avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 7673 console.info(`on outputDeviceChange state: ${state}, device : ${device}`); 7674}); 7675``` 7676 7677### off('outputDeviceChange')<sup>10+</sup> 7678 7679off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7680 7681媒体控制器取消监听分布式设备变化的事件。 7682 7683**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7684 7685**系统能力:** SystemCapability.Multimedia.AVSession.Core 7686 7687**参数:** 7688 7689| 参数名 | 类型 | 必填 | 说明 | 7690| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 7691| type | string | 是 | 取消对应的监听事件,支持事件`'outputDeviceChange'`。 | 7692| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否 | 回调函数,参数device是设备相关信息。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7693 7694**错误码:** 7695 7696以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7697 7698| 错误码ID | 错误信息 | 7699| -------- | ---------------- | 7700| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7701| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7702| 6600103 | The session controller does not exist. | 7703 7704**示例:** 7705 7706```ts 7707avsessionController.off('outputDeviceChange'); 7708``` 7709 7710### on('sessionEvent')<sup>10+</sup> 7711 7712on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key: string]: Object}) => void): void 7713 7714媒体控制器设置会话自定义事件变化的监听器。 7715 7716**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7717 7718**系统能力:** SystemCapability.Multimedia.AVSession.Core 7719 7720**参数:** 7721 7722| 参数名 | 类型 | 必填 | 说明 | 7723| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7724| type | string | 是 | 事件回调类型,支持事件`'sessionEvent'`:当会话事件变化时,触发该事件。 | 7725| callback | (sessionEvent: string, args: {[key: string]: Object}) => void | 是 | 回调函数,sessionEvent为变化的会话事件名,args为事件的参数。 | 7726 7727**错误码:** 7728 7729以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7730 7731| 错误码ID | 错误信息 | 7732| -------- | ------------------------------ | 7733| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7734| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7735| 6600103 | The session controller does not exist. | 7736 7737**示例:** 7738 7739```ts 7740import { BusinessError } from '@kit.BasicServicesKit'; 7741import { avSession } from '@kit.AVSessionKit'; 7742 7743let tag: string = "createNewSession"; 7744let sessionId: string = ""; 7745let controller:avSession.AVSessionController | undefined = undefined; 7746avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7747 currentAVSession = data; 7748 sessionId = currentAVSession.sessionId; 7749 controller = await currentAVSession.getController(); 7750 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7751}).catch((err: BusinessError) => { 7752 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7753}); 7754if (controller !== undefined) { 7755 (controller as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => { 7756 console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); 7757 }); 7758} 7759``` 7760 7761### off('sessionEvent')<sup>10+</sup> 7762 7763off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key: string]: Object}) => void): void 7764 7765媒体控制器取消监听会话事件的变化通知。 7766 7767**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7768 7769**系统能力:** SystemCapability.Multimedia.AVSession.Core 7770 7771**参数:** 7772 7773| 参数名 | 类型 | 必填 | 说明 | 7774| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7775| type | string | 是 | 取消对应的监听事件,支持事件`'sessionEvent'`。 | 7776| callback | (sessionEvent: string, args: {[key: string]: Object}) => void | 否 | 回调函数,参数sessionEvent是变化的事件名,args为事件的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对sessionEvent事件的监听。 | 7777 7778**错误码:** 7779 7780以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7781 7782| 错误码ID | 错误信息 | 7783| -------- | ---------------- | 7784| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7785| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7786| 6600103 | The session controller does not exist. | 7787 7788**示例:** 7789 7790```ts 7791avsessionController.off('sessionEvent'); 7792``` 7793 7794### on('queueItemsChange')<sup>10+</sup> 7795 7796on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7797 7798媒体控制器设置会话自定义播放列表变化的监听器。 7799 7800**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7801 7802**系统能力:** SystemCapability.Multimedia.AVSession.Core 7803 7804**参数:** 7805 7806| 参数名 | 类型 | 必填 | 说明 | 7807| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | 7808| type | string | 是 | 事件回调类型,支持事件`'queueItemsChange'`:当session修改播放列表时,触发该事件。 | 7809| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 是 | 回调函数,items为变化的播放列表。 | 7810 7811**错误码:** 7812 7813以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7814 7815| 错误码ID | 错误信息 | 7816| -------- | ------------------------------ | 7817| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7818| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7819| 6600103 | The session controller does not exist. | 7820 7821**示例:** 7822 7823```ts 7824avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => { 7825 console.info(`OnQueueItemsChange, items length is ${items.length}`); 7826}); 7827``` 7828 7829### off('queueItemsChange')<sup>10+</sup> 7830 7831off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7832 7833媒体控制器取消监听播放列表变化的事件。 7834 7835**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7836 7837**系统能力:** SystemCapability.Multimedia.AVSession.Core 7838 7839**参数:** 7840 7841| 参数名 | 类型 | 必填 | 说明 | 7842| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | 7843| type | string | 是 | 取消对应的监听事件,支持事件`'queueItemsChange'`。 | 7844| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 否 | 回调函数,参数items是变化的播放列表。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7845 7846**错误码:** 7847 7848以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7849 7850| 错误码ID | 错误信息 | 7851| -------- | ---------------- | 7852| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7853| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7854| 6600103 | The session controller does not exist. | 7855 7856**示例:** 7857 7858```ts 7859avsessionController.off('queueItemsChange'); 7860``` 7861 7862### on('queueTitleChange')<sup>10+</sup> 7863 7864on(type: 'queueTitleChange', callback: (title: string) => void): void 7865 7866媒体控制器设置会话自定义播放列表的名称变化的监听器。 7867 7868**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7869 7870**系统能力:** SystemCapability.Multimedia.AVSession.Core 7871 7872**参数:** 7873 7874| 参数名 | 类型 | 必填 | 说明 | 7875| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | 7876| type | string | 是 | 事件回调类型,支持事件`'queueTitleChange'`:当session修改播放列表名称时,触发该事件。 | 7877| callback | (title: string) => void | 是 | 回调函数,title为变化的播放列表名称。 | 7878 7879**错误码:** 7880 7881以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7882 7883| 错误码ID | 错误信息 | 7884| -------- | ------------------------------ | 7885| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7886| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7887| 6600103 | The session controller does not exist. | 7888 7889**示例:** 7890 7891```ts 7892avsessionController.on('queueTitleChange', (title: string) => { 7893 console.info(`queueTitleChange, title is ${title}`); 7894}); 7895``` 7896 7897### off('queueTitleChange')<sup>10+</sup> 7898 7899off(type: 'queueTitleChange', callback?: (title: string) => void): void 7900 7901媒体控制器取消监听播放列表名称变化的事件。 7902 7903**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7904 7905**系统能力:** SystemCapability.Multimedia.AVSession.Core 7906 7907**参数:** 7908 7909| 参数名 | 类型 | 必填 | 说明 | 7910| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7911| type | string | 是 | 取消对应的监听事件,支持事件`'queueTitleChange'`。 | 7912| callback | (title: string) => void | 否 | 回调函数,参数items是变化的播放列表名称。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7913 7914**错误码:** 7915 7916以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7917 7918| 错误码ID | 错误信息 | 7919| -------- | ---------------- | 7920| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7921| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7922| 6600103 | The session controller does not exist. | 7923 7924**示例:** 7925 7926```ts 7927avsessionController.off('queueTitleChange'); 7928``` 7929 7930### on('extrasChange')<sup>10+</sup> 7931 7932on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void 7933 7934媒体控制器设置自定义媒体数据包事件变化的监听器。 7935 7936**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7937 7938**系统能力:** SystemCapability.Multimedia.AVSession.Core 7939 7940**参数:** 7941 7942| 参数名 | 类型 | 必填 | 说明 | 7943| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7944| type | string | 是 | 事件回调类型,支持事件`'extrasChange'`:当媒体提供方设置自定义媒体数据包时,触发该事件。 | 7945| callback | (extras: {[key:string]: Object}) => void | 是 | 回调函数,extras为媒体提供方新设置的自定义媒体数据包,该自定义媒体数据包与dispatchSessionEvent方法设置的数据包完全一致。 | 7946 7947**错误码:** 7948 7949以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7950 7951| 错误码ID | 错误信息 | 7952| -------- | ------------------------------ | 7953| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7954| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7955| 6600103 | The session controller does not exist. | 7956 7957**示例:** 7958 7959```ts 7960import { BusinessError } from '@kit.BasicServicesKit'; 7961import { avSession } from '@kit.AVSessionKit'; 7962 7963let tag: string = "createNewSession"; 7964let sessionId: string = ""; 7965let controller:avSession.AVSessionController | undefined = undefined; 7966avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7967 currentAVSession = data; 7968 sessionId = currentAVSession.sessionId; 7969 controller = await currentAVSession.getController(); 7970 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7971}).catch((err: BusinessError) => { 7972 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7973}); 7974if (controller !== undefined) { 7975 (controller as avSession.AVSessionController).on('extrasChange', (extras) => { 7976 console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); 7977 }); 7978} 7979``` 7980 7981### off('extrasChange')<sup>10+</sup> 7982 7983off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void 7984 7985媒体控制器取消监听自定义媒体数据包变化事件。 7986 7987**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7988 7989**系统能力:** SystemCapability.Multimedia.AVSession.Core 7990 7991**参数:** 7992 7993| 参数名 | 类型 | 必填 | 说明 | 7994| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7995| type | string | 是 | 取消对应的监听事件,支持事件`'extrasChange'`。 | 7996| callback | (extras: {[key:string]: Object}) => void | 否 | 注册监听事件时的回调函数。<br>该参数为可选参数,若不填写该参数,则认为取消会话所有与此事件相关的监听。 | 7997 7998**错误码:** 7999 8000以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8001 8002| 错误码ID | 错误信息 | 8003| -------- | ---------------- | 8004| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8005| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8006| 6600103 | The session controller does not exist. | 8007 8008**示例:** 8009 8010```ts 8011avsessionController.off('extrasChange'); 8012``` 8013 8014### getAVPlaybackStateSync<sup>10+</sup> 8015 8016getAVPlaybackStateSync(): AVPlaybackState; 8017 8018使用同步方法获取当前会话的播放状态。 8019 8020**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8021 8022**系统能力:** SystemCapability.Multimedia.AVSession.Core 8023 8024**返回值:** 8025 8026| 类型 | 说明 | 8027| --------- | ------------------------------------------------------------ | 8028| [AVPlaybackState](#avplaybackstate10) | 当前会话的播放状态。 | 8029 8030**错误码:** 8031 8032以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8033 8034| 错误码ID | 错误信息 | 8035| -------- | ---------------------------------------- | 8036| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8037| 6600102 | The session does not exist. | 8038| 6600103 | The session controller does not exist. | 8039 8040**示例:** 8041 8042```ts 8043import { BusinessError } from '@kit.BasicServicesKit'; 8044 8045try { 8046 let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync(); 8047} catch (err) { 8048 let error = err as BusinessError; 8049 console.error(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`); 8050} 8051``` 8052 8053### getAVMetadataSync<sup>10+</sup> 8054 8055getAVMetadataSync(): AVMetadata 8056 8057使用同步方法获取会话元数据。 8058 8059**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8060 8061**系统能力:** SystemCapability.Multimedia.AVSession.Core 8062 8063**返回值:** 8064 8065| 类型 | 说明 | 8066| ----------------------------------- | ----------------------------- | 8067| [AVMetadata](#avmetadata10) | 会话元数据。 | 8068 8069**错误码:** 8070 8071以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8072 8073| 错误码ID | 错误信息 | 8074| -------- | ---------------------------------------- | 8075| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8076| 6600102 | The session does not exist. | 8077| 6600103 | The session controller does not exist. | 8078 8079**示例:** 8080```ts 8081import { BusinessError } from '@kit.BasicServicesKit'; 8082 8083try { 8084 let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync(); 8085} catch (err) { 8086 let error = err as BusinessError; 8087 console.error(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`); 8088} 8089``` 8090 8091### getAVCallState<sup>11+</sup> 8092 8093getAVCallState(): Promise\<AVCallState> 8094 8095获取通话状态数据。结果通过Promise异步回调方式返回。 8096 8097**系统能力:** SystemCapability.Multimedia.AVSession.Core 8098 8099**返回值:** 8100 8101| 类型 | 说明 | 8102| ----------------------------------- | ----------------------------- | 8103| Promise<[AVCallState](#avcallstate11)\> | Promise对象,返回通话状态。 | 8104 8105**错误码:** 8106 8107以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8108 8109| 错误码ID | 错误信息 | 8110| -------- | ---------------------------------------- | 8111| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8112| 6600102 | The session does not exist. | 8113| 6600103 | The session controller does not exist. | 8114 8115**示例:** 8116 8117```ts 8118import { BusinessError } from '@kit.BasicServicesKit'; 8119 8120avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => { 8121 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 8122}).catch((err: BusinessError) => { 8123 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 8124}); 8125``` 8126 8127### getAVCallState<sup>11+</sup> 8128 8129getAVCallState(callback: AsyncCallback\<AVCallState>): void 8130 8131获取通话状态数据。结果通过callback异步回调方式返回。 8132 8133**系统能力:** SystemCapability.Multimedia.AVSession.Core 8134 8135**参数:** 8136 8137| 参数名 | 类型 | 必填 | 说明 | 8138| -------- | ----------------------------------------- | ---- | -------------------------- | 8139| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | 是 | 回调函数,返回通话状态。 | 8140 8141**错误码:** 8142 8143以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8144 8145| 错误码ID | 错误信息 | 8146| -------- | ---------------------------------------- | 8147| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8148| 6600102 | The session does not exist. | 8149| 6600103 | The session controller does not exist. | 8150 8151**示例:** 8152 8153```ts 8154import { BusinessError } from '@kit.BasicServicesKit'; 8155 8156avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => { 8157 if (err) { 8158 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 8159 } else { 8160 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 8161 } 8162}); 8163``` 8164 8165### getCallMetadata<sup>11+</sup> 8166 8167getCallMetadata(): Promise\<CallMetadata> 8168 8169获取通话会话的元数据。结果通过Promise异步回调方式返回。 8170 8171**系统能力:** SystemCapability.Multimedia.AVSession.Core 8172 8173**返回值:** 8174 8175| 类型 | 说明 | 8176| ----------------------------------- | ----------------------------- | 8177| Promise<[CallMetadata](#callmetadata11)\> | Promise对象,返回会话元数据。 | 8178 8179**错误码:** 8180 8181以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8182 8183| 错误码ID | 错误信息 | 8184| -------- | ---------------------------------------- | 8185| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8186| 6600102 | The session does not exist. | 8187| 6600103 | The session controller does not exist. | 8188 8189**示例:** 8190 8191```ts 8192import { BusinessError } from '@kit.BasicServicesKit'; 8193 8194avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => { 8195 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 8196}).catch((err: BusinessError) => { 8197 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 8198}); 8199``` 8200 8201### getCallMetadata<sup>11+</sup> 8202 8203getCallMetadata(callback: AsyncCallback\<CallMetadata>): void 8204 8205获取通话会话的元数据。结果通过callback异步回调方式返回。 8206 8207**系统能力:** SystemCapability.Multimedia.AVSession.Core 8208 8209**参数:** 8210 8211| 参数名 | 类型 | 必填 | 说明 | 8212| -------- | ----------------------------------------- | ---- | -------------------------- | 8213| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | 是 | 回调函数,返回会话元数据。 | 8214 8215**错误码:** 8216 8217以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8218 8219| 错误码ID | 错误信息 | 8220| -------- | ---------------------------------------- | 8221| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8222| 6600102 | The session does not exist. | 8223| 6600103 | The session controller does not exist. | 8224 8225**示例:** 8226 8227```ts 8228import { BusinessError } from '@kit.BasicServicesKit'; 8229 8230avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => { 8231 if (err) { 8232 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 8233 } else { 8234 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 8235 } 8236}); 8237``` 8238 8239### getAVQueueTitleSync<sup>10+</sup> 8240 8241getAVQueueTitleSync(): string 8242 8243使用同步方法获取当前会话播放列表的名称。 8244 8245**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8246 8247**系统能力:** SystemCapability.Multimedia.AVSession.Core 8248 8249**返回值:** 8250 8251| 类型 | 说明 | 8252| ---------------- | ----------------------------- | 8253| string | 当前会话播放列表名称。 | 8254 8255**错误码:** 8256 8257以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8258 8259| 错误码ID | 错误信息 | 8260| -------- | ---------------------------------------- | 8261| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8262| 6600102 | The session does not exist. | 8263| 6600103 | The session controller does not exist. | 8264 8265**示例:** 8266 8267```ts 8268import { BusinessError } from '@kit.BasicServicesKit'; 8269 8270try { 8271 let currentQueueTitle: string = avsessionController.getAVQueueTitleSync(); 8272} catch (err) { 8273 let error = err as BusinessError; 8274 console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`); 8275} 8276``` 8277 8278### getAVQueueItemsSync<sup>10+</sup> 8279 8280getAVQueueItemsSync(): Array\<AVQueueItem\> 8281 8282使用同步方法获取当前会话播放列表相关信息。 8283 8284**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8285 8286**系统能力:** SystemCapability.Multimedia.AVSession.Core 8287 8288**返回值:** 8289 8290| 类型 | 说明 | 8291| --------------------------------------------- | ----------------------------- | 8292| Array<[AVQueueItem](#avqueueitem10)\> | 当前会话播放列表队列。 | 8293 8294**错误码:** 8295 8296以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8297 8298| 错误码ID | 错误信息 | 8299| -------- | ---------------------------------------- | 8300| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8301| 6600102 | The session does not exist. | 8302| 6600103 | The session controller does not exist. | 8303 8304**示例:** 8305 8306```ts 8307import { BusinessError } from '@kit.BasicServicesKit'; 8308 8309try { 8310 let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync(); 8311} catch (err) { 8312 let error = err as BusinessError; 8313 console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`); 8314} 8315``` 8316 8317### getOutputDeviceSync<sup>10+</sup> 8318 8319getOutputDeviceSync(): OutputDeviceInfo 8320 8321使用同步方法获取当前输出设备信息。 8322 8323**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8324 8325**系统能力:** SystemCapability.Multimedia.AVSession.Core 8326 8327**返回值:** 8328 8329| 类型 | 说明 | 8330| ----------------------------------------------- | --------------------------------- | 8331| [OutputDeviceInfo](#outputdeviceinfo10) | 当前输出设备信息。 | 8332 8333**错误码:** 8334 8335以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8336 8337| 错误码ID | 错误信息 | 8338| -------- | ---------------------------------------- | 8339| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8340| 6600103 | The session controller does not exist. | 8341 8342**示例:** 8343 8344```ts 8345import { BusinessError } from '@kit.BasicServicesKit'; 8346 8347try { 8348 let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync(); 8349} catch (err) { 8350 let error = err as BusinessError; 8351 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 8352} 8353``` 8354 8355### isActiveSync<sup>10+</sup> 8356 8357isActiveSync(): boolean 8358 8359使用同步方法判断会话是否被激活。 8360 8361**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8362 8363**系统能力:** SystemCapability.Multimedia.AVSession.Core 8364 8365**返回值:** 8366 8367| 类型 | 说明 | 8368| ----------------- | ------------------------------------------------------------ | 8369| boolean | 会话是否为激活状态,true表示被激活,false表示禁用。 | 8370 8371**错误码:** 8372 8373以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8374 8375| 错误码ID | 错误信息 | 8376| -------- | ---------------------------------------- | 8377| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8378| 6600102 | The session does not exist. | 8379| 6600103 | The session controller does not exist. | 8380 8381**示例:** 8382 8383```ts 8384import { BusinessError } from '@kit.BasicServicesKit'; 8385 8386try { 8387 let isActive: boolean = avsessionController.isActiveSync(); 8388} catch (err) { 8389 let error = err as BusinessError; 8390 console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`); 8391} 8392``` 8393 8394### getValidCommandsSync<sup>10+</sup> 8395 8396getValidCommandsSync(): Array\<AVControlCommandType\> 8397 8398使用同步方法获取会话支持的有效命令。 8399 8400**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8401 8402**系统能力:** SystemCapability.Multimedia.AVSession.Core 8403 8404**返回值:** 8405 8406| 类型 | 说明 | 8407| ------------------------------------------------------------ | --------------------------------- | 8408| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | 会话支持的有效命令的集合。 | 8409 8410**错误码:** 8411 8412以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8413 8414| 错误码ID | 错误信息 | 8415| -------- | ---------------------------------------- | 8416| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8417| 6600102 | The session does not exist. | 8418| 6600103 | The session controller does not exist. | 8419 8420**示例:** 8421 8422```ts 8423import { BusinessError } from '@kit.BasicServicesKit'; 8424 8425try { 8426 let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync(); 8427} catch (err) { 8428 let error = err as BusinessError; 8429 console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`); 8430} 8431``` 8432 8433## AVControlCommandType<sup>10+</sup> 8434 8435type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 8436 'seek' | 'setSpeed' | 'setLoopMode' | 'setTargetLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'playWithAssetId' | 'answer' | 'hangUp' | 'toggleCallMute' 8437 8438会话可传递的命令。 8439 8440该类型可取的值为下表字符串的并集。 8441 8442**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8443 8444**系统能力:** SystemCapability.Multimedia.AVSession.Core 8445 8446| 类型 | 说明 | 8447| ---------------- | ------------ | 8448| 'play' | 播放。无需传入参数。| 8449| 'pause' | 暂停。无需传入参数。| 8450| 'stop' | 停止。 无需传入参数。 | 8451| 'playNext' | 下一首。无需传入参数。| 8452| 'playPrevious' | 上一首。无需传入参数。| 8453| 'fastForward' | 快进。无需传入参数。 | 8454| 'rewind' | 快退。无需传入参数。 | 8455| 'seek' | 跳转某一节点。对应参数使用number类型。| 8456| 'setSpeed' | 设置播放倍速。对应参数使用number类型。 | 8457| 'setLoopMode' | 设置循环模式。对应参数使用[LoopMode](#loopmode10)。 | 8458| 'setTargetLoopMode' <sup>18+</sup> | 设置目标循环模式。对应参数推荐使用[LoopMode](#loopmode10)。 | 8459| 'toggleFavorite' | 是否收藏。对应参数使用[AVMetadata.assetId](#avmetadata10)。 | 8460| 'playFromAssetId'| 播放指定的assetId。 | 8461| 'playWithAssetId' <sup>20+</sup> | 播放指定的assetId。对应参数使用[AVMetadata.assetId](#avmetadata10),<br>字符串长度<40960字节。<br> | 8462|'answer' | 接听。无需传入参数。 | 8463| 'hangUp' | 挂断。无需传入参数。 | 8464|'toggleCallMute' | 设置通话静音状态。无需传入参数。 | 8465 8466## AVControlCommand<sup>10+</sup> 8467 8468会话接受的命令的对象描述。 8469 8470**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 8471 8472**系统能力:** SystemCapability.Multimedia.AVSession.Core 8473 8474| 名称 | 类型 | 必填 | 说明 | 8475| --------- | ------------------------------------------------- | ---- | -------------- | 8476| command | [AVControlCommandType](#avcontrolcommandtype10) | 是 | 命令。每种命令对应的参数不同,具体的对应关系可查阅[AVControlCommandType](#avcontrolcommandtype10)里的详细介绍。 | 8477| parameter | [LoopMode](#loopmode10) | string | number | 否 | 命令对应的参数。 | 8478 8479 8480## AVCastPickerOptions<sup>14+</sup> 8481 8482拉起的投播半模态窗口相关属性。 8483 8484**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8485 8486**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 8487 8488| 名称 | 类型 | 必填 | 说明 | 8489| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 8490| sessionType | [AVSessionType](#avsessiontype10) | 否 | 会话类型,默认值为'audio'。<br>当前仅支持'audio'、'video'会话类型。如果传入'voice_call'、'video_call',将按照传入默认值'audio'处理。 | 8491 8492## AVCastPickerHelper<sup>14+</sup> 8493 8494投播半模态对象,可拉起半模态窗口,选择投播设备。在使用前,需要创建AVCastPickerHelper实例。 8495 8496**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8497 8498**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 8499 8500### constructor<sup>14+</sup> 8501 8502constructor(context: Context) 8503 8504创建AVCastPickerHelper对象,获取context参考[getContext](../apis-arkui/arkts-apis-uicontext-uicontext.md#gethostcontext12)。 8505 8506**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8507 8508**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 8509 8510**参数:** 8511 8512| 参数名 | 类型 | 必填 | 说明 | 8513| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 8514| context | Context | 是 | 应用上下文(仅支持[UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md))。 | 8515 8516**错误码:** 8517 8518以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8519 8520| 错误码ID | 错误信息 | 8521| -------- | ---------------------------------------- | 8522| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8523| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8524 8525**示例:** 8526 8527```ts 8528import { common } from '@kit.AbilityKit'; 8529import { avSession } from '@kit.AVSessionKit'; 8530@Entry 8531@Component 8532struct Index { 8533 @State message: string = 'hello world'; 8534 8535 build() { 8536 Row() { 8537 Column() { 8538 Text(this.message) 8539 .fontSize(40) 8540 .fontWeight(FontWeight.Bold) 8541 .onClick(()=>{ 8542 let context = this.getUIContext().getHostContext() as Context; 8543 let avCastPicker = new avSession.AVCastPickerHelper(context); 8544 }) 8545 } 8546 .width('100%') 8547 } 8548 .height('100%') 8549 } 8550} 8551``` 8552 8553### select<sup>14+</sup> 8554 8555select(options?: AVCastPickerOptions): Promise\<void> 8556 8557通过选择模式拉起AVCastPicker界面,用户可以选择投播设备。接口采用Promise异步返回形式,传入可选参数AVCastPickerOptions对象,无返回值。 8558 8559**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8560 8561**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 8562 8563**参数:** 8564 8565| 参数名 | 类型 | 必填 | 说明 | 8566| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 8567| options | [AVCastPickerOptions](#avcastpickeroptions14) | 否 | AVCastPicker选择选项。无此参数时,以AVCastPickerOptions默认值拉起。 | 8568 8569**返回值:** 8570 8571| 类型 | 说明 | 8572| -------------- | ----------------------------- | 8573| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 8574 8575**错误码:** 8576 8577以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8578 8579| 错误码ID | 错误信息 | 8580| -------- | ---------------------------------------- | 8581| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8582 8583**示例:** 8584 8585```ts 8586import { common } from '@kit.AbilityKit'; 8587import { BusinessError } from '@kit.BasicServicesKit'; 8588 8589async function avCastPicker(context: common.Context) { 8590 let avCastPickerOptions : avSession.AVCastPickerOptions = { 8591 sessionType : 'video', 8592 } 8593 let avCastPicker = new avSession.AVCastPickerHelper(context); 8594 avCastPicker.select(avCastPickerOptions).then(() => { 8595 console.info('select successfully'); 8596 }).catch((err: BusinessError) => { 8597 console.error(`AVCastPicker.select failed with err: ${err.code}, ${err.message}`); 8598 }); 8599} 8600``` 8601### on('pickerStateChange')<sup>14+</sup> 8602 8603on(type: 'pickerStateChange', callback: Callback<AVCastPickerState\>) : void 8604 8605设置半模态窗口变化的监听事件。 8606 8607**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8608 8609**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 8610 8611**参数:** 8612 8613| 参数名 | 类型 | 必填 | 说明 | 8614| --------| -----------|-----|------------| 8615| type | string | 是 | 事件回调类型,支持事件`'pickerStateChange'`:当半模态窗口变化时,触发该事件。 | 8616| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)> | 是 | 回调函数,参数state是变化后的半模态窗口状态。| 8617 8618**错误码:** 8619 8620以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8621 8622| 错误码ID | 错误信息 | 8623| -------- | ---------------------------------------- | 8624| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8625| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8626 8627**示例:** 8628 8629```ts 8630import { common } from '@kit.AbilityKit'; 8631import { AVCastPickerState } from '@kit.AVSessionKit'; 8632 8633async function onPickerStateChange(context: common.Context) { 8634 let avCastPicker = new avSession.AVCastPickerHelper(context); 8635 avCastPicker.on('pickerStateChange', (state: AVCastPickerState) => { 8636 console.info(`picker state change : ${state}`); 8637 }); 8638} 8639``` 8640 8641### off('pickerStateChange')<sup>14+</sup> 8642 8643off(type: 'pickerStateChange', callback?: Callback<AVCastPickerState\>) : void 8644 8645取消半模态窗口变化的监听事件,关闭后,不再进行该事件回调。 8646 8647**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。 8648 8649**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 8650 8651**参数:** 8652 8653| 参数名 | 类型 | 必填 | 说明 | 8654| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | 8655| type | string | 是 | 取消对应的监听事件,支持事件`'pickerStateChange'`。 | 8656| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)> | 否 | 回调函数,参数state是变化后的半模态窗口状态。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 8657 8658**错误码:** 8659 8660以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 8661 8662| 错误码ID | 错误信息 | 8663| -------- | ---------------------------------------- | 8664| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8665| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8666 8667**示例:** 8668 8669```ts 8670import { common } from '@kit.AbilityKit'; 8671 8672async function onPickerStateChange(context: common.Context) { 8673 let avCastPicker = new avSession.AVCastPickerHelper(context); 8674 avCastPicker.off('pickerStateChange'); 8675} 8676``` 8677 8678## AVSessionErrorCode<sup>10+</sup> 8679 8680会话发生错误时的错误码。 8681 8682| 名称 | 值 | 说明 | 8683| -------------------------------------- | ------- | ------------------------------- | 8684| ERR_CODE_SERVICE_EXCEPTION | 6600101 | 会话服务端异常。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core| 8685| ERR_CODE_SESSION_NOT_EXIST | 6600102 | 会话不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 8686| ERR_CODE_CONTROLLER_NOT_EXIST | 6600103 | 会话控制器不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 8687| ERR_CODE_REMOTE_CONNECTION_ERR | 6600104 | 远端会话连接失败。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core| 8688| ERR_CODE_COMMAND_INVALID | 6600105 | 无效会话命令。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core| 8689| ERR_CODE_SESSION_INACTIVE | 6600106 | 会话未激活。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 8690| ERR_CODE_MESSAGE_OVERLOAD | 6600107 | 命令&消息过载。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 8691| ERR_CODE_DEVICE_CONNECTION_FAILED | 6600108 | 设备连接失败。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 8692| ERR_CODE_REMOTE_CONNECTION_NOT_EXIST | 6600109 | 远端会话不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 8693| ERR_CODE_CAST_CONTROL_UNSPECIFIED<sup>13+</sup> | 6611000 | 未被定义的投播错误码。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8694| ERR_CODE_CAST_CONTROL_REMOTE_ERROR<sup>13+</sup> | 6611001 | 远端播放器中发生不明错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8695| ERR_CODE_CAST_CONTROL_BEHIND_LIVE_WINDOW<sup>13+</sup> | 6611002 | 播放出现延迟。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8696| ERR_CODE_CAST_CONTROL_TIMEOUT<sup>13+</sup> | 6611003 | 投播控制进程超时。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8697| ERR_CODE_CAST_CONTROL_RUNTIME_CHECK_FAILED<sup>13+</sup> | 6611004 | 运行时检查失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8698| ERR_CODE_CAST_CONTROL_PLAYER_NOT_WORKING<sup>13+</sup> | 6611100 | 跨设备数据传输被锁定。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8699| ERR_CODE_CAST_CONTROL_SEEK_MODE_UNSUPPORTED<sup>13+</sup> | 6611101 | 不支持指定的查找模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8700| ERR_CODE_CAST_CONTROL_ILLEGAL_SEEK_TARGET<sup>13+</sup> | 6611102 | 要搜索的位置超出媒体的范围,或者不支持当前搜索模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8701| ERR_CODE_CAST_CONTROL_PLAY_MODE_UNSUPPORTED<sup>13+</sup> | 6611103 | 不支持指定的播放模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8702| ERR_CODE_CAST_CONTROL_PLAY_SPEED_UNSUPPORTED<sup>13+</sup> | 6611104 | 不支持指定的播放速度。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8703| ERR_CODE_CAST_CONTROL_DEVICE_MISSING<sup>13+</sup> | 6611105 | 操作失败,因为媒体源设备或媒体接收器设备已被销毁。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8704| ERR_CODE_CAST_CONTROL_INVALID_PARAM<sup>13+</sup> | 6611106 | 该参数无效。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8705| ERR_CODE_CAST_CONTROL_NO_MEMORY<sup>13+</sup> | 6611107 | 内存分配失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8706| ERR_CODE_CAST_CONTROL_OPERATION_NOT_ALLOWED<sup>13+</sup> | 6611108 | 不被允许的操作。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8707| ERR_CODE_CAST_CONTROL_IO_UNSPECIFIED<sup>13+</sup> | 6612000 | 未指定的输入/输出错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8708| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_FAILED<sup>13+</sup> | 6612001 | 网络连接失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8709| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_TIMEOUT<sup>13+</sup> | 6612002 | 网络连接超时。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8710| ERR_CODE_CAST_CONTROL_IO_INVALID_HTTP_CONTENT_TYPE <sup>13+</sup> | 6612003 | 无效的"Content-Type"。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8711| ERR_CODE_CAST_CONTROL_IO_BAD_HTTP_STATUS<sup>13+</sup> | 6612004 | HTTP服务器返回一个意外的HTTP响应状态码。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8712| ERR_CODE_CAST_CONTROL_IO_FILE_NOT_FOUND<sup>13+</sup> | 6612005 | 文件不存在。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8713| ERR_CODE_CAST_CONTROL_IO_NO_PERMISSION<sup>13+</sup> | 6612006 | 不允许执行输入/输出的IO操作。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8714| ERR_CODE_CAST_CONTROL_IO_CLEARTEXT_NOT_PERMITTED<sup>13+</sup> | 6612007 | 应用的网络安全配置不允许访问明文HTTP流量。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8715| ERR_CODE_CAST_CONTROL_IO_READ_POSITION_OUT_OF_RANGE<sup>13+</sup> | 6612008 | 从数据绑定中读取数据。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8716| ERR_CODE_CAST_CONTROL_IO_NO_CONTENTS<sup>13+</sup> | 6612100 | 媒体中没有可播放的内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8717| ERR_CODE_CAST_CONTROL_IO_READ_ERROR<sup>13+</sup> | 6612101 | 媒体无法读取。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8718| ERR_CODE_CAST_CONTROL_IO_CONTENT_BUSY<sup>13+</sup> | 6612102 | 该资源正在使用中。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8719| ERR_CODE_CAST_CONTROL_IO_CONTENT_EXPIRED<sup>13+</sup> | 6612103 | 输入/输出的IO请求内容已过期。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8720| ERR_CODE_CAST_CONTROL_IO_USE_FORBIDDEN<sup>13+</sup> | 6612104 | 不允许播放请求内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8721| ERR_CODE_CAST_CONTROL_IO_NOT_VERIFIED<sup>13+</sup> | 6612105 | 无法验证所允许的内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8722| ERR_CODE_CAST_CONTROL_IO_EXHAUSTED_ALLOWED_USES<sup>13+</sup> | 6612106 | 此内容已达到允许的最大使用次数。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8723| ERR_CODE_CAST_CONTROL_IO_NETWORK_PACKET_SENDING_FAILED<sup>13+</sup> | 6612107 | 从源设备发送数据包到接收设备时出现错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8724| ERR_CODE_CAST_CONTROL_PARSING_UNSPECIFIED<sup>13+</sup> | 6613000 | 未指定的内容解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8725| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_MALFORMED<sup>13+</sup> | 6613001 | 媒体容器比特流的格式解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8726| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_MALFORMED<sup>13+</sup> | 6613002 | 媒体清单解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8727| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_UNSUPPORTED<sup>13+</sup> | 6613003 | 文件的媒体容器格式/媒体容器特性不被支持。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8728| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_UNSUPPORTED<sup>13+</sup> | 6613004 | 媒体清单中不支持的特性。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8729| ERR_CODE_CAST_CONTROL_DECODING_UNSPECIFIED<sup>13+</sup> | 6614000 | 未指定的解码错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8730| ERR_CODE_CAST_CONTROL_DECODING_INIT_FAILED<sup>13+</sup> | 6614001 | 解码器初始化失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8731| ERR_CODE_CAST_CONTROL_DECODING_QUERY_FAILED<sup>13+</sup> | 6614002 | 解码器查询失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8732| ERR_CODE_CAST_CONTROL_DECODING_FAILED<sup>13+</sup> | 6614003 | 媒体样本解码失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8733| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_EXCEEDS_CAPABILITIES<sup>13+</sup> | 6614004 | 设备的能力无法解码当前格式。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8734| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_UNSUPPORTED<sup>13+</sup> | 6614005 | 不支持的解码格式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8735| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_UNSPECIFIED<sup>13+</sup> | 6615000 | 未指定的音频渲染器错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8736| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_INIT_FAILED <sup>13+</sup> | 6615001 | 音频渲染器初始化失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8737| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_WRITE_FAILED<sup>13+</sup> | 6615002 | 音频渲染器写入数据失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8738| ERR_CODE_CAST_CONTROL_DRM_UNSPECIFIED<sup>13+</sup> | 6616000 | 未指定的DRM相关错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8739| ERR_CODE_CAST_CONTROL_DRM_SCHEME_UNSUPPORTED<sup>13+</sup> | 6616001 | 设备不支持所选择的DRM保护方案。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8740| ERR_CODE_CAST_CONTROL_DRM_PROVISIONING_FAILED<sup>13+</sup> | 6616002 | 设备配置失败。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8741| ERR_CODE_CAST_CONTROL_DRM_CONTENT_ERROR<sup>13+</sup> | 6616003 | 受DRM保护的内容无法播放。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8742| ERR_CODE_CAST_CONTROL_DRM_LICENSE_ACQUISITION_FAILED<sup>13+</sup> | 6616004 | 获取许可证失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8743| ERR_CODE_CAST_CONTROL_DRM_DISALLOWED_OPERATION<sup>13+</sup> | 6616005 | 许可证策略不允许该操作。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8744| ERR_CODE_CAST_CONTROL_DRM_SYSTEM_ERROR<sup>13+</sup> | 6616006 | DRM系统中发生错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8745| ERR_CODE_CAST_CONTROL_DRM_DEVICE_REVOKED<sup>13+</sup> | 6616007 | 设备已撤销DRM权限。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8746| ERR_CODE_CAST_CONTROL_DRM_LICENSE_EXPIRED<sup>13+</sup> | 6616008 | 加载中的DRM许可证已过期。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8747| ERR_CODE_CAST_CONTROL_DRM_PROVIDE_KEY_RESPONSE_ERROR<sup>13+</sup> | 6616100 | DRM处理密钥响应时发生错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8748 8749## SkipIntervals<sup>11+</sup> 8750 8751表示session支持的快进快退时间间隔的枚举。 8752 8753**系统能力:** SystemCapability.Multimedia.AVSession.Core 8754 8755| 名称 | 值 | 说明 | 8756| ---------------------- | -- | ----------------------- | 8757| SECONDS_10 | 10 | 时间为10秒。 | 8758| SECONDS_15 | 15 | 时间为15秒。 | 8759| SECONDS_30 | 30 | 时间为30秒。 | 8760 8761## AudioCapabilities<sup>20+</sup> 8762 8763表示投播设备支持的音频能力。 8764 8765**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。 8766 8767**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 8768 8769| 名称 | 类型 | 只读 | 可选 | 说明 | 8770| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 8771| streamInfos | Array\<[audio.AudioStreamInfo](../apis-audio-kit/arkts-apis-audio-i.md#audiostreaminfo8)> | 是 | 否 | 音频能力参数的列表。 |