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. | 53 54**示例:** 55 56```ts 57import { BusinessError } from '@kit.BasicServicesKit'; 58 59let currentAVSession: avSession.AVSession; 60let tag = "createNewSession"; 61let context: Context = getContext(this); 62let sessionId: string; // 供后续函数入参使用 63 64avSession.createAVSession(context, tag, "audio").then((data: avSession.AVSession) => { 65 currentAVSession = data; 66 sessionId = currentAVSession.sessionId; 67 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 68}).catch((err: BusinessError) => { 69 console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 70}); 71``` 72 73## avSession.createAVSession<sup>10+</sup> 74 75createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void 76 77创建会话对象,一个Ability只能存在一个会话,重复创建会失败,结果通过callback异步回调方式返回。 78 79**系统能力:** SystemCapability.Multimedia.AVSession.Core 80 81**参数:** 82 83| 参数名 | 类型 | 必填 | 说明 | 84| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 85| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | 是| 需要使用UIAbilityContext,用于系统获取应用组件的相关信息。 | 86| tag | string | 是 | 会话的自定义名称。 | 87| type | [AVSessionType](#avsessiontype10) | 是 | 会话类型。 | 88| callback | AsyncCallback<[AVSession](#avsession10)\> | 是 | 回调函数。回调返回会话实例对象,可用于获取会话ID,以及设置元数据、播放状态,发送按键事件等操作。 | 89 90**错误码:** 91 92以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 93 94| 错误码ID | 错误信息 | 95| -------- | ---------------------------------------- | 96| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 97| 6600101 | Session service exception. | 98 99**示例:** 100 101```ts 102import { BusinessError } from '@kit.BasicServicesKit'; 103 104let currentAVSession: avSession.AVSession; 105let tag = "createNewSession"; 106let context: Context = getContext(this); 107let sessionId: string; // 供后续函数入参使用 108 109avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 110 if (err) { 111 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 112 } else { 113 currentAVSession = data; 114 sessionId = currentAVSession.sessionId; 115 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 116 } 117}); 118``` 119 120## ProtocolType<sup>11+</sup> 121 122远端设备支持的协议类型的枚举。 123 124**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 125 126**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 127 128| 名称 | 值 | 说明 | 129| --------------------------- | ---- | ----------- | 130| TYPE_LOCAL<sup>11+</sup> | 0 | 本地设备,包括设备本身的内置扬声器或音频插孔、A2DP 设备。 | 131| TYPE_CAST_PLUS_STREAM<sup>11+</sup> | 2 | Cast+的Stream模式。表示媒体正在其他设备上展示。 | 132| TYPE_DLNA<sup>12+</sup> | 4 | DLNA协议。表示媒体正在其他设备上展示。 | 133 134## AVSessionType<sup>10+<sup> 135 136type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call' 137 138当前会话支持的会话类型。 139 140该类型可取的值为下表字符串。 141 142**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 143 144**系统能力:** SystemCapability.Multimedia.AVSession.Core 145 146| 类型 | 说明 | 147| ----- | ---- | 148| 'audio' | 音频 | 149| 'video' | 视频 | 150| 'voice_call'<sup>11+<sup> | 音频通话 | 151| 'video_call'<sup>12+<sup> | 视频通话 | 152 153## AVSession<sup>10+</sup> 154 155调用[avSession.createAVSession](#avsessioncreateavsession10)后,返回会话的实例,可以获得会话ID,完成设置元数据,播放状态信息等操作。 156 157### 属性 158 159**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 160 161**系统能力:** SystemCapability.Multimedia.AVSession.Core 162 163| 名称 | 类型 | 可读 | 可写 | 说明 | 164| :-------- | :----- | :--- | :--- | :---------------------------- | 165| sessionId | string | 是 | 否 | AVSession对象唯一的会话标识。 | 166| sessionType| [AVSessionType](#avsessiontype10) | 是 | 否 | AVSession会话类型。 | 167 168**示例:** 169 170```ts 171let sessionId: string = currentAVSession.sessionId; 172let sessionType: avSession.AVSessionType = currentAVSession.sessionType; 173``` 174 175### setAVMetadata<sup>10+</sup> 176 177setAVMetadata(data: AVMetadata): Promise\<void> 178 179设置会话元数据。结果通过Promise异步回调方式返回。 180 181**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 182 183**系统能力:** SystemCapability.Multimedia.AVSession.Core 184 185**参数:** 186 187| 参数名 | 类型 | 必填 | 说明 | 188| ------ | ------------------------- | ---- | ------------ | 189| data | [AVMetadata](#avmetadata10) | 是 | 会话元数据。 | 190 191**返回值:** 192 193| 类型 | 说明 | 194| -------------- | ----------------------------- | 195| Promise\<void> | Promise对象。当元数据设置成功,无返回结果,否则返回错误对象。 | 196 197**错误码:** 198 199以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 200 201| 错误码ID | 错误信息 | 202| -------- | ---------------------------------------- | 203| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 204| 6600101 | Session service exception. | 205| 6600102 | The session does not exist. | 206 207**示例:** 208 209```ts 210import { BusinessError } from '@kit.BasicServicesKit'; 211 212let metadata: avSession.AVMetadata = { 213 assetId: "121278", 214 title: "lose yourself", 215 artist: "Eminem", 216 author: "ST", 217 album: "Slim shady", 218 writer: "ST", 219 composer: "ST", 220 duration: 2222, 221 mediaImage: "https://www.example.com/example.jpg", 222 subtitle: "8 Mile", 223 description: "Rap", 224 // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。 225 // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n 226 lyric: "lrc格式歌词内容", 227 previousAssetId: "121277", 228 nextAssetId: "121279" 229}; 230currentAVSession.setAVMetadata(metadata).then(() => { 231 console.info('SetAVMetadata successfully'); 232}).catch((err: BusinessError) => { 233 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 234}); 235``` 236 237### setAVMetadata<sup>10+</sup> 238 239setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void 240 241设置会话元数据。结果通过callback异步回调方式返回。 242 243**系统能力:** SystemCapability.Multimedia.AVSession.Core 244 245**参数:** 246 247| 参数名 | 类型 | 必填 | 说明 | 248| -------- | ------------------------- | ---- | ------------------------------------- | 249| data | [AVMetadata](#avmetadata10) | 是 | 会话元数据。 | 250| callback | AsyncCallback\<void> | 是 | 回调函数。当元数据设置成功,err为undefined,否则返回错误对象。 | 251 252**错误码:** 253 254以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 255 256| 错误码ID | 错误信息 | 257| -------- | ---------------------------------------- | 258| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 259| 6600101 | Session service exception. | 260| 6600102 | The session does not exist. | 261 262**示例:** 263 264```ts 265import { BusinessError } from '@kit.BasicServicesKit'; 266 267let metadata: avSession.AVMetadata = { 268 assetId: "121278", 269 title: "lose yourself", 270 artist: "Eminem", 271 author: "ST", 272 album: "Slim shady", 273 writer: "ST", 274 composer: "ST", 275 duration: 2222, 276 mediaImage: "https://www.example.com/example.jpg", 277 subtitle: "8 Mile", 278 description: "Rap", 279 // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。 280 // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n 281 lyric: "lrc格式歌词内容", 282 previousAssetId: "121277", 283 nextAssetId: "121279" 284}; 285currentAVSession.setAVMetadata(metadata, (err: BusinessError) => { 286 if (err) { 287 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 288 } else { 289 console.info('SetAVMetadata successfully'); 290 } 291}); 292``` 293 294### setCallMetadata<sup>11+</sup> 295 296setCallMetadata(data: CallMetadata): Promise\<void> 297 298设置通话会话元数据。结果通过Promise异步回调方式返回。 299 300**系统能力:** SystemCapability.Multimedia.AVSession.Core 301 302**参数:** 303 304| 参数名 | 类型 | 必填 | 说明 | 305| ------ | ------------------------- | ---- | ------------ | 306| data | [CallMetadata](#callmetadata11) | 是 | 通话会话元数据。 | 307 308**返回值:** 309 310| 类型 | 说明 | 311| -------------- | ----------------------------- | 312| Promise\<void> | Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。 | 313 314**错误码:** 315 316以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 317 318| 错误码ID | 错误信息 | 319| -------- | ---------------------------------------- | 320| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 321| 6600101 | Session service exception. | 322| 6600102 | The session does not exist. | 323 324**示例:** 325 326```ts 327import { image } from '@kit.ImageKit'; 328import { resourceManager } from '@kit.LocalizationKit'; 329import { BusinessError } from '@kit.BasicServicesKit'; 330 331let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 332 let imageSource = await image.createImageSource(value.buffer); 333 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 334 let calldata: avSession.CallMetadata = { 335 name: "xiaoming", 336 phoneNumber: "111xxxxxxxx", 337 avatar: imagePixel 338 }; 339currentAVSession.setCallMetadata(calldata).then(() => { 340 console.info('setCallMetadata successfully'); 341}).catch((err: BusinessError) => { 342 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 343}); 344``` 345 346### setCallMetadata<sup>11+</sup> 347 348setCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void 349 350设置通话会话元数据。结果通过callback异步回调方式返回。 351 352**系统能力:** SystemCapability.Multimedia.AVSession.Core 353 354**参数:** 355 356| 参数名 | 类型 | 必填 | 说明 | 357| -------- | ------------------------- | ---- | ------------------------------------- | 358| data | [CallMetadata](#callmetadata11) | 是 | 通话会话元数据。 | 359| callback | AsyncCallback\<void> | 是 | 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。 | 360 361**错误码:** 362 363以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 364 365| 错误码ID | 错误信息 | 366| -------- | ---------------------------------------- | 367| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 368| 6600101 | Session service exception. | 369| 6600102 | The session does not exist. | 370 371**示例:** 372 373```ts 374import { image } from '@kit.ImageKit'; 375import { resourceManager } from '@kit.LocalizationKit'; 376import { BusinessError } from '@kit.BasicServicesKit'; 377 378async function setCallMetadata() { 379 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 380 let imageSource = await image.createImageSource(value.buffer); 381 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 382 let calldata: avSession.CallMetadata = { 383 name: "xiaoming", 384 phoneNumber: "111xxxxxxxx", 385 avatar: imagePixel 386 }; 387 currentAVSession.setCallMetadata(calldata, (err: BusinessError) => { 388 if (err) { 389 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 390 } else { 391 console.info('setCallMetadata successfully'); 392 } 393 }); 394} 395``` 396 397### setAVCallState<sup>11+</sup> 398 399setAVCallState(state: AVCallState): Promise\<void> 400 401设置通话状态。结果通过Promise异步回调方式返回。 402 403**系统能力:** SystemCapability.Multimedia.AVSession.Core 404 405**参数:** 406 407| 参数名 | 类型 | 必填 | 说明 | 408| ------ | ------------------------- | ---- | ------------ | 409| state | [AVCallState](#avcallstate11) | 是 | 通话状态。 | 410 411**返回值:** 412 413| 类型 | 说明 | 414| -------------- | ----------------------------- | 415| Promise\<void> | Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。 | 416 417**错误码:** 418 419以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 420 421| 错误码ID | 错误信息 | 422| -------- | ---------------------------------------- | 423| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 424| 6600101 | Session service exception. | 425| 6600102 | The session does not exist. | 426 427**示例:** 428 429```ts 430import { BusinessError } from '@kit.BasicServicesKit'; 431 432let calldata: avSession.AVCallState = { 433 state: avSession.CallState.CALL_STATE_ACTIVE, 434 muted: false 435}; 436currentAVSession.setAVCallState(calldata).then(() => { 437 console.info('setAVCallState successfully'); 438}).catch((err: BusinessError) => { 439 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 440}); 441``` 442 443### setAVCallState<sup>11+</sup> 444 445setAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void 446 447设置通话状态。结果通过callback异步回调方式返回。 448 449**系统能力:** SystemCapability.Multimedia.AVSession.Core 450 451**参数:** 452 453| 参数名 | 类型 | 必填 | 说明 | 454| -------- | ------------------------- | ---- | ------------------------------------- | 455| state | [AVCallState](#avcallstate11) | 是 | 通话状态。 | 456| callback | AsyncCallback\<void> | 是 | 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。 | 457 458**错误码:** 459 460以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 461 462| 错误码ID | 错误信息 | 463| -------- | ---------------------------------------- | 464| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 465| 6600101 | Session service exception. | 466| 6600102 | The session does not exist. | 467 468**示例:** 469 470```ts 471import { BusinessError } from '@kit.BasicServicesKit'; 472 473let avcalldata: avSession.AVCallState = { 474 state: avSession.CallState.CALL_STATE_ACTIVE, 475 muted: false 476}; 477currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => { 478 if (err) { 479 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 480 } else { 481 console.info('setAVCallState successfully'); 482 } 483}); 484``` 485 486### setAVPlaybackState<sup>10+</sup> 487 488setAVPlaybackState(state: AVPlaybackState): Promise\<void> 489 490设置会话播放状态。结果通过Promise异步回调方式返回。 491 492**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 493 494**系统能力:** SystemCapability.Multimedia.AVSession.Core 495 496**参数:** 497 498| 参数名 | 类型 | 必填 | 说明 | 499| ------ | ----------------------------------- | ---- | ---------------------------------------------- | 500| state | [AVPlaybackState](#avplaybackstate10) | 是 | 会话播放状态,包括状态、倍数、循环模式等信息。 | 501 502**返回值:** 503 504| 类型 | 说明 | 505| -------------- | ----------------------------- | 506| Promise\<void> | Promise对象。当播放状态设置成功,无返回结果,否则返回错误对象。 | 507 508**错误码:** 509 510以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 511 512| 错误码ID | 错误信息 | 513| -------- | ---------------------------------------- | 514| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 515| 6600101 | Session service exception. | 516| 6600102 | The session does not exist. | 517 518**示例:** 519 520```ts 521import { BusinessError } from '@kit.BasicServicesKit'; 522 523let playbackState: avSession.AVPlaybackState = { 524 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 525 speed: 1.0, 526 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 527 bufferedTime:1000, 528 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 529 isFavorite:true 530}; 531currentAVSession.setAVPlaybackState(playbackState).then(() => { 532 console.info('SetAVPlaybackState successfully'); 533}).catch((err: BusinessError) => { 534 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 535}); 536``` 537 538### setAVPlaybackState<sup>10+</sup> 539 540setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void 541 542设置会话播放状态。结果通过callback异步回调方式返回。 543 544**系统能力:** SystemCapability.Multimedia.AVSession.Core 545 546**参数:** 547 548| 参数名 | 类型 | 必填 | 说明 | 549| -------- | ----------------------------------- | ---- | ---------------------------------------------- | 550| state | [AVPlaybackState](#avplaybackstate10) | 是 | 会话播放状态,包括状态、倍数、循环模式等信息。 | 551| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 552 553**错误码:** 554 555以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 556 557| 错误码ID | 错误信息 | 558| -------- | ---------------------------------------- | 559| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 560| 6600101 | Session service exception. | 561| 6600102 | The session does not exist. | 562 563**示例:** 564 565```ts 566import { BusinessError } from '@kit.BasicServicesKit'; 567 568let PlaybackState: avSession.AVPlaybackState = { 569 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 570 speed: 1.0, 571 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 572 bufferedTime:1000, 573 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 574 isFavorite:true 575}; 576currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => { 577 if (err) { 578 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 579 } else { 580 console.info('SetAVPlaybackState successfully'); 581 } 582}); 583``` 584 585### setLaunchAbility<sup>10+</sup> 586 587setLaunchAbility(ability: WantAgent): Promise\<void> 588 589设置一个WantAgent用于拉起会话的Ability。结果通过Promise异步回调方式返回。 590 591**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 592 593**系统能力:** SystemCapability.Multimedia.AVSession.Core 594 595**参数:** 596 597| 参数名 | 类型 | 必填 | 说明 | 598| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 599| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 600 601**返回值:** 602 603| 类型 | 说明 | 604| -------------- | ----------------------------- | 605| Promise\<void> | Promise对象。当Ability设置成功,无返回结果,否则返回错误对象。 | 606 607**错误码:** 608 609以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 610 611| 错误码ID | 错误信息 | 612| -------- | ---------------------------------------- | 613| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 614| 6600101 | Session service exception. | 615| 6600102 | The session does not exist. | 616 617**示例:** 618 619```ts 620import { wantAgent } from '@kit.AbilityKit'; 621import { BusinessError } from '@kit.BasicServicesKit'; 622 623// WantAgentInfo对象 624let wantAgentInfo: wantAgent.WantAgentInfo = { 625 wants: [ 626 { 627 deviceId: "deviceId", 628 bundleName: "com.example.myapplication", 629 abilityName: "EntryAbility", 630 action: "action1", 631 entities: ["entity1"], 632 type: "MIMETYPE", 633 uri: "key = {true,true,false}", 634 parameters: 635 { 636 mykey0: 2222, 637 mykey1: [1, 2, 3], 638 mykey2: "[1, 2, 3]", 639 mykey3: "ssssssssssssssssssssssssss", 640 mykey4: [false, true, false], 641 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 642 mykey6: true 643 } 644 } 645 ], 646 operationType: wantAgent.OperationType.START_ABILITIES, 647 requestCode: 0, 648 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 649} 650 651wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 652 currentAVSession.setLaunchAbility(agent).then(() => { 653 console.info('SetLaunchAbility successfully'); 654 }).catch((err: BusinessError) => { 655 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 656 }); 657}); 658``` 659 660### setLaunchAbility<sup>10+</sup> 661 662setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void 663 664设置一个WantAgent用于拉起会话的Ability。结果通过callback异步回调方式返回。 665 666**系统能力:** SystemCapability.Multimedia.AVSession.Core 667 668**参数:** 669 670| 参数名 | 类型 | 必填 | 说明 | 671| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 672| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是 | 应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 673| callback | AsyncCallback\<void> | 是 | 回调函数。当Ability设置成功,err为undefined,否则返回错误对象。 | 674 675**错误码:** 676 677以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 678 679| 错误码ID | 错误信息 | 680| -------- | ---------------------------------------- | 681| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 682| 6600101 | Session service exception. | 683| 6600102 | The session does not exist. | 684 685**示例:** 686 687```ts 688import { wantAgent } from '@kit.AbilityKit'; 689import { BusinessError } from '@kit.BasicServicesKit'; 690 691// WantAgentInfo对象 692let wantAgentInfo: wantAgent.WantAgentInfo = { 693 wants: [ 694 { 695 deviceId: "deviceId", 696 bundleName: "com.example.myapplication", 697 abilityName: "EntryAbility", 698 action: "action1", 699 entities: ["entity1"], 700 type: "MIMETYPE", 701 uri: "key = {true,true,false}", 702 parameters: 703 { 704 mykey0: 2222, 705 mykey1: [1, 2, 3], 706 mykey2: "[1, 2, 3]", 707 mykey3: "ssssssssssssssssssssssssss", 708 mykey4: [false, true, false], 709 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 710 mykey6: true 711 } 712 } 713 ], 714 operationType: wantAgent.OperationType.START_ABILITIES, 715 requestCode: 0, 716 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 717} 718 719wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 720 currentAVSession.setLaunchAbility(agent, (err: BusinessError) => { 721 if (err) { 722 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 723 } else { 724 console.info('SetLaunchAbility successfully'); 725 } 726 }); 727}); 728``` 729 730### dispatchSessionEvent<sup>10+</sup> 731 732dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void> 733 734媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容, 结果通过Promise异步回调方式返回。 735 736**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 737 738**系统能力:** SystemCapability.Multimedia.AVSession.Core 739 740**参数:** 741 742| 参数名 | 类型 | 必填 | 说明 | 743| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 744| event | string | 是 | 需要设置的会话事件的名称 | 745| args | {[key: string]: Object} | 是 | 需要传递的会话事件内容。 | 746 747> **说明:** 748> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 749 750**返回值:** 751 752| 类型 | 说明 | 753| -------------- | ----------------------------- | 754| Promise\<void> | Promise对象。当事件设置成功,无返回结果,否则返回错误对象。 | 755 756**错误码:** 757 758以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 759 760| 错误码ID | 错误信息 | 761| -------- | ---------------------------------------- | 762| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 763| 6600101 | Session service exception. | 764| 6600102 | The session does not exist. | 765 766**示例:** 767 768```ts 769import { BusinessError } from '@kit.BasicServicesKit'; 770 771let currentAVSession: avSession.AVSession | undefined = undefined; 772let tag = "createNewSession"; 773let context: Context = getContext(this); 774 775avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 776 if (err) { 777 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 778 } else { 779 currentAVSession = data; 780 } 781}); 782let eventName = "dynamic_lyric"; 783if (currentAVSession !== undefined) { 784 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => { 785 console.info('dispatchSessionEvent successfully'); 786 }).catch((err: BusinessError) => { 787 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 788 }) 789} 790``` 791 792### dispatchSessionEvent<sup>10+</sup> 793 794dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 795 796媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容, 结果通过callback异步回调方式返回。 797 798**系统能力:** SystemCapability.Multimedia.AVSession.Core 799 800**参数:** 801 802| 参数名 | 类型 | 必填 | 说明 | 803| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 804| event | string | 是 | 需要设置的会话事件的名称 | 805| args | {[key: string]: Object} | 是 | 需要传递的会话事件内容。 | 806| callback | AsyncCallback\<void> | 是 | 回调函数。当会话事件设置成功,err为undefined,否则返回错误对象。 | 807 808> **说明:** 809 810> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 811 812**错误码:** 813 814以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 815 816| 错误码ID | 错误信息 | 817| -------- | ---------------------------------------- | 818| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 819| 6600101 | Session service exception. | 820| 6600102 | The session does not exist. | 821 822**示例:** 823 824```ts 825import { BusinessError } from '@kit.BasicServicesKit'; 826 827let currentAVSession: avSession.AVSession | undefined = undefined; 828let tag = "createNewSession"; 829let context: Context = getContext(this); 830 831avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 832 if (err) { 833 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 834 } else { 835 currentAVSession = data; 836 } 837}); 838let eventName: string = "dynamic_lyric"; 839if (currentAVSession !== undefined) { 840 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => { 841 if (err) { 842 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 843 } 844 }) 845} 846``` 847 848### setAVQueueItems<sup>10+</sup> 849 850setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void> 851 852设置媒体播放列表。结果通过Promise异步回调方式返回。 853 854**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 855 856**系统能力:** SystemCapability.Multimedia.AVSession.Core 857 858**参数:** 859 860| 参数名 | 类型 | 必填 | 说明 | 861| ------ | ------------------------------------ | ---- | ---------------------------------- | 862| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | 863 864**返回值:** 865 866| 类型 | 说明 | 867| -------------- | ----------------------------- | 868| Promise\<void> | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | 869 870**错误码:** 871 872以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 873 874| 错误码ID | 错误信息 | 875| -------- | ---------------------------------------- | 876| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 877| 6600101 | Session service exception. | 878| 6600102 | The session does not exist. | 879 880**示例:** 881 882```ts 883import { image } from '@kit.ImageKit'; 884import { resourceManager } from '@kit.LocalizationKit'; 885import { BusinessError } from '@kit.BasicServicesKit'; 886 887async function setAVQueueItems() { 888 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 889 let imageSource = await image.createImageSource(value.buffer); 890 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 891 let queueItemDescription_1: avSession.AVMediaDescription = { 892 assetId: '001', 893 title: 'music_name', 894 subtitle: 'music_sub_name', 895 description: 'music_description', 896 mediaImage : imagePixel, 897 extras: {extras:'any'} 898 }; 899 let queueItem_1: avSession.AVQueueItem = { 900 itemId: 1, 901 description: queueItemDescription_1 902 }; 903 let queueItemDescription_2: avSession.AVMediaDescription = { 904 assetId: '002', 905 title: 'music_name', 906 subtitle: 'music_sub_name', 907 description: 'music_description', 908 mediaImage: imagePixel, 909 extras: {extras:'any'} 910 }; 911 let queueItem_2: avSession.AVQueueItem = { 912 itemId: 2, 913 description: queueItemDescription_2 914 }; 915 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 916 currentAVSession.setAVQueueItems(queueItemsArray).then(() => { 917 console.info('SetAVQueueItems successfully'); 918 }).catch((err: BusinessError) => { 919 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 920 }); 921} 922``` 923 924### setAVQueueItems<sup>10+</sup> 925 926setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void 927 928设置媒体播放列表。结果通过callback异步回调方式返回。 929 930**系统能力:** SystemCapability.Multimedia.AVSession.Core 931 932**参数:** 933 934| 参数名 | 类型 | 必填 | 说明 | 935| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | 936| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | 937| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 938 939**错误码:** 940 941以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 942 943| 错误码ID | 错误信息 | 944| -------- | ---------------------------------------- | 945| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 946| 6600101 | Session service exception. | 947| 6600102 | The session does not exist. | 948 949**示例:** 950 951```ts 952import { image } from '@kit.ImageKit'; 953import { resourceManager } from '@kit.LocalizationKit'; 954import { BusinessError } from '@kit.BasicServicesKit'; 955 956async function setAVQueueItems() { 957 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 958 let imageSource = await image.createImageSource(value.buffer); 959 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 960 let queueItemDescription_1: avSession.AVMediaDescription = { 961 assetId: '001', 962 title: 'music_name', 963 subtitle: 'music_sub_name', 964 description: 'music_description', 965 mediaImage : imagePixel, 966 extras: {extras:'any'} 967 }; 968 let queueItem_1: avSession.AVQueueItem = { 969 itemId: 1, 970 description: queueItemDescription_1 971 }; 972 let queueItemDescription_2: avSession.AVMediaDescription = { 973 assetId: '002', 974 title: 'music_name', 975 subtitle: 'music_sub_name', 976 description: 'music_description', 977 mediaImage: imagePixel, 978 extras: {extras:'any'} 979 }; 980 let queueItem_2: avSession.AVQueueItem = { 981 itemId: 2, 982 description: queueItemDescription_2 983 }; 984 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 985 currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => { 986 if (err) { 987 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 988 } else { 989 console.info('SetAVQueueItems successfully'); 990 } 991 }); 992} 993``` 994 995### setAVQueueTitle<sup>10+</sup> 996 997setAVQueueTitle(title: string): Promise\<void> 998 999设置媒体播放列表名称。结果通过Promise异步回调方式返回。 1000 1001**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1002 1003**系统能力:** SystemCapability.Multimedia.AVSession.Core 1004 1005**参数:** 1006 1007| 参数名 | 类型 | 必填 | 说明 | 1008| ------ | ------ | ---- | -------------- | 1009| title | string | 是 | 播放列表的名称。 | 1010 1011**返回值:** 1012 1013| 类型 | 说明 | 1014| -------------- | ----------------------------- | 1015| Promise\<void> | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | 1016 1017**错误码:** 1018 1019以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1020 1021| 错误码ID | 错误信息 | 1022| -------- | ---------------------------------------- | 1023| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1024| 6600101 | Session service exception. | 1025| 6600102 | The session does not exist. | 1026 1027**示例:** 1028 1029```ts 1030import { BusinessError } from '@kit.BasicServicesKit'; 1031 1032let queueTitle = 'QUEUE_TITLE'; 1033currentAVSession.setAVQueueTitle(queueTitle).then(() => { 1034 console.info('SetAVQueueTitle successfully'); 1035}).catch((err: BusinessError) => { 1036 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1037}); 1038``` 1039 1040### setAVQueueTitle<sup>10+</sup> 1041 1042setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void 1043 1044设置媒体播放列表名称。结果通过callback异步回调方式返回。 1045 1046**系统能力:** SystemCapability.Multimedia.AVSession.Core 1047 1048**参数:** 1049 1050| 参数名 | 类型 | 必填 | 说明 | 1051| -------- | --------------------- | ---- | ----------------------------------------------------------- | 1052| title | string | 是 | 播放列表名称字段。 | 1053| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 1054 1055**错误码:** 1056 1057以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1058 1059| 错误码ID | 错误信息 | 1060| -------- | ---------------------------------------- | 1061| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1062| 6600101 | Session service exception. | 1063| 6600102 | The session does not exist. | 1064 1065**示例:** 1066 1067```ts 1068import { BusinessError } from '@kit.BasicServicesKit'; 1069 1070let queueTitle = 'QUEUE_TITLE'; 1071currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => { 1072 if (err) { 1073 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1074 } else { 1075 console.info('SetAVQueueTitle successfully'); 1076 } 1077}); 1078``` 1079 1080### setExtras<sup>10+</sup> 1081 1082setExtras(extras: {[key: string]: Object}): Promise\<void> 1083 1084媒体提供方设置键值对形式的自定义媒体数据包, 结果通过Promise异步回调方式返回。 1085 1086**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1087 1088**系统能力:** SystemCapability.Multimedia.AVSession.Core 1089 1090**参数:** 1091 1092| 参数名 | 类型 | 必填 | 说明 | 1093| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1094| extras | {[key: string]: Object} | 是 | 需要传递的自定义媒体数据包键值对 | 1095 1096> **说明:** 1097 1098> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 1099 1100**返回值:** 1101 1102| 类型 | 说明 | 1103| -------------- | ----------------------------- | 1104| Promise\<void> | Promise对象。当自定义媒体数据包设置成功,无返回结果,否则返回错误对象。 | 1105 1106**错误码:** 1107 1108以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1109 1110| 错误码ID | 错误信息 | 1111| -------- | ---------------------------------------- | 1112| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1113| 6600101 | Session service exception. | 1114| 6600102 | The session does not exist. | 1115 1116**示例:** 1117 1118```ts 1119import { BusinessError } from '@kit.BasicServicesKit'; 1120 1121let currentAVSession: avSession.AVSession | undefined = undefined; 1122let tag = "createNewSession"; 1123let context: Context = getContext(this); 1124 1125avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1126 if (err) { 1127 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1128 } else { 1129 currentAVSession = data; 1130 } 1131}); 1132if (currentAVSession !== undefined) { 1133 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => { 1134 console.info('setExtras successfully'); 1135 }).catch((err: BusinessError) => { 1136 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1137 }) 1138} 1139``` 1140 1141### setExtras<sup>10+</sup> 1142 1143setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void 1144 1145媒体提供方设置键值对形式的自定义媒体数据包, 结果通过callback异步回调方式返回。 1146 1147**系统能力:** SystemCapability.Multimedia.AVSession.Core 1148 1149**参数:** 1150 1151| 参数名 | 类型 | 必填 | 说明 | 1152| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1153| extras | {[key: string]: Object} | 是 | 需要传递的自定义媒体数据包键值对 | 1154| callback | AsyncCallback\<void> | 是 | 回调函数。当自定义媒体数据包设置成功,err为undefined,否则返回错误对象。 | 1155 1156> **说明:** 1157 1158> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 1159 1160**错误码:** 1161 1162以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1163 1164| 错误码ID | 错误信息 | 1165| -------- | ---------------------------------------- | 1166| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1167| 6600101 | Session service exception. | 1168| 6600102 | The session does not exist. | 1169 1170**示例:** 1171 1172```ts 1173import { BusinessError } from '@kit.BasicServicesKit'; 1174 1175let currentAVSession: avSession.AVSession | undefined = undefined; 1176let tag = "createNewSession"; 1177let context: Context = getContext(this); 1178 1179avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1180 if (err) { 1181 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1182 } else { 1183 currentAVSession = data; 1184 } 1185}); 1186if (currentAVSession !== undefined) { 1187 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => { 1188 if (err) { 1189 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1190 } 1191 }) 1192} 1193``` 1194 1195### getController<sup>10+</sup> 1196 1197getController(): Promise\<AVSessionController> 1198 1199获取本会话对应的控制器。结果通过Promise异步回调方式返回。 1200 1201**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1202 1203**系统能力:** SystemCapability.Multimedia.AVSession.Core 1204 1205**返回值:** 1206 1207| 类型 | 说明 | 1208| ---------------------------------------------------- | ----------------------------- | 1209| Promise<[AVSessionController](#avsessioncontroller10)> | Promise对象。返回会话控制器。 | 1210 1211**错误码:** 1212 1213以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1214 1215| 错误码ID | 错误信息 | 1216| -------- | ---------------------------------------- | 1217| 6600101 | Session service exception. | 1218| 6600102 | The session does not exist. | 1219 1220**示例:** 1221 1222```ts 1223import { BusinessError } from '@kit.BasicServicesKit'; 1224 1225let avsessionController: avSession.AVSessionController; 1226currentAVSession.getController().then((avcontroller: avSession.AVSessionController) => { 1227 avsessionController = avcontroller; 1228 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1229}).catch((err: BusinessError) => { 1230 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1231}); 1232``` 1233 1234### getController<sup>10+</sup> 1235 1236getController(callback: AsyncCallback\<AVSessionController>): void 1237 1238获取本会话相应的控制器。结果通过callback异步回调方式返回。 1239 1240**系统能力:** SystemCapability.Multimedia.AVSession.Core 1241 1242**参数:** 1243 1244| 参数名 | 类型 | 必填 | 说明 | 1245| -------- | ----------------------------------------------------------- | ---- | -------------------------- | 1246| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | 是 | 回调函数。返回会话控制器。 | 1247 1248**错误码:** 1249 1250以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1251 1252| 错误码ID | 错误信息 | 1253| -------- | ---------------------------------------- | 1254| 6600101 | Session service exception. | 1255| 6600102 | The session does not exist. | 1256 1257**示例:** 1258 1259```ts 1260import { BusinessError } from '@kit.BasicServicesKit'; 1261 1262let avsessionController: avSession.AVSessionController; 1263currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => { 1264 if (err) { 1265 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1266 } else { 1267 avsessionController = avcontroller; 1268 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1269 } 1270}); 1271``` 1272 1273### getAVCastController<sup>10+</sup> 1274 1275getAVCastController(): Promise\<AVCastController> 1276 1277设备建立连接后,获取投播控制器。结果通过Promise异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。 1278 1279**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1280 1281**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 1282 1283**返回值:** 1284 1285| 类型 | 说明 | 1286| --------- | ------------------------------------------------------------ | 1287| Promise<[AVCastController](#avcastcontroller10)\> | Promise对象。返回投播控制器实例。 | 1288 1289**错误码:** 1290 1291以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1292 1293| 错误码ID | 错误信息 | 1294| -------- | --------------------------------------- | 1295| 6600102| The session does not exist. | 1296| 6600109| The remote connection is not established. | 1297 1298**示例:** 1299 1300```ts 1301import { BusinessError } from '@kit.BasicServicesKit'; 1302 1303let aVCastController: avSession.AVCastController; 1304currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => { 1305 aVCastController = avcontroller; 1306 console.info('getAVCastController : SUCCESS'); 1307}).catch((err: BusinessError) => { 1308 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1309}); 1310``` 1311 1312### getAVCastController<sup>10+</sup> 1313 1314getAVCastController(callback: AsyncCallback\<AVCastController>): void 1315 1316设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。 1317 1318**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 1319 1320**参数:** 1321 1322| 参数名 | 类型 | 必填 | 说明 | 1323| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1324| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | 是 | 回调函数,返回投播控制器实例。 | 1325 1326**错误码:** 1327 1328以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1329 1330| 错误码ID | 错误信息 | 1331| -------- |---------------------------------------| 1332| 6600102| The session does not exist. | 1333| 6600109| The remote connection is not established. | 1334 1335**示例:** 1336 1337```ts 1338import { BusinessError } from '@kit.BasicServicesKit'; 1339 1340let aVCastController: avSession.AVCastController; 1341currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => { 1342 if (err) { 1343 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1344 } else { 1345 aVCastController = avcontroller; 1346 console.info('getAVCastController : SUCCESS'); 1347 } 1348}); 1349``` 1350 1351### getOutputDevice<sup>10+</sup> 1352 1353getOutputDevice(): Promise\<OutputDeviceInfo> 1354 1355通过会话获取播放设备信息。结果通过Promise异步回调方式返回。 1356 1357**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1358 1359**系统能力:** SystemCapability.Multimedia.AVSession.Core 1360 1361**返回值:** 1362 1363| 类型 | 说明 | 1364| ---------------------------------------------- | --------------------------------- | 1365| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise对象。返回播放设备信息。 | 1366 1367**错误码:** 1368 1369以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1370 1371| 错误码ID | 错误信息 | 1372| -------- | ---------------------------------------- | 1373| 6600101 | Session service exception. | 1374| 6600102 | The session does not exist. | 1375 1376**示例:** 1377 1378```ts 1379import { BusinessError } from '@kit.BasicServicesKit'; 1380 1381currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => { 1382 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1383}).catch((err: BusinessError) => { 1384 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1385}) 1386``` 1387 1388### getOutputDevice<sup>10+</sup> 1389 1390getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 1391 1392通过会话获取播放设备相关信息。结果通过callback异步回调方式返回。 1393 1394**系统能力:** SystemCapability.Multimedia.AVSession.Core 1395 1396**参数:** 1397 1398| 参数名 | 类型 | 必填 | 说明 | 1399| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 1400| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是 | 回调函数,返回播放设备信息。 | 1401 1402**错误码:** 1403 1404以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1405 1406| 错误码ID | 错误信息 | 1407| -------- | ---------------------------------------- | 1408| 6600101 | Session service exception. | 1409| 6600102 | The session does not exist. | 1410 1411**示例:** 1412 1413```ts 1414import { BusinessError } from '@kit.BasicServicesKit'; 1415 1416currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => { 1417 if (err) { 1418 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1419 } else { 1420 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1421 } 1422}); 1423``` 1424 1425### activate<sup>10+</sup> 1426 1427activate(): Promise\<void> 1428 1429激活会话,激活后可正常使用会话。结果通过Promise异步回调方式返回。 1430 1431**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1432 1433**系统能力:** SystemCapability.Multimedia.AVSession.Core 1434 1435**返回值:** 1436 1437| 类型 | 说明 | 1438| -------------- | ----------------------------- | 1439| Promise\<void> | Promise对象。当会话激活成功,无返回结果,否则返回错误对象。 | 1440 1441**错误码:** 1442 1443以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1444 1445| 错误码ID | 错误信息 | 1446| -------- | ---------------------------------------- | 1447| 6600101 | Session service exception. | 1448| 6600102 | The session does not exist. | 1449 1450**示例:** 1451 1452```ts 1453import { BusinessError } from '@kit.BasicServicesKit'; 1454 1455currentAVSession.activate().then(() => { 1456 console.info('Activate : SUCCESS '); 1457}).catch((err: BusinessError) => { 1458 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1459}); 1460``` 1461 1462### activate<sup>10+</sup> 1463 1464activate(callback: AsyncCallback\<void>): void 1465 1466激活会话,激活后可正常使用会话。结果通过callback异步回调方式返回。 1467 1468**系统能力:** SystemCapability.Multimedia.AVSession.Core 1469 1470**参数:** 1471 1472| 参数名 | 类型 | 必填 | 说明 | 1473| -------- | -------------------- | ---- | ---------- | 1474| callback | AsyncCallback\<void> | 是 | 回调函数。当会话激活成功,err为undefined,否则返回错误对象。 | 1475 1476**错误码:** 1477 1478以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1479 1480| 错误码ID | 错误信息 | 1481| -------- | ---------------------------------------- | 1482| 6600101 | Session service exception. | 1483| 6600102 | The session does not exist. | 1484 1485**示例:** 1486 1487```ts 1488import { BusinessError } from '@kit.BasicServicesKit'; 1489 1490currentAVSession.activate((err: BusinessError) => { 1491 if (err) { 1492 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1493 } else { 1494 console.info('Activate : SUCCESS '); 1495 } 1496}); 1497``` 1498 1499### deactivate<sup>10+</sup> 1500 1501deactivate(): Promise\<void> 1502 1503禁用当前会话的功能,可通过[activate](#activate10)恢复。结果通过Promise异步回调方式返回。 1504 1505**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1506 1507**系统能力:** SystemCapability.Multimedia.AVSession.Core 1508 1509**返回值:** 1510 1511| 类型 | 说明 | 1512| -------------- | ----------------------------- | 1513| Promise\<void> | Promise对象。当禁用会话成功,无返回结果,否则返回错误对象。| 1514 1515**错误码:** 1516 1517以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1518 1519| 错误码ID | 错误信息 | 1520| -------- | ---------------------------------------- | 1521| 6600101 | Session service exception. | 1522| 6600102 | The session does not exist. | 1523 1524**示例:** 1525 1526```ts 1527import { BusinessError } from '@kit.BasicServicesKit'; 1528 1529currentAVSession.deactivate().then(() => { 1530 console.info('Deactivate : SUCCESS '); 1531}).catch((err: BusinessError) => { 1532 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1533}); 1534``` 1535 1536### deactivate<sup>10+</sup> 1537 1538deactivate(callback: AsyncCallback\<void>): void 1539 1540禁用当前会话。结果通过callback异步回调方式返回。 1541 1542禁用当前会话的功能,可通过[activate](#activate10)恢复。 1543 1544**系统能力:** SystemCapability.Multimedia.AVSession.Core 1545 1546**参数:** 1547 1548| 参数名 | 类型 | 必填 | 说明 | 1549| -------- | -------------------- | ---- | ---------- | 1550| callback | AsyncCallback\<void> | 是 | 回调函数。当禁用会话成功,err为undefined,否则返回错误对象。| 1551 1552**错误码:** 1553 1554以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1555 1556| 错误码ID | 错误信息 | 1557| -------- | ---------------------------------------- | 1558| 6600101 | Session service exception. | 1559| 6600102 | The session does not exist. | 1560 1561**示例:** 1562 1563```ts 1564import { BusinessError } from '@kit.BasicServicesKit'; 1565 1566currentAVSession.deactivate((err: BusinessError) => { 1567 if (err) { 1568 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1569 } else { 1570 console.info('Deactivate : SUCCESS '); 1571 } 1572}); 1573``` 1574 1575### destroy<sup>10+</sup> 1576 1577destroy(): Promise\<void> 1578 1579销毁当前会话,使当前会话完全失效。结果通过Promise异步回调方式返回。 1580 1581**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1582 1583**系统能力:** SystemCapability.Multimedia.AVSession.Core 1584 1585**返回值:** 1586 1587| 类型 | 说明 | 1588| -------------- | ----------------------------- | 1589| Promise\<void> | Promise对象。当会话销毁成功,无返回结果,否则返回错误对象。 | 1590 1591**错误码:** 1592 1593以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1594 1595| 错误码ID | 错误信息 | 1596| -------- | ---------------------------------------- | 1597| 6600101 | Session service exception. | 1598| 6600102 | The session does not exist. | 1599 1600**示例:** 1601 1602```ts 1603import { BusinessError } from '@kit.BasicServicesKit'; 1604 1605currentAVSession.destroy().then(() => { 1606 console.info('Destroy : SUCCESS '); 1607}).catch((err: BusinessError) => { 1608 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1609}); 1610``` 1611 1612### destroy<sup>10+</sup> 1613 1614destroy(callback: AsyncCallback\<void>): void 1615 1616销毁当前会话,使当前会话完全失效。结果通过callback异步回调方式返回。 1617 1618**系统能力:** SystemCapability.Multimedia.AVSession.Core 1619 1620**参数:** 1621 1622| 参数名 | 类型 | 必填 | 说明 | 1623| -------- | -------------------- | ---- | ---------- | 1624| callback | AsyncCallback\<void> | 是 | 回调函数。当会话销毁成功,err为undefined,否则返回错误对象。 | 1625 1626**错误码:** 1627 1628以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1629 1630| 错误码ID | 错误信息 | 1631| -------- | ---------------------------------------- | 1632| 6600101 | Session service exception. | 1633| 6600102 | The session does not exist. | 1634 1635**示例:** 1636 1637```ts 1638import { BusinessError } from '@kit.BasicServicesKit'; 1639 1640currentAVSession.destroy((err: BusinessError) => { 1641 if (err) { 1642 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1643 } else { 1644 console.info('Destroy : SUCCESS '); 1645 } 1646}); 1647``` 1648 1649### on('play')<sup>10+</sup> 1650 1651on(type: 'play', callback: () => void): void 1652 1653设置播放命令监听事件。注册该监听,说明应用支持播放指令。 1654 1655每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1656 1657**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1658 1659**系统能力:** SystemCapability.Multimedia.AVSession.Core 1660 1661**参数:** 1662 1663| 参数名 | 类型 | 必填 | 说明 | 1664| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1665| type | string | 是 | 事件回调类型,支持的事件为`'play'`当播放命令被发送到会话时,触发该事件回调。 | 1666| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1667 1668**错误码:** 1669 1670以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1671 1672| 错误码ID | 错误信息 | 1673| -------- | ---------------------------------------- | 1674| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1675| 6600101 | Session service exception. | 1676| 6600102 | The session does not exist. | 1677 1678**示例:** 1679 1680```ts 1681currentAVSession.on('play', () => { 1682 console.info('on play entry'); 1683}); 1684``` 1685 1686### on('pause')<sup>10+</sup> 1687 1688on(type: 'pause', callback: () => void): void 1689 1690设置暂停命令监听事件。注册该监听,说明应用支持暂停指令。 1691 1692每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1693 1694**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1695 1696**系统能力:** SystemCapability.Multimedia.AVSession.Core 1697 1698**参数:** 1699 1700| 参数名 | 类型 | 必填 | 说明 | 1701| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1702| type | string | 是 | 事件回调类型,支持的事件为`'pause'`,当暂停命令被发送到会话时,触发该事件回调。 | 1703| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1704 1705**错误码:** 1706 1707以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1708 1709| 错误码ID | 错误信息 | 1710| -------- | ---------------------------------------- | 1711| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1712| 6600101 | Session service exception. | 1713| 6600102 | The session does not exist. | 1714 1715**示例:** 1716 1717```ts 1718currentAVSession.on('pause', () => { 1719 console.info('on pause entry'); 1720}); 1721``` 1722 1723### on('stop')<sup>10+</sup> 1724 1725on(type:'stop', callback: () => void): void 1726 1727设置停止命令监听事件。注册该监听,说明应用支持停止指令。 1728 1729每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1730 1731**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1732 1733**系统能力:** SystemCapability.Multimedia.AVSession.Core 1734 1735**参数:** 1736 1737| 参数名 | 类型 | 必填 | 说明 | 1738| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1739| type | string | 是 | 事件回调类型,支持的事件是`'stop'`,当停止命令被发送到会话时,触发该事件回调。 | 1740| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1741 1742**错误码:** 1743 1744以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1745 1746| 错误码ID | 错误信息 | 1747| -------- | ---------------------------------------- | 1748| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1749| 6600101 | Session service exception. | 1750| 6600102 | The session does not exist. | 1751 1752**示例:** 1753 1754```ts 1755currentAVSession.on('stop', () => { 1756 console.info('on stop entry'); 1757}); 1758``` 1759 1760### on('playNext')<sup>10+</sup> 1761 1762on(type:'playNext', callback: () => void): void 1763 1764设置播放下一首命令监听事件。注册该监听,说明应用支持下一首指令。 1765 1766每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1767 1768**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1769 1770**系统能力:** SystemCapability.Multimedia.AVSession.Core 1771 1772**参数:** 1773 1774| 参数名 | 类型 | 必填 | 说明 | 1775| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1776| type | string | 是 | 事件回调类型,支持的事件是`'playNext'`,当播放下一首命令被发送到会话时,触发该事件回调。 | 1777| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1778 1779**错误码:** 1780 1781以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1782 1783| 错误码ID | 错误信息 | 1784| -------- | ---------------------------------------- | 1785| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1786| 6600101 | Session service exception. | 1787| 6600102 | The session does not exist. | 1788 1789**示例:** 1790 1791```ts 1792currentAVSession.on('playNext', () => { 1793 console.info('on playNext entry'); 1794}); 1795``` 1796 1797### on('playPrevious')<sup>10+</sup> 1798 1799on(type:'playPrevious', callback: () => void): void 1800 1801设置播放上一首命令监听事件。注册该监听,说明应用支持上一首指令。 1802 1803每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1804 1805**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1806 1807**系统能力:** SystemCapability.Multimedia.AVSession.Core 1808 1809**参数:** 1810 1811| 参数名 | 类型 | 必填 | 说明 | 1812| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1813| type | string | 是 | 事件回调类型,支持的事件是`'playPrevious'`当播放上一首命令被发送到会话时,触发该事件回调。 | 1814| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 1815 1816**错误码:** 1817 1818以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1819 1820| 错误码ID | 错误信息 | 1821| -------- | ---------------------------------------- | 1822| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1823| 6600101 | Session service exception. | 1824| 6600102 | The session does not exist. | 1825 1826**示例:** 1827 1828```ts 1829currentAVSession.on('playPrevious', () => { 1830 console.info('on playPrevious entry'); 1831}); 1832``` 1833 1834### on('fastForward')<sup>10+</sup> 1835 1836on(type: 'fastForward', callback: (time?: number) => void): void 1837 1838设置快进命令监听事件。注册该监听,说明应用支持快进指令。 1839 1840每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。 1841 1842**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1843 1844**系统能力:** SystemCapability.Multimedia.AVSession.Core 1845 1846**参数:** 1847 1848| 参数名 | 类型 | 必填 | 说明 | 1849| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1850| type | string | 是 | 事件回调类型,支持的事件是 `'fastForward'`,当快进命令被发送到会话时,触发该事件回调。 | 1851| callback | (time?: number) => void | 是 | 回调函数。参数time是时间节点,单位为秒。 | 1852 1853**错误码:** 1854 1855以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1856 1857| 错误码ID | 错误信息 | 1858| -------- | ---------------------------------------- | 1859| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1860| 6600101 | Session service exception. | 1861| 6600102 | The session does not exist. | 1862 1863**示例:** 1864 1865```ts 1866currentAVSession.on('fastForward', (time?: number) => { 1867 console.info('on fastForward entry'); 1868}); 1869``` 1870 1871### on('rewind')<sup>10+</sup> 1872 1873on(type:'rewind', callback: (time?: number) => void): void 1874 1875设置快退命令监听事件。 1876 1877**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1878 1879**系统能力:** SystemCapability.Multimedia.AVSession.Core 1880 1881**参数:** 1882 1883| 参数名 | 类型 | 必填 | 说明 | 1884| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1885| type | string | 是 | 事件回调类型,支持的事件是`'rewind'`,当快退命令被发送到会话时,触发该事件回调。 | 1886| callback | (time?: number) => void | 是 | 回调函数。参数time是时间节点,单位为秒。 | 1887 1888**错误码:** 1889 1890以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1891 1892| 错误码ID | 错误信息 | 1893| -------- | ---------------------------------------- | 1894| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1895| 6600101 | Session service exception. | 1896| 6600102 | The session does not exist. | 1897 1898**示例:** 1899 1900```ts 1901currentAVSession.on('rewind', (time?: number) => { 1902 console.info('on rewind entry'); 1903}); 1904``` 1905 1906### on('playFromAssetId')<sup>11+</sup> 1907 1908on(type:'playFromAssetId', callback: (assetId: number) => void): void 1909 1910设置媒体id播放监听事件。 1911 1912**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1913 1914**系统能力:** SystemCapability.Multimedia.AVSession.Core 1915 1916**参数:** 1917 1918| 参数名 | 类型 | 必填 | 说明 | 1919| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1920| type | string | 是 | 事件回调类型,支持的事件是`'playFromAssetId'`,当媒体id播放时,触发该事件回调。 | 1921| callback | callback: (assetId: number) => void | 是 | 回调函数。参数assetId是媒体id。 | 1922 1923**错误码:** 1924 1925以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1926 1927| 错误码ID | 错误信息 | 1928| -------- | ---------------------------------------- | 1929| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1930| 6600101 | Session service exception. | 1931| 6600102 | The session does not exist. | 1932 1933**示例:** 1934 1935```ts 1936currentAVSession.on('playFromAssetId', (assetId: number) => { 1937 console.info('on playFromAssetId entry'); 1938}); 1939``` 1940 1941### off('playFromAssetId')<sup>11+</sup> 1942 1943off(type: 'playFromAssetId', callback?: (assetId: number) => void): void 1944 1945取消媒体id播放事件监听,关闭后,不再进行该事件回调。 1946 1947**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1948 1949**系统能力:** SystemCapability.Multimedia.AVSession.Core 1950 1951**参数:** 1952 1953| 参数名 | 类型 | 必填 | 说明 | 1954| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 1955| type | string | 是 | 关闭对应的监听事件,支持的事件是`'playFromAssetId'`。 | 1956| callback | callback: (assetId: number) => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。参数assetId是媒体id。 | 1957 1958**错误码:** 1959 1960以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1961 1962| 错误码ID | 错误信息 | 1963| -------- | ---------------------------------------- | 1964| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1965| 6600101 | Session service exception. | 1966| 6600102 | The session does not exist. | 1967 1968**示例:** 1969 1970```ts 1971currentAVSession.off('playFromAssetId'); 1972``` 1973 1974### on('seek')<sup>10+</sup> 1975 1976on(type: 'seek', callback: (time: number) => void): void 1977 1978设置跳转节点监听事件。 1979 1980**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 1981 1982**系统能力:** SystemCapability.Multimedia.AVSession.Core 1983 1984**参数:** 1985 1986| 参数名 | 类型 | 必填 | 说明 | 1987| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1988| type | string | 是 | 事件回调类型,支持事件`'seek'`:当跳转节点命令被发送到会话时,触发该事件。 | 1989| callback | (time: number) => void | 是 | 回调函数。参数time是时间节点,单位为毫秒。 | 1990 1991**错误码:** 1992 1993以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 1994 1995| 错误码ID | 错误信息 | 1996| -------- | ---------------------------------------- | 1997| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1998| 6600101 | Session service exception. | 1999| 6600102 | The session does not exist. | 2000 2001**示例:** 2002 2003```ts 2004currentAVSession.on('seek', (time: number) => { 2005 console.info(`on seek entry time : ${time}`); 2006}); 2007``` 2008 2009### on('setSpeed')<sup>10+</sup> 2010 2011on(type: 'setSpeed', callback: (speed: number) => void): void 2012 2013设置播放速率的监听事件。 2014 2015**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2016 2017**系统能力:** SystemCapability.Multimedia.AVSession.Core 2018 2019**参数:** 2020 2021| 参数名 | 类型 | 必填 | 说明 | 2022| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 2023| type | string | 是 | 事件回调类型,支持事件`'setSpeed'`:当设置播放速率的命令被发送到会话时,触发该事件。 | 2024| callback | (speed: number) => void | 是 | 回调函数。参数speed是播放倍速。 | 2025 2026**错误码:** 2027 2028以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2029 2030| 错误码ID | 错误信息 | 2031| -------- | ---------------------------------------- | 2032| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2033| 6600101 | Session service exception. | 2034| 6600102 | The session does not exist. | 2035 2036**示例:** 2037 2038```ts 2039currentAVSession.on('setSpeed', (speed: number) => { 2040 console.info(`on setSpeed speed : ${speed}`); 2041}); 2042``` 2043 2044### on('setLoopMode')<sup>10+</sup> 2045 2046on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void 2047 2048设置循环模式的监听事件。 2049 2050**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2051 2052**系统能力:** SystemCapability.Multimedia.AVSession.Core 2053 2054**参数:** 2055 2056| 参数名 | 类型 | 必填 | 说明 | 2057| -------- | ------------------------------------- | ---- | ---- | 2058| type | string | 是 | 事件回调类型,支持事件`'setLoopMode'`:当设置循环模式的命令被发送到会话时,触发该事件。 | 2059| callback | (mode: [LoopMode](#loopmode10)) => void | 是 | 回调函数。参数mode是循环模式。 | 2060 2061**错误码:** 2062 2063以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2064 2065| 错误码ID | 错误信息 | 2066| -------- | ---------------------------------------- | 2067| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2068| 6600101 | Session service exception. | 2069| 6600102 | The session does not exist. | 2070 2071**示例:** 2072 2073```ts 2074currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => { 2075 console.info(`on setLoopMode mode : ${mode}`); 2076}); 2077``` 2078 2079### on('toggleFavorite')<sup>10+</sup> 2080 2081on(type: 'toggleFavorite', callback: (assetId: string) => void): void 2082 2083设置是否收藏的监听事件 2084 2085**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2086 2087**系统能力:** SystemCapability.Multimedia.AVSession.Core 2088 2089**参数:** 2090 2091| 参数名 | 类型 | 必填 | 说明 | 2092| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 2093| type | string | 是 | 事件回调类型,支持事件`'toggleFavorite'`:当是否收藏的命令被发送到会话时,触发该事件。 | 2094| callback | (assetId: string) => void | 是 | 回调函数。参数assetId是媒体ID。 | 2095 2096**错误码:** 2097 2098以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2099 2100| 错误码ID | 错误信息 | 2101| -------- | ---------------------------------------- | 2102| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2103| 6600101 | Session service exception. | 2104| 6600102 | The session does not exist. | 2105 2106**示例:** 2107 2108```ts 2109currentAVSession.on('toggleFavorite', (assetId: string) => { 2110 console.info(`on toggleFavorite mode : ${assetId}`); 2111}); 2112``` 2113 2114### on('skipToQueueItem')<sup>10+</sup> 2115 2116on(type: 'skipToQueueItem', callback: (itemId: number) => void): void 2117 2118设置播放列表其中某项被选中的监听事件,session端可以选择对这个单项歌曲进行播放。 2119 2120**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2121 2122**系统能力:** SystemCapability.Multimedia.AVSession.Core 2123 2124**参数:** 2125 2126| 参数名 | 类型 | 必填 | 说明 | 2127| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- | 2128| type | string | 是 | 事件回调类型,支持事件`'skipToQueueItem'`:当播放列表选中单项的命令被发送到会话时,触发该事件。 | 2129| callback | (itemId: number) => void | 是 | 回调函数。参数itemId是选中的播放列表项的ID。 | 2130 2131**错误码:** 2132 2133以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2134 2135| 错误码ID | 错误信息 | 2136| -------- | ---------------------------------------- | 2137| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2138| 6600101 | Session service exception. | 2139| 6600102 | The session does not exist. | 2140 2141**示例:** 2142 2143```ts 2144currentAVSession.on('skipToQueueItem', (itemId: number) => { 2145 console.info(`on skipToQueueItem id : ${itemId}`); 2146}); 2147``` 2148 2149### on('handleKeyEvent')<sup>10+</sup> 2150 2151on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void 2152 2153设置蓝牙/有线等外设接入的按键输入事件的监听,监听多媒体按键事件中播放、暂停、上下一首、快进、快退的指令。 2154 2155**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2156 2157**系统能力:** SystemCapability.Multimedia.AVSession.Core 2158 2159**参数:** 2160 2161| 参数名 | 类型 | 必填 | 说明 | 2162| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2163| type | string | 是 | 事件回调类型,支持事件`'handleKeyEvent'`:当按键事件被发送到会话时,触发该事件。 | 2164| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | 是 | 回调函数。参数event是按键事件。 | 2165 2166**错误码:** 2167 2168以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2169 2170| 错误码ID | 错误信息 | 2171| -------- | ---------------------------------------- | 2172| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2173| 6600101 | Session service exception. | 2174| 6600102 | The session does not exist. | 2175 2176**示例:** 2177 2178```ts 2179import { KeyEvent } from '@kit.InputKit'; 2180 2181currentAVSession.on('handleKeyEvent', (event: KeyEvent) => { 2182 console.info(`on handleKeyEvent event : ${event}`); 2183}); 2184 2185``` 2186 2187### on('outputDeviceChange')<sup>10+</sup> 2188 2189on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 2190 2191设置播放设备变化的监听事件。应用接入[系统投播组件](ohos-multimedia-avcastpicker.md),当用户通过组件切换设备时,会收到设备切换的回调。 2192 2193**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2194 2195**系统能力:** SystemCapability.Multimedia.AVSession.Core 2196 2197**参数:** 2198 2199| 参数名 | 类型 | 必填 | 说明 | 2200| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2201| type | string | 是 | 事件回调类型,支持事件`'outputDeviceChange'`:当播放设备变化时,触发该事件。 | 2202| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是 | 回调函数,参数device是设备相关信息。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2203 2204**错误码:** 2205 2206以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2207 2208| 错误码ID | 错误信息 | 2209| -------- | ---------------------------------------- | 2210| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2211| 6600101 | Session service exception. | 2212| 6600102 | The session does not exist. | 2213 2214**示例:** 2215 2216```ts 2217currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 2218 console.info(`on outputDeviceChange device : ${device}`); 2219}); 2220``` 2221 2222### on('commonCommand')<sup>10+</sup> 2223 2224on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void 2225 2226设置自定义控制命令变化的监听器。 2227 2228**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2229 2230**系统能力:** SystemCapability.Multimedia.AVSession.Core 2231 2232**参数:** 2233 2234| 参数名 | 类型 | 必填 | 说明 | 2235| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2236| type | string | 是 | 事件回调类型,支持事件`'commonCommand'`:当自定义控制命令变化时,触发该事件。 | 2237| callback | (command: string, args: {[key:string]: Object}) => void | 是 | 回调函数,command为变化的自定义控制命令名,args为自定义控制命令的参数,参数内容与[sendCommonCommand](#sendcommoncommand10)方法设置的参数内容完全一致。 | 2238 2239**错误码:** 2240 2241以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2242 2243| 错误码ID | 错误信息 | 2244| -------- | ------------------------------ | 2245| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2246| 6600101 | Session service exception. | 2247| 6600102 | The session does not exist. | 2248 2249**示例:** 2250 2251```ts 2252import { BusinessError } from '@kit.BasicServicesKit'; 2253 2254let currentAVSession: avSession.AVSession | undefined = undefined; 2255let tag = "createNewSession"; 2256let context: Context = getContext(this); 2257 2258avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 2259 if (err) { 2260 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 2261 } else { 2262 currentAVSession = data; 2263 } 2264}); 2265if (currentAVSession !== undefined) { 2266 (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => { 2267 console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); 2268 }); 2269} 2270``` 2271 2272### off('play')<sup>10+</sup> 2273 2274off(type: 'play', callback?: () => void): void 2275 2276取消会话播放事件监听,关闭后,不再进行该事件回调。 2277 2278取消回调时,需要更新支持的命令列表。 2279 2280**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2281 2282**系统能力:** SystemCapability.Multimedia.AVSession.Core 2283 2284**参数:** 2285 2286| 参数名 | 类型 | 必填 | 说明 | 2287| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2288| type | string | 是 | 关闭对应的监听事件,支持的事件是`'play'`| 2289| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2290 2291**错误码:** 2292 2293以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2294 2295| 错误码ID | 错误信息 | 2296| -------- | ---------------------------------------- | 2297| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2298| 6600101 | Session service exception. | 2299| 6600102 | The session does not exist. | 2300 2301**示例:** 2302 2303```ts 2304currentAVSession.off('play'); 2305``` 2306 2307### off('pause')<sup>10+</sup> 2308 2309off(type: 'pause', callback?: () => void): void 2310 2311取消会话暂停事件监听,关闭后,不再进行该事件回调。 2312 2313取消回调时,需要更新支持的命令列表。 2314 2315**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2316 2317**系统能力:** SystemCapability.Multimedia.AVSession.Core 2318 2319**参数:** 2320 2321| 参数名 | 类型 | 必填 | 说明 | 2322| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2323| type | string | 是 | 关闭对应的监听事件,支持的事件是`'pause'`。 | 2324| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2325 2326**错误码:** 2327 2328以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2329 2330| 错误码ID | 错误信息 | 2331| -------- | ---------------------------------------- | 2332| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2333| 6600101 | Session service exception. | 2334| 6600102 | The session does not exist. | 2335 2336**示例:** 2337 2338```ts 2339currentAVSession.off('pause'); 2340``` 2341 2342### off('stop')<sup>10+</sup> 2343 2344off(type: 'stop', callback?: () => void): void 2345 2346取消会话停止事件监听,关闭后,不再进行该事件回调。 2347 2348取消回调时,需要更新支持的命令列表。 2349 2350**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2351 2352**系统能力:** SystemCapability.Multimedia.AVSession.Core 2353 2354**参数:** 2355 2356| 参数名 | 类型 | 必填 | 说明 | 2357| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2358| type | string | 是 | 关闭对应的监听事件,支持的事件是`'stop'`。 | 2359| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2360 2361**错误码:** 2362 2363以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2364 2365| 错误码ID | 错误信息 | 2366| -------- | ---------------------------------------- | 2367| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2368| 6600101 | Session service exception. | 2369| 6600102 | The session does not exist. | 2370 2371**示例:** 2372 2373```ts 2374currentAVSession.off('stop'); 2375``` 2376 2377### off('playNext')<sup>10+</sup> 2378 2379off(type: 'playNext', callback?: () => void): void 2380 2381取消会话播放下一首事件监听,关闭后,不再进行该事件回调。 2382 2383取消回调时,需要更新支持的命令列表。 2384 2385**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2386 2387**系统能力:** SystemCapability.Multimedia.AVSession.Core 2388 2389**参数:** 2390 2391| 参数名 | 类型 | 必填 | 说明 | 2392| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2393| type | string | 是 | 关闭对应的监听事件,支持的事件是 `'playNext'`。 | 2394| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2395 2396**错误码:** 2397 2398以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2399 2400| 错误码ID | 错误信息 | 2401| -------- | ---------------------------------------- | 2402| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2403| 6600101 | Session service exception. | 2404| 6600102 | The session does not exist. | 2405 2406**示例:** 2407 2408```ts 2409currentAVSession.off('playNext'); 2410``` 2411 2412### off('playPrevious')<sup>10+</sup> 2413 2414off(type: 'playPrevious', callback?: () => void): void 2415 2416取消会话播放上一首事件监听,关闭后,不再进行该事件回调。 2417 2418取消回调时,需要更新支持的命令列表。 2419 2420**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2421 2422**系统能力:** SystemCapability.Multimedia.AVSession.Core 2423 2424**参数:** 2425 2426| 参数名 | 类型 | 必填 | 说明 | 2427| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2428| type | string | 是 | 关闭对应的监听事件,支持的事件是`'playPrevious'`。 | 2429| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2430 2431**错误码:** 2432 2433以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2434 2435| 错误码ID | 错误信息 | 2436| -------- | ---------------------------------------- | 2437| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2438| 6600101 | Session service exception. | 2439| 6600102 | The session does not exist. | 2440 2441**示例:** 2442 2443```ts 2444currentAVSession.off('playPrevious'); 2445``` 2446 2447### off('fastForward')<sup>10+</sup> 2448 2449off(type: 'fastForward', callback?: () => void): void 2450 2451取消会话快进事件监听,关闭后,不再进行该事件回调。 2452 2453取消回调时,需要更新支持的命令列表。 2454 2455**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2456 2457**系统能力:** SystemCapability.Multimedia.AVSession.Core 2458 2459**参数:** 2460 2461| 参数名 | 类型 | 必填 | 说明 | 2462| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2463| type | string | 是 | 关闭对应的监听事件,支持的事件是`'fastForward'`。 | 2464| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2465 2466**错误码:** 2467 2468以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2469 2470| 错误码ID | 错误信息 | 2471| -------- | ---------------------------------------- | 2472| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2473| 6600101 | Session service exception. | 2474| 6600102 | The session does not exist. | 2475 2476**示例:** 2477 2478```ts 2479currentAVSession.off('fastForward'); 2480``` 2481 2482### off('rewind')<sup>10+</sup> 2483 2484off(type: 'rewind', callback?: () => void): void 2485 2486取消会话快退事件监听,关闭后,不再进行该事件回调。 2487 2488**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2489 2490**系统能力:** SystemCapability.Multimedia.AVSession.Core 2491 2492**参数:** 2493 2494| 参数名 | 类型 | 必填 | 说明 | 2495| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2496| type | string | 是 | 关闭对应的监听事件,支持的事件是`'rewind'`。 | 2497| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2498 2499**错误码:** 2500 2501以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2502 2503| 错误码ID | 错误信息 | 2504| -------- | ---------------------------------------- | 2505| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2506| 6600101 | Session service exception. | 2507| 6600102 | The session does not exist. | 2508 2509**示例:** 2510 2511```ts 2512currentAVSession.off('rewind'); 2513``` 2514 2515### off('seek')<sup>10+</sup> 2516 2517off(type: 'seek', callback?: (time: number) => void): void 2518 2519取消监听跳转节点事件。 2520 2521**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2522 2523**系统能力:** SystemCapability.Multimedia.AVSession.Core 2524 2525**参数:** 2526 2527| 参数名 | 类型 | 必填 | 说明 | 2528| -------- | ---------------------- | ---- | ----------------------------------------- | 2529| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'seek'`。 | 2530| callback | (time: number) => void | 否 | 回调函数,参数time是时间节点,单位为毫秒。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2531 2532**错误码:** 2533 2534以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2535 2536| 错误码ID | 错误信息 | 2537| -------- | ---------------------------------------- | 2538| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2539| 6600101 | Session service exception. | 2540| 6600102 | The session does not exist. | 2541 2542**示例:** 2543 2544```ts 2545currentAVSession.off('seek'); 2546``` 2547 2548### off('setSpeed')<sup>10+</sup> 2549 2550off(type: 'setSpeed', callback?: (speed: number) => void): void 2551 2552取消监听播放速率变化事件。 2553 2554**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2555 2556**系统能力:** SystemCapability.Multimedia.AVSession.Core 2557 2558**参数:** 2559 2560| 参数名 | 类型 | 必填 | 说明 | 2561| -------- | ----------------------- | ---- | -------------------------------------------| 2562| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'setSpeed'`。 | 2563| callback | (speed: number) => void | 否 | 回调函数,参数speed是播放倍速。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2564 2565**错误码:** 2566 2567以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2568 2569| 错误码ID | 错误信息 | 2570| -------- | ---------------------------------------- | 2571| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2572| 6600101 | Session service exception. | 2573| 6600102 | The session does not exist. | 2574 2575**示例:** 2576 2577```ts 2578currentAVSession.off('setSpeed'); 2579``` 2580 2581### off('setLoopMode')<sup>10+</sup> 2582 2583off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void 2584 2585取消监听循环模式变化事件。 2586 2587**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2588 2589**系统能力:** SystemCapability.Multimedia.AVSession.Core 2590 2591**参数:** 2592 2593| 参数名 | 类型 | 必填 | 说明 | 2594| -------- | ------------------------------------- | ---- | ----- | 2595| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'setLoopMode'`。| 2596| callback | (mode: [LoopMode](#loopmode10)) => void | 否 | 回调函数,参数mode是循环模式。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2597 2598**错误码:** 2599 2600以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2601 2602| 错误码ID | 错误信息 | 2603| -------- | ---------------------------------------- | 2604| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2605| 6600101 | Session service exception. | 2606| 6600102 | The session does not exist. | 2607 2608**示例:** 2609 2610```ts 2611currentAVSession.off('setLoopMode'); 2612``` 2613 2614### off('toggleFavorite')<sup>10+</sup> 2615 2616off(type: 'toggleFavorite', callback?: (assetId: string) => void): void 2617 2618取消监听是否收藏的事件 2619 2620**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2621 2622**系统能力:** SystemCapability.Multimedia.AVSession.Core 2623 2624**参数:** 2625 2626| 参数名 | 类型 | 必填 | 说明 | 2627| -------- | ------------------------- | ---- | -------------------------------------------------------- | 2628| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'toggleFavorite'`。 | 2629| callback | (assetId: string) => void | 否 | 回调函数,参数assetId是媒体ID。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2630 2631**错误码:** 2632 2633以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2634 2635| 错误码ID | 错误信息 | 2636| -------- | ---------------------------------------- | 2637| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2638| 6600101 | Session service exception. | 2639| 6600102 | The session does not exist. | 2640 2641**示例:** 2642 2643```ts 2644currentAVSession.off('toggleFavorite'); 2645``` 2646 2647### off('skipToQueueItem')<sup>10+</sup> 2648 2649off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void 2650 2651取消监听播放列表单项选中的事件 2652 2653**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2654 2655**系统能力:** SystemCapability.Multimedia.AVSession.Core 2656 2657**参数:** 2658 2659| 参数名 | 类型 | 必填 | 说明 | 2660| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | 2661| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'skipToQueueItem'`。 | 2662| callback | (itemId: number) => void | 否 | 回调函数,参数itemId是播放列表单项ID。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2663 2664**错误码:** 2665 2666以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2667 2668| 错误码ID | 错误信息 | 2669| -------- | ---------------------------------------- | 2670| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2671| 6600101 | Session service exception. | 2672| 6600102 | The session does not exist. | 2673 2674**示例:** 2675 2676```ts 2677currentAVSession.off('skipToQueueItem'); 2678``` 2679 2680### off('handleKeyEvent')<sup>10+</sup> 2681 2682off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void 2683 2684取消监听按键事件。 2685 2686**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2687 2688**系统能力:** SystemCapability.Multimedia.AVSession.Core 2689 2690**参数:** 2691 2692| 参数名 | 类型 | 必填 | 说明 | 2693| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2694| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'handleKeyEvent'`。 | 2695| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | 否 | 回调函数,参数event是按键事件。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2696 2697**错误码:** 2698 2699以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2700 2701| 错误码ID | 错误信息 | 2702| -------- | ---------------------------------------- | 2703| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2704| 6600101 | Session service exception. | 2705| 6600102 | The session does not exist. | 2706 2707**示例:** 2708 2709```ts 2710currentAVSession.off('handleKeyEvent'); 2711``` 2712 2713### off('outputDeviceChange')<sup>10+</sup> 2714 2715off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 2716 2717取消监听播放设备变化的事件。 2718 2719**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2720 2721**系统能力:** SystemCapability.Multimedia.AVSession.Core 2722 2723**参数:** 2724 2725| 参数名 | 类型 | 必填 | 说明 | 2726| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 2727| type | string | 是 | 关闭对应的监听事件,支持关闭事件`'outputDeviceChange'`。 | 2728| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否 | 回调函数,参数device是设备相关信息。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2729 2730**错误码:** 2731 2732以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2733 2734| 错误码ID | 错误信息 | 2735| -------- | ---------------------------------------- | 2736| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2737| 6600101 | Session service exception. | 2738| 6600102 | The session does not exist. | 2739 2740**示例:** 2741 2742```ts 2743currentAVSession.off('outputDeviceChange'); 2744``` 2745 2746 2747### off('commonCommand')<sup>10+</sup> 2748 2749off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void 2750 2751取消监听自定义控制命令的变化。 2752 2753**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2754 2755**系统能力:** SystemCapability.Multimedia.AVSession.Core 2756 2757**参数:** 2758 2759| 参数名 | 类型 | 必填 | 说明 | 2760| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 2761| type | string | 是 | 取消对应的监听事件,支持事件`'commonCommand'`。 | 2762| callback | (command: string, args: {[key:string]: Object}) => void | 否 | 回调函数,参数command是变化的自定义控制命令名,args为自定义控制命令的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对command事件的监听。 | 2763 2764**错误码:** 2765 2766以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2767 2768| 错误码ID | 错误信息 | 2769| -------- | ---------------- | 2770| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2771| 6600101 | Session service exception. | 2772| 6600102 | The session does not exist. | 2773 2774**示例:** 2775 2776```ts 2777currentAVSession.off('commonCommand'); 2778``` 2779 2780### on('answer')<sup>11+</sup> 2781 2782on(type: 'answer', callback: Callback\<void>): void; 2783 2784设置通话接听的监听事件。 2785 2786**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2787 2788**系统能力:** SystemCapability.Multimedia.AVSession.Core 2789 2790**参数:** 2791 2792| 参数名 | 类型 | 必填 | 说明 | 2793| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2794| type | string | 是 | 事件回调类型,支持事件`'answer'`:当通话接听时,触发该事件。 | 2795| callback | Callback\<void> | 是 | 回调函数 | 2796 2797**错误码:** 2798 2799以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2800 2801| 错误码ID | 错误信息 | 2802| -------- | ------------------------------ | 2803| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2804| 6600101 | Session service exception. | 2805| 6600102 | The session does not exist. | 2806 2807**示例:** 2808 2809```ts 2810currentAVSession.on('answer', () => { 2811 console.info('on call answer'); 2812}); 2813``` 2814 2815### off('answer')<sup>11+</sup> 2816 2817off(type: 'answer', callback?: Callback\<void>): void; 2818 2819取消通话接听事件的监听。 2820 2821**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2822 2823**系统能力:** SystemCapability.Multimedia.AVSession.Core 2824 2825**参数:** 2826 2827| 参数名 | 类型 | 必填 | 说明 | 2828| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2829| type | string | 是 | 关闭对应的监听事件,支持的事件是`'answer'`。 | 2830| callback | Callback\<void> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2831 2832**错误码:** 2833 2834以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2835 2836| 错误码ID | 错误信息 | 2837| -------- | ---------------------------------------- | 2838| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2839| 6600101 | Session service exception. | 2840| 6600102 | The session does not exist. | 2841 2842**示例:** 2843 2844```ts 2845currentAVSession.off('answer'); 2846``` 2847 2848### on('hangUp')<sup>11+</sup> 2849 2850on(type: 'hangUp', callback: Callback\<void>): void; 2851 2852设置通话挂断的监听事件。 2853 2854**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2855 2856**系统能力:** SystemCapability.Multimedia.AVSession.Core 2857 2858**参数:** 2859 2860| 参数名 | 类型 | 必填 | 说明 | 2861| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2862| type | string | 是 | 事件回调类型,支持事件`'hangUp'`:当通话挂断时,触发该事件。 | 2863| callback | Callback\<void> | 是 | 回调函数 | 2864 2865**错误码:** 2866 2867以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2868 2869| 错误码ID | 错误信息 | 2870| -------- | ------------------------------ | 2871| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2872| 6600101 | Session service exception. | 2873| 6600102 | The session does not exist. | 2874 2875**示例:** 2876 2877```ts 2878currentAVSession.on('hangUp', () => { 2879 console.info('on call hangUp'); 2880}); 2881``` 2882 2883### off('hangUp')<sup>11+</sup> 2884 2885off(type: 'hangUp', callback?: Callback\<void>): void; 2886 2887取消通话挂断事件的监听。 2888 2889**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2890 2891**系统能力:** SystemCapability.Multimedia.AVSession.Core 2892 2893**参数:** 2894 2895| 参数名 | 类型 | 必填 | 说明 | 2896| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2897| type | string | 是 | 关闭对应的监听事件,支持的事件是`'hangUp'`。 | 2898| callback | Callback\<void> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2899 2900**错误码:** 2901 2902以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2903 2904| 错误码ID | 错误信息 | 2905| -------- | ---------------------------------------- | 2906| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2907| 6600101 | Session service exception. | 2908| 6600102 | The session does not exist. | 2909 2910**示例:** 2911 2912```ts 2913currentAVSession.off('hangUp'); 2914``` 2915 2916### on('toggleCallMute')<sup>11+</sup> 2917 2918on(type: 'toggleCallMute', callback: Callback\<void>): void; 2919 2920设置通话静音的监听事件。 2921 2922**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2923 2924**系统能力:** SystemCapability.Multimedia.AVSession.Core 2925 2926**参数:** 2927 2928| 参数名 | 类型 | 必填 | 说明 | 2929| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2930| type | string | 是 | 事件回调类型,支持事件`'toggleCallMute'`:当通话静音或解除静音时,触发该事件。 | 2931| callback | Callback\<void> | 是 | 回调函数 | 2932 2933**错误码:** 2934 2935以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2936 2937| 错误码ID | 错误信息 | 2938| -------- | ------------------------------ | 2939| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2940| 6600101 | Session service exception. | 2941| 6600102 | The session does not exist. | 2942 2943**示例:** 2944 2945```ts 2946currentAVSession.on('toggleCallMute', () => { 2947 console.info('on call toggleCallMute'); 2948}); 2949``` 2950 2951### off('toggleCallMute')<sup>11+</sup> 2952 2953off(type: 'toggleCallMute', callback?: Callback\<void>): void; 2954 2955取消通话静音事件的监听。 2956 2957**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2958 2959**系统能力:** SystemCapability.Multimedia.AVSession.Core 2960 2961**参数:** 2962 2963| 参数名 | 类型 | 必填 | 说明 | 2964| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2965| type | string | 是 | 关闭对应的监听事件,支持的事件是`'toggleCallMute'`。 | 2966| callback | Callback\<void> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 2967 2968**错误码:** 2969 2970以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 2971 2972| 错误码ID | 错误信息 | 2973| -------- | ---------------------------------------- | 2974| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2975| 6600101 | Session service exception. | 2976| 6600102 | The session does not exist. | 2977 2978**示例:** 2979 2980```ts 2981currentAVSession.off('toggleCallMute'); 2982``` 2983 2984### on('castDisplayChange')<sup>12+</sup> 2985 2986on(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void 2987 2988设置扩展屏投播显示设备变化的监听事件。 2989 2990**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 2991 2992**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 2993 2994**参数:** 2995 2996| 参数名 | 类型 | 必填 | 说明 | 2997| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2998| type | string | 是 | 事件回调类型,支持事件`'castDisplayChange'`:当扩展屏投播显示设备变化时触发事件。 | 2999| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)> | 是 | 回调函数。参数是扩展屏投播显示设备信息。 | 3000 3001**错误码:** 3002 3003以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3004 3005| 错误码ID | 错误信息 | 3006| -------- | ---------------------------------------- | 3007| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3008| 6600101 | Session service exception. | 3009| 6600102 | The session does not exist. | 3010 3011**示例:** 3012 3013```ts 3014let castDisplay: avSession.CastDisplayInfo; 3015currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => { 3016 if (display.state === avSession.CastDisplayState.STATE_ON) { 3017 castDisplay = display; 3018 console.info(`Succeeded in castDisplayChange display : ${display.id} ON`); 3019 } else if (display.state === avSession.CastDisplayState.STATE_OFF){ 3020 console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`); 3021 } 3022}); 3023``` 3024### off('castDisplayChange')<sup>12+</sup> 3025 3026 off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void 3027 3028取消扩展屏投播显示设备变化事件监听,关闭后,不再进行该事件回调。 3029 3030**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3031 3032**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3033 3034**参数:** 3035 3036| 参数名 | 类型 | 必填 | 说明 | 3037| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3038| type | string | 是 | 关闭对应的监听事件,支持的事件是`'castDisplayChange'`。 | 3039| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 3040 3041**错误码:** 3042 3043以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3044 3045| 错误码ID | 错误信息 | 3046| -------- | ---------------------------------------- | 3047| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3048| 6600101 | Session service exception. | 3049| 6600102 | The session does not exist. | 3050 3051**示例:** 3052 3053```ts 3054currentAVSession.off('castDisplayChange'); 3055``` 3056 3057### stopCasting<sup>10+</sup> 3058 3059stopCasting(callback: AsyncCallback\<void>): void 3060 3061结束投播。结果通过callback异步回调方式返回。 3062 3063**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3064 3065**参数:** 3066 3067| 参数名 | 类型 | 必填 | 说明 | 3068| -------- | ------------------------------------- | ---- | ------------------------------------- | 3069| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3070 3071**错误码:** 3072 3073以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3074 3075| 错误码ID | 错误信息 | 3076| -------- | ---------------------------------------- | 3077| 6600109 | The remote connection is not established. | 3078 3079**示例:** 3080 3081```ts 3082import { BusinessError } from '@kit.BasicServicesKit'; 3083 3084currentAVSession.stopCasting((err: BusinessError) => { 3085 if (err) { 3086 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3087 } else { 3088 console.info('stopCasting successfully'); 3089 } 3090}); 3091``` 3092 3093### stopCasting<sup>10+</sup> 3094 3095stopCasting(): Promise\<void> 3096 3097结束投播。结果通过Promise异步回调方式返回。 3098 3099**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3100 3101**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3102 3103**返回值:** 3104 3105| 类型 | 说明 | 3106| -------------- | ----------------------------- | 3107| Promise\<void> | Promise对象。当成功结束投播,无返回结果,否则返回错误对象。 | 3108 3109**错误码:** 3110 3111以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3112 3113| 错误码ID | 错误信息 | 3114| -------- | ---------------------------------------- | 3115| 6600109 | The remote connection is not established. | 3116 3117**示例:** 3118 3119```ts 3120import { BusinessError } from '@kit.BasicServicesKit'; 3121 3122currentAVSession.stopCasting().then(() => { 3123 console.info('stopCasting successfully'); 3124}).catch((err: BusinessError) => { 3125 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3126}); 3127``` 3128 3129### getOutputDeviceSync<sup>10+</sup> 3130 3131getOutputDeviceSync(): OutputDeviceInfo 3132 3133使用同步方法获取当前输出设备信息。 3134 3135**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3136 3137**系统能力:** SystemCapability.Multimedia.AVSession.Core 3138 3139**返回值:** 3140 3141| 类型 | 说明 | 3142| ----------------------------------------------- | --------------------------------- | 3143| [OutputDeviceInfo](#outputdeviceinfo10) | 当前输出设备信息。 | 3144 3145**错误码:** 3146 3147以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3148 3149| 错误码ID | 错误信息 | 3150|---------| --------------------------------------- | 3151| 6600101 | Session service exception. | 3152| 6600102 | The session does not exist. | 3153 3154**示例:** 3155 3156```ts 3157import { BusinessError } from '@kit.BasicServicesKit'; 3158 3159try { 3160 let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync(); 3161} catch (err) { 3162 let error = err as BusinessError; 3163 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 3164} 3165``` 3166### getAllCastDisplays<sup>12+</sup> 3167 3168getAllCastDisplays(): Promise<Array\<CastDisplayInfo>> 3169 3170获取当前系统中所有支持扩展屏投播的显示设备。通过Promise异步回调方式返回。 3171 3172**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3173 3174**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3175 3176**返回值:** 3177 3178| 类型 | 说明 | 3179| ----------------------------------------------- | --------------------------------- | 3180| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise对象,返回当前系统中所有支持扩展屏投播的显示设备。 | 3181 3182**错误码:** 3183 3184以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3185 3186| 错误码ID | 错误信息 | 3187|---------| --------------------------------------- | 3188| 6600101 | Session service exception. | 3189| 6600102 | The session does not exist. | 3190 3191**示例:** 3192 3193```ts 3194import { BusinessError } from '@kit.BasicServicesKit'; 3195 3196let castDisplay: avSession.CastDisplayInfo; 3197currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => { 3198 if (data.length >= 1) { 3199 castDisplay = data[0]; 3200 } 3201 }).catch((err: BusinessError) => { 3202 console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`); 3203 }); 3204``` 3205 3206## AVCastControlCommandType<sup>10+</sup> 3207 3208type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 3209 'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute' 3210 3211投播控制器可传递的命令。 3212 3213**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3214 3215**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3216 3217| 类型 | 说明 | 3218| ---------------- | ------------ | 3219| 'play' | 播放 | 3220| 'pause' | 暂停 | 3221| 'stop' | 停止 | 3222| 'playNext' | 下一首 | 3223| 'playPrevious' | 上一首 | 3224| 'fastForward' | 快进 | 3225| 'rewind' | 快退 | 3226| 'seek' | 跳转某一节点 | 3227| 'setVolume' | 设置音量 | 3228| 'setSpeed' | 设置播放倍速 | 3229| 'setLoopMode' | 设置循环模式 | 3230| 'toggleFavorite' | 是否收藏 | 3231| 'toggleMute' | 设置静音状态 | 3232 3233## AVCastControlCommand<sup>10+</sup> 3234 3235投播控制器接受的命令的对象描述。 3236 3237**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3238 3239**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3240 3241| 名称 | 类型 | 必填 | 说明 | 3242| --------- | ------------------------------------------------- | ---- | -------------- | 3243| command | [AVCastControlCommandType](#avcastcontrolcommandtype10) | 是 | 命令 | 3244| parameter | [media.PlaybackSpeed](../apis-media-kit/js-apis-media.md#playbackspeed8) | number | string | [LoopMode](#loopmode10) | 否 | 命令对应的参数 | 3245 3246## AVCastController<sup>10+</sup> 3247 3248在投播建立后,调用[avSession.getAVCastController](#getavcastcontroller10)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 3249 3250### getAVPlaybackState<sup>10+</sup> 3251 3252getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 3253 3254获取当前的远端播放状态。结果通过callback异步回调方式返回。 3255 3256**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3257 3258**参数:** 3259 3260| 参数名 | 类型 | 必填 | 说明 | 3261| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3262| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | 是 | 回调函数,返回远端播放状态。 | 3263 3264**错误码:** 3265 3266以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3267 3268| 错误码ID | 错误信息 | 3269| -------- | ---------------------------------------- | 3270| 6600101 | Session service exception | 3271 3272**示例:** 3273 3274```ts 3275import { BusinessError } from '@kit.BasicServicesKit'; 3276 3277aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 3278 if (err) { 3279 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3280 } else { 3281 console.info('getAVPlaybackState : SUCCESS'); 3282 } 3283}); 3284``` 3285 3286### getAVPlaybackState<sup>10+</sup> 3287 3288getAVPlaybackState(): Promise\<AVPlaybackState> 3289 3290获取当前的远端播放状态。结果通过Promise异步回调方式返回。 3291 3292**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3293 3294**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3295 3296**返回值:** 3297 3298| 类型 | 说明 | 3299| --------- | ------------------------------------------------------------ | 3300| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise对象。返回远端播放状态。 | 3301 3302**错误码:** 3303 3304以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3305 3306| 错误码ID | 错误信息 | 3307| -------- | ---------------------------------------- | 3308| 6600101 | Session service exception | 3309 3310**示例:** 3311 3312```ts 3313import { BusinessError } from '@kit.BasicServicesKit'; 3314 3315aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 3316 console.info('getAVPlaybackState : SUCCESS'); 3317}).catch((err: BusinessError) => { 3318 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3319}); 3320``` 3321 3322### sendControlCommand<sup>10+</sup> 3323 3324sendControlCommand(command: AVCastControlCommand): Promise\<void> 3325 3326通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 3327 3328 3329**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3330 3331**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3332 3333**参数:** 3334 3335| 参数名 | 类型 | 必填 | 说明 | 3336| ------- | ------------------------------------- | ---- | ------------------------------ | 3337| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 3338 3339**返回值:** 3340 3341| 类型 | 说明 | 3342| -------------- | ----------------------------- | 3343| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 3344 3345**错误码:** 3346 3347以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3348 3349| 错误码ID | 错误信息 | 3350| -------- | ---------------------------------------- | 3351| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3352| 6600101 | Session service exception. | 3353| 6600105 | Invalid session command. | 3354| 6600109 | The remote connection is not established. | 3355 3356**示例:** 3357 3358```ts 3359import { BusinessError } from '@kit.BasicServicesKit'; 3360 3361let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3362aVCastController.sendControlCommand(avCommand).then(() => { 3363 console.info('SendControlCommand successfully'); 3364}).catch((err: BusinessError) => { 3365 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3366}); 3367``` 3368 3369### sendControlCommand<sup>10+</sup> 3370 3371sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void 3372 3373通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 3374 3375 3376**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3377 3378**参数:** 3379 3380| 参数名 | 类型 | 必填 | 说明 | 3381| -------- | ------------------------------------- | ---- | ------------------------------ | 3382| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 3383| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3384 3385**错误码:** 3386 3387以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3388 3389| 错误码ID | 错误信息 | 3390| -------- | ------------------------------- | 3391| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3392| 6600101 | Session service exception. | 3393| 6600105 | Invalid session command. | 3394| 6600109 | The remote connection is not established. | 3395 3396**示例:** 3397 3398```ts 3399import { BusinessError } from '@kit.BasicServicesKit'; 3400 3401let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3402aVCastController.sendControlCommand(avCommand, (err: BusinessError) => { 3403 if (err) { 3404 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3405 } else { 3406 console.info('SendControlCommand successfully'); 3407 } 3408}); 3409``` 3410 3411### prepare<sup>10+</sup> 3412 3413prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void 3414 3415准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过callback异步回调方式返回。 3416 3417**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3418 3419**参数:** 3420 3421| 参数名 | 类型 | 必填 | 说明 | 3422| ------- | ------------------------------------- | ---- | ------------------------------ | 3423| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 3424| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3425 3426**错误码:** 3427 3428以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3429 3430| 错误码ID | 错误信息 | 3431| -------- | ---------------------------------------- | 3432| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3433| 6600101 | Session service exception. | 3434| 6600109 | The remote connection is not established. | 3435 3436**示例:** 3437 3438```ts 3439import { BusinessError } from '@kit.BasicServicesKit'; 3440 3441// 设置播放参数,开始播放 3442let playItem: avSession.AVQueueItem = { 3443 itemId: 0, 3444 description: { 3445 assetId: '12345', 3446 mediaType: 'AUDIO', 3447 mediaUri: 'http://resource1_address', 3448 mediaSize: 12345, 3449 startPosition: 0, 3450 duration: 0, 3451 artist: 'mysong', 3452 albumTitle: 'song1_title', 3453 albumCoverUri: "http://resource1_album_address", 3454 lyricUri: "http://resource1_lyric_address", 3455 appName: 'MyMusic' 3456 } 3457}; 3458// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 3459aVCastController.prepare(playItem, (err: BusinessError) => { 3460 if (err) { 3461 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3462 } else { 3463 console.info('prepare successfully'); 3464 } 3465}); 3466``` 3467 3468 3469### prepare<sup>10+</sup> 3470 3471prepare(item: AVQueueItem): Promise\<void> 3472 3473准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过Promise异步回调方式返回。 3474 3475 3476**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3477 3478**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3479 3480**参数:** 3481 3482| 参数名 | 类型 | 必填 | 说明 | 3483| ------- | ------------------------------------- | ---- | ------------------------------ | 3484| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 3485 3486**返回值:** 3487 3488| 类型 | 说明 | 3489| -------------- | ----------------------------- | 3490| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 3491 3492**错误码:** 3493 3494以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3495 3496| 错误码ID | 错误信息 | 3497| -------- | ---------------------------------------- | 3498| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3499| 6600101 | Session service exception. | 3500| 6600109 | The remote connection is not established. | 3501 3502 3503**示例:** 3504 3505```ts 3506import { BusinessError } from '@kit.BasicServicesKit'; 3507 3508// 设置播放参数,开始播放 3509let playItem: avSession.AVQueueItem = { 3510 itemId: 0, 3511 description: { 3512 assetId: '12345', 3513 mediaType: 'AUDIO', 3514 mediaUri: 'http://resource1_address', 3515 mediaSize: 12345, 3516 startPosition: 0, 3517 duration: 0, 3518 artist: 'mysong', 3519 albumTitle: 'song1_title', 3520 albumCoverUri: "http://resource1_album_address", 3521 lyricUri: "http://resource1_lyric_address", 3522 appName: 'MyMusic' 3523 } 3524}; 3525// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 3526aVCastController.prepare(playItem).then(() => { 3527 console.info('prepare successfully'); 3528}).catch((err: BusinessError) => { 3529 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3530}); 3531``` 3532 3533### start<sup>10+</sup> 3534 3535start(item: AVQueueItem, callback: AsyncCallback\<void>): void 3536 3537启动播放某个媒体资源。结果通过callback异步回调方式返回。 3538 3539**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3540 3541**参数:** 3542 3543| 参数名 | 类型 | 必填 | 说明 | 3544| ------- | ------------------------------------- | ---- | ------------------------------ | 3545| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 3546| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3547 3548**错误码:** 3549 3550以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3551 3552| 错误码ID | 错误信息 | 3553| -------- | ---------------------------------------- | 3554| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3555| 6600101 | Session service exception. | 3556| 6600109 | The remote connection is not established. | 3557 3558**示例:** 3559 3560```ts 3561import { BusinessError } from '@kit.BasicServicesKit'; 3562 3563// 设置播放参数,开始播放 3564let playItem: avSession.AVQueueItem = { 3565 itemId: 0, 3566 description: { 3567 assetId: '12345', 3568 mediaType: 'AUDIO', 3569 mediaUri: 'http://resource1_address', 3570 mediaSize: 12345, 3571 startPosition: 0, 3572 duration: 0, 3573 artist: 'mysong', 3574 albumTitle: 'song1_title', 3575 albumCoverUri: "http://resource1_album_address", 3576 lyricUri: "http://resource1_lyric_address", 3577 appName: 'MyMusic' 3578 } 3579}; 3580 3581// 启动播放 3582aVCastController.start(playItem, (err: BusinessError) => { 3583 if (err) { 3584 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 3585 } else { 3586 console.info('start successfully'); 3587 } 3588}); 3589``` 3590 3591### start<sup>10+</sup> 3592 3593start(item: AVQueueItem): Promise\<void> 3594 3595启动播放某个媒体资源。结果通过Promise异步回调方式返回。 3596 3597 3598**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3599 3600**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3601 3602**参数:** 3603 3604| 参数名 | 类型 | 必填 | 说明 | 3605| ------- | ------------------------------------- | ---- | ------------------------------ | 3606| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | 3607 3608**返回值:** 3609 3610| 类型 | 说明 | 3611| -------------- | ----------------------------- | 3612| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 3613 3614**错误码:** 3615 3616以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3617 3618| 错误码ID | 错误信息 | 3619| -------- | ---------------------------------------- | 3620| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3621| 6600101 | Session service exception. | 3622| 6600109 | The remote connection is not established. | 3623 3624 3625**示例:** 3626 3627```ts 3628import { BusinessError } from '@kit.BasicServicesKit'; 3629 3630// 设置播放参数,开始播放 3631let playItem: avSession.AVQueueItem = { 3632 itemId: 0, 3633 description: { 3634 assetId: '12345', 3635 mediaType: 'AUDIO', 3636 mediaUri: 'http://resource1_address', 3637 mediaSize: 12345, 3638 startPosition: 0, 3639 duration: 0, 3640 artist: 'mysong', 3641 albumTitle: 'song1_title', 3642 albumCoverUri: "http://resource1_album_address", 3643 lyricUri: "http://resource1_lyric_address", 3644 appName: 'MyMusic' 3645 } 3646}; 3647// 启动播放 3648aVCastController.start(playItem).then(() => { 3649 console.info('start successfully'); 3650}).catch((err: BusinessError) => { 3651 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 3652}); 3653``` 3654 3655### getCurrentItem<sup>10+</sup> 3656 3657getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void 3658 3659获取当前投播的资源信息。结果通过callback异步回调方式返回。 3660 3661**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3662 3663**参数:** 3664 3665| 参数名 | 类型 | 必填 | 说明 | 3666| -------- | ------------------------------------- | ---- | ------------------------------------- | 3667| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 3668 3669**错误码:** 3670 3671以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3672 3673| 错误码ID | 错误信息 | 3674| -------- | ---------------------------------------- | 3675| 6600101 | Session service exception. | 3676 3677**示例:** 3678 3679```ts 3680import { BusinessError } from '@kit.BasicServicesKit'; 3681 3682aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => { 3683 if (err) { 3684 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 3685 } else { 3686 console.info('getCurrentItem successfully'); 3687 } 3688}); 3689``` 3690 3691### getCurrentItem<sup>10+</sup> 3692 3693getCurrentItem(): Promise\<AVQueueItem> 3694 3695获取当前投播的资源信息。结果通过Promise异步回调方式返回。 3696 3697**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3698 3699**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3700 3701**返回值:** 3702 3703| 类型 | 说明 | 3704| -------------- | ----------------------------- | 3705| Promise\<[AVQueueItem](#avqueueitem10)> | Promise对象,返回当前的播放资源,否则返回错误对象。 | 3706 3707**错误码:** 3708 3709以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3710 3711| 错误码ID | 错误信息 | 3712| -------- | ---------------------------------------- | 3713| 6600101 | Session service exception. | 3714 3715**示例:** 3716 3717```ts 3718import { BusinessError } from '@kit.BasicServicesKit'; 3719 3720aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => { 3721 console.info('getCurrentItem successfully'); 3722}).catch((err: BusinessError) => { 3723 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 3724}); 3725``` 3726 3727### getValidCommands<sup>11+</sup> 3728 3729getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void 3730 3731获取当前支持的命令。结果通过callback异步回调方式返回。 3732 3733**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3734 3735**参数:** 3736 3737| 参数名 | 类型 | 必填 | 说明 | 3738| -------- | ------------------------------------- | ---- | ------------------------------------- | 3739| callback | Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)> | 是 | 回调函数。返回当前支持的命令。 | 3740 3741**错误码:** 3742 3743以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3744 3745| 错误码ID | 错误信息 | 3746| -------- | ---------------------------------------- | 3747| 6600101 | Session service exception. | 3748 3749**示例:** 3750 3751```ts 3752import { BusinessError } from '@kit.BasicServicesKit'; 3753 3754aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType) => { 3755 if (err) { 3756 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 3757 } else { 3758 console.info('getValidCommands successfully'); 3759 } 3760}); 3761``` 3762 3763### getValidCommands<sup>11+</sup> 3764 3765getValidCommands(): Promise<Array\<AVCastControlCommandType>> 3766 3767获取当前支持的命令。结果通过Promise异步回调方式返回。 3768 3769**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3770 3771**返回值:** 3772 3773| 类型 | 说明 | 3774| -------------- | ----------------------------- | 3775| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise对象,返回当前支持的命令。 | 3776 3777**错误码:** 3778 3779以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3780 3781| 错误码ID | 错误信息 | 3782| -------- | ---------------------------------------- | 3783| 6600101 | Session service exception. | 3784 3785**示例:** 3786 3787```ts 3788import { BusinessError } from '@kit.BasicServicesKit'; 3789 3790aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType) => { 3791 console.info('getValidCommands successfully'); 3792}).catch((err: BusinessError) => { 3793 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 3794}); 3795``` 3796 3797### processMediaKeyResponse<sup>12+</sup> 3798 3799processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void> 3800 3801在线DRM资源投播时,处理许可证响应。结果通过Promise异步回调方式返回。 3802 3803**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3804 3805**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3806 3807**参数:** 3808 3809| 参数名 | 类型 | 必填 | 说明 | 3810| -------- | ------------------------------------- | ---- | ------------------------------------- | 3811| assetId | string | 是 | 媒体ID。 | 3812| response | Uint8Array | 是 | 许可证响应。 | 3813 3814**返回值:** 3815 3816| 类型 | 说明 | 3817| -------------- | ----------------------------- | 3818| Promise\<void> | Promise对象,当处理许可证响应成功,无返回结果,否则返回错误对象。 | 3819 3820**错误码:** 3821 3822以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3823 3824| 错误码ID | 错误信息 | 3825| -------- | ---------------------------------------- | 3826| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3827| 6600101 | Session service exception. | 3828 3829**示例:** 3830 3831```ts 3832let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 3833 // 根据assetId获取对应的DRM url 3834 let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense'; 3835 // 从服务器获取许可证,需要开发者根据实际情况进行赋值 3836 let licenseResponseData: Uint8Array = new Uint8Array(); 3837 console.info(`Succeeded in get license by ${drmUrl}.`); 3838 aVCastController.processMediaKeyResponse(assetId, licenseResponseData); 3839} 3840``` 3841 3842### release<sup>11+</sup> 3843 3844release(callback: AsyncCallback\<void>): void 3845 3846销毁当前controller,结果通过callback异步回调方式返回。 3847 3848**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3849 3850**参数:** 3851 3852| 参数名 | 类型 | 必填 | 说明 | 3853| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 3854| callback | AsyncCallback\<void> | 是 | 回调函数。当命令执行成功,err为undefined,否则返回错误对象。 | 3855 3856**错误码:** 3857 3858以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3859 3860| 错误码ID | 错误信息 | 3861| -------- | -------------------------- | 3862| 6600101 | Session service exception. | 3863 3864**示例:** 3865 3866```ts 3867import { BusinessError } from '@kit.BasicServicesKit'; 3868 3869aVCastController.release((err: BusinessError) => { 3870 if (err) { 3871 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 3872 } else { 3873 console.info('release successfully'); 3874 } 3875}); 3876``` 3877 3878### release<sup>11+</sup> 3879 3880release(): Promise\<void> 3881 3882销毁当前controller。结果通过Promise异步回调方式返回。 3883 3884**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3885 3886**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3887 3888**返回值:** 3889 3890| 类型 | 说明 | 3891| -------------- | ----------------------------- | 3892| Promise\<void> | Promise对象,controller销毁成功,无结果返回,否则返回错误对象。 | 3893 3894**错误码:** 3895 3896以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3897 3898| 错误码ID | 错误信息 | 3899| -------- | ------------------------------ | 3900| 6600101 | Session service exception. | 3901 3902**示例:** 3903 3904```ts 3905import { BusinessError } from '@kit.BasicServicesKit'; 3906 3907aVCastController.release().then(() => { 3908 console.info('release successfully'); 3909}).catch((err: BusinessError) => { 3910 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 3911}); 3912 3913``` 3914 3915### on('playbackStateChange')<sup>10+</sup> 3916 3917on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void 3918 3919设置播放状态变化的监听事件。 3920 3921**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3922 3923**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3924 3925**参数:** 3926 3927| 参数名 | 类型 | 必填 | 说明 | 3928| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3929| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | 3930| filter | Array\<keyof [AVPlaybackState](#avplaybackstate10)\> | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array<keyof [AVPlaybackState](#avplaybackstate10)\> 表示关注Array中的字段变化。 | 3931| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。 | 3932 3933**错误码:** 3934 3935以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3936 3937| 错误码ID | 错误信息 | 3938| -------- | ------------------------------ | 3939| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3940| 6600101 | Session service exception. | 3941 3942**示例:** 3943 3944```ts 3945aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 3946 console.info(`on playbackStateChange state : ${playbackState.state}`); 3947}); 3948 3949let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode']; 3950aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => { 3951 console.info(`on playbackStateChange state : ${playbackState.state}`); 3952}); 3953``` 3954 3955### off('playbackStateChange')<sup>10+</sup> 3956 3957off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void 3958 3959媒体控制器取消监听播放状态变化的事件。 3960 3961**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3962 3963**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3964 3965**参数:** 3966 3967| 参数名 | 类型 | 必填 | 说明 | 3968| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 3969| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | 3970| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 3971 3972**错误码:** 3973 3974以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 3975 3976| 错误码ID | 错误信息 | 3977| -------- | ---------------- | 3978| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3979| 6600101 | Session service exception. | 3980 3981**示例:** 3982 3983```ts 3984aVCastController.off('playbackStateChange'); 3985``` 3986 3987### on('mediaItemChange')<sup>10+</sup> 3988 3989on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void 3990 3991设置投播当前播放媒体内容的监听事件。 3992 3993**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 3994 3995**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 3996 3997**参数:** 3998 3999| 参数名 | 类型 | 必填 | 说明 | 4000| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4001| type | string | 是 | 事件回调类型,支持事件`'mediaItemChange'`:当播放的媒体内容变化时,触发该事件。 | 4002| callback | (callback: [AVQueueItem](#avqueueitem10)) => void | 是 | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。 | 4003 4004**错误码:** 4005 4006以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4007 4008| 错误码ID | 错误信息 | 4009| -------- | ------------------------------ | 4010| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4011| 6600101 | Session service exception. | 4012 4013**示例:** 4014 4015```ts 4016aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => { 4017 console.info(`on mediaItemChange state : ${item.itemId}`); 4018}); 4019``` 4020 4021### off('mediaItemChange')<sup>10+</sup> 4022 4023off(type: 'mediaItemChange'): void 4024 4025取消设置投播当前播放媒体内容的监听事件。 4026 4027**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4028 4029**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4030 4031**参数:** 4032 4033| 参数名 | 类型 | 必填 | 说明 | 4034| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4035| type | string | 是 | 取消对应的监听事件,支持事件`'mediaItemChange'`。 | 4036 4037**错误码:** 4038 4039以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4040 4041| 错误码ID | 错误信息 | 4042| -------- | ---------------- | 4043| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4044| 6600101 | Session service exception. | 4045 4046**示例:** 4047 4048```ts 4049aVCastController.off('mediaItemChange'); 4050``` 4051 4052### on('playNext')<sup>10+</sup> 4053 4054on(type: 'playNext', callback: Callback\<void>): void 4055 4056设置播放下一首资源的监听事件。 4057 4058**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4059 4060**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4061 4062**参数:** 4063 4064| 参数名 | 类型 | 必填 | 说明 | 4065| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4066| type | string | 是 | 事件回调类型,支持事件`'playNext'`:当播放下一首状态变化时,触发该事件。 | 4067| callback | Callback\<void\> | 是 | 回调函数 | 4068 4069**错误码:** 4070 4071以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4072 4073| 错误码ID | 错误信息 | 4074| -------- | ------------------------------ | 4075| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4076| 6600101 | Session service exception. | 4077 4078**示例:** 4079 4080```ts 4081aVCastController.on('playNext', () => { 4082 console.info('on playNext'); 4083}); 4084``` 4085 4086### off('playNext')<sup>10+</sup> 4087 4088off(type: 'playNext'): void 4089 4090取消设置播放下一首资源的监听事件。 4091 4092**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4093 4094**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4095 4096**参数:** 4097 4098| 参数名 | 类型 | 必填 | 说明 | 4099| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4100| type | string | 是 | 取消对应的监听事件,支持事件`'playNext'`。 | 4101 4102**错误码:** 4103 4104以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4105 4106| 错误码ID | 错误信息 | 4107| -------- | ---------------- | 4108| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4109| 6600101 | Session service exception. | 4110 4111**示例:** 4112 4113```ts 4114aVCastController.off('playNext'); 4115``` 4116 4117### on('playPrevious')<sup>10+</sup> 4118 4119on(type: 'playPrevious', callback: Callback\<void>): void 4120 4121设置播放上一首资源的监听事件。 4122 4123**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4124 4125**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4126 4127**参数:** 4128 4129| 参数名 | 类型 | 必填 | 说明 | 4130| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4131| type | string | 是 | 事件回调类型,支持事件`'playPrevious'`:当播放上一首状态变化时,触发该事件。 | 4132| callback | Callback\<void\> | 是 | 回调函数 | 4133 4134**错误码:** 4135 4136以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4137 4138| 错误码ID | 错误信息 | 4139| -------- | ------------------------------ | 4140| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4141| 6600101 | Session service exception. | 4142 4143**示例:** 4144 4145```ts 4146aVCastController.on('playPrevious', () => { 4147 console.info('on playPrevious'); 4148}); 4149``` 4150 4151### off('playPrevious')<sup>10+</sup> 4152 4153off(type: 'playPrevious'): void 4154 4155取消设置播放上一首资源的监听事件。 4156 4157**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4158 4159**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4160 4161**参数:** 4162 4163| 参数名 | 类型 | 必填 | 说明 | 4164| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4165| type | string | 是 | 取消对应的监听事件,支持事件`'playPrevious'`。 | 4166 4167**错误码:** 4168 4169以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4170 4171| 错误码ID | 错误信息 | 4172| -------- | ---------------- | 4173| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4174| 6600101 | Session service exception. | 4175 4176**示例:** 4177 4178```ts 4179aVCastController.off('playPrevious'); 4180``` 4181 4182### on('requestPlay')<sup>11+</sup> 4183 4184on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void 4185 4186设置请求播放的监听事件。 4187 4188**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4189 4190**参数:** 4191 4192| 参数名 | 类型 | 必填 | 说明 | 4193| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4194| type | string | 是 | 事件回调类型,支持事件`'requestPlay'`:当请求播放状态变化时,触发该事件。 | 4195| callback | (state: [AVQueueItem](#avqueueitem10)) => void | 是 | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件注册成功,err为undefined,否则返回错误对象。 | 4196 4197**错误码:** 4198 4199以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4200 4201| 错误码ID | 错误信息 | 4202| -------- | ------------------------------ | 4203| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4204| 6600101 | Session service exception. | 4205 4206**示例:** 4207 4208```ts 4209aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => { 4210 console.info(`on requestPlay state : ${item.itemId}`); 4211}); 4212``` 4213 4214### off('requestPlay')<sup>11+</sup> 4215 4216off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void 4217 4218取消设置请求播放的监听事件。 4219 4220**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4221 4222**参数:** 4223 4224| 参数名 | 类型 | 必填 | 说明 | 4225| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4226| type | string | 是 | 取消对应的监听事件,支持事件`'requestPlay'`。 | 4227| callback | (state: [AVQueueItem](#avqueueitem10)) => void | 否 | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。| 4228 4229**错误码:** 4230 4231以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4232 4233| 错误码ID | 错误信息 | 4234| -------- | ---------------- | 4235| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4236| 6600101 | Session service exception. | 4237 4238**示例:** 4239 4240```ts 4241aVCastController.off('requestPlay'); 4242``` 4243 4244### on('endOfStream')<sup>11+</sup> 4245 4246on(type: 'endOfStream', callback: Callback\<void>): void 4247 4248设置播放结束的监听事件。 4249 4250**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4251 4252**参数:** 4253 4254| 参数名 | 类型 | 必填 | 说明 | 4255| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ | 4256| type | string | 是 | 事件回调类型,支持事件`'endOfStream'`:当资源播放结束时,触发该事件。 | 4257| callback | Callback\<void\> | 是 | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。 | 4258 4259**错误码:** 4260 4261以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4262 4263| 错误码ID | 错误信息 | 4264| -------- | ------------------------------ | 4265| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4266| 6600101 | Session service exception. | 4267 4268**示例:** 4269 4270```ts 4271aVCastController.on('endOfStream', () => { 4272 console.info('on endOfStream'); 4273}); 4274``` 4275 4276### off('endOfStream')<sup>11+</sup> 4277 4278off(type: 'endOfStream', callback?: Callback\<void>): void 4279 4280取消设置播放结束的监听事件。 4281 4282**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4283 4284**参数:** 4285 4286| 参数名 | 类型 | 必填 | 说明 | 4287| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4288| type | string | 是 | 取消对应的监听事件,支持事件`'endOfStream'`。 | 4289| callback | Callback\<void\> | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4290 4291**错误码:** 4292 4293以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4294 4295| 错误码ID | 错误信息 | 4296| -------- | ---------------- | 4297| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4298| 6600101 | Session service exception. | 4299 4300**示例:** 4301 4302```ts 4303aVCastController.off('endOfStream'); 4304``` 4305 4306### on('seekDone')<sup>10+</sup> 4307 4308on(type: 'seekDone', callback: Callback\<number>): void 4309 4310设置seek结束的监听事件。 4311 4312**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4313 4314**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4315 4316**参数:** 4317 4318| 参数名 | 类型 | 必填 | 说明 | 4319| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4320| type | string | 是 | 事件回调类型,支持事件`'seekDone'`:当seek结束时,触发该事件。 | 4321| callback | Callback\<number\> | 是 | 回调函数,返回seek后播放的位置 | 4322 4323**错误码:** 4324 4325以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4326 4327| 错误码ID | 错误信息 | 4328| -------- | ------------------------------ | 4329| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4330| 6600101 | Session service exception. | 4331 4332**示例:** 4333 4334```ts 4335aVCastController.on('seekDone', (pos: number) => { 4336 console.info(`on seekDone pos:${pos} `); 4337}); 4338``` 4339 4340### off('seekDone')<sup>10+</sup> 4341 4342off(type: 'seekDone'): void 4343 4344取消设置seek结束的监听事件。 4345 4346**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4347 4348**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4349 4350**参数:** 4351 4352| 参数名 | 类型 | 必填 | 说明 | 4353| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4354| type | string | 是 | 取消对应的监听事件,支持事件`'seekDone'`。 | 4355 4356**错误码:** 4357 4358以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4359 4360| 错误码ID | 错误信息 | 4361| -------- | ---------------- | 4362| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4363| 6600101 | Session service exception. | 4364 4365**示例:** 4366 4367```ts 4368aVCastController.off('seekDone'); 4369``` 4370 4371### on('validCommandChange')<sup>11+</sup> 4372 4373on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>) 4374 4375会话支持的有效命令变化监听事件。 4376 4377**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4378 4379**参数:** 4380 4381| 参数名 | 类型 | 必填 | 说明 | 4382| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4383| type | string | 是 | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 | 4384| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | 是 | 回调函数。参数commands是有效命令的集合。 | 4385 4386**错误码:** 4387 4388以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4389 4390| 错误码ID | 错误信息 | 4391| -------- | ------------------------------ | 4392| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4393| 6600101 | Session service exception. | 4394| 6600103 | The session controller does not exist. | 4395 4396**示例:** 4397 4398```ts 4399aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => { 4400 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 4401 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 4402}); 4403``` 4404 4405### off('validCommandChange')<sup>11+</sup> 4406 4407off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>) 4408 4409媒体控制器取消监听会话有效命令变化的事件。 4410 4411**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4412 4413**参数:** 4414 4415| 参数名 | 类型 | 必填 | 说明 | 4416| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 4417| type | string | 是 | 取消对应的监听事件,支持事件`'validCommandChange'`。 | 4418| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | 否 | 回调函数。参数commands是有效命令的集合。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4419 4420**错误码:** 4421 4422以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4423 4424| 错误码ID | 错误信息 | 4425| -------- | ---------------- | 4426| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4427| 6600101 | Session service exception. | 4428| 6600103 | The session controller does not exist. | 4429 4430**示例:** 4431 4432```ts 4433aVCastController.off('validCommandChange'); 4434``` 4435 4436### on('error')<sup>10+</sup> 4437 4438on(type: 'error', callback: ErrorCallback): void 4439 4440监听远端播放器的错误事件,该事件仅用于错误提示,不需要用户停止播控动作。 4441 4442**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4443 4444**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4445 4446**参数:** 4447 4448| 参数名 | 类型 | 必填 | 说明 | 4449| -------- | -------- | ---- | ------------------------------------------------------------ | 4450| type | string | 是 | 错误事件回调类型,支持的事件:'error',用户操作和系统都会触发此事件。 | 4451| callback | ErrorCallback | 是 | 错误事件回调方法:远端播放过程中发生的错误,会提供错误码ID和错误信息。 | 4452 4453**错误码:** 4454 4455以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。 4456 4457| 错误码ID | 错误信息 | 4458| -------- | --------------------- | 4459| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4460| 5400101 | No memory. | 4461| 5400102 | Operation not allowed. | 4462| 5400103 | I/O error. | 4463| 5400104 | Time out. | 4464| 5400105 | Service died. | 4465| 5400106 | Unsupport format. | 4466| 6600101 | Session service exception. | 4467 4468**示例:** 4469 4470```ts 4471import { BusinessError } from '@kit.BasicServicesKit'; 4472 4473aVCastController.on('error', (error: BusinessError) => { 4474 console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`) 4475}) 4476``` 4477 4478### off('error')<sup>10+</sup> 4479 4480off(type: 'error'): void 4481 4482取消监听播放的错误事件。 4483 4484**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4485 4486**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4487 4488**参数:** 4489 4490| 参数名 | 类型 | 必填 | 说明 | 4491| ------ | ------ | ---- | ----------------------------------------- | 4492| type | string | 是 | 错误事件回调类型,取消注册的事件:'error' | 4493 4494**错误码:** 4495 4496以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。 4497 4498| 错误码ID | 错误信息 | 4499| -------- | --------------------- | 4500| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4501| 5400101 | No memory. | 4502| 5400102 | Operation not allowed. | 4503| 5400103 | I/O error. | 4504| 5400104 | Time out. | 4505| 5400105 | Service died. | 4506| 5400106 | Unsupport format. | 4507| 6600101 | Session service exception. | 4508 4509**示例:** 4510 4511```ts 4512aVCastController.off('error') 4513``` 4514 4515### on('keyRequest')<sup>12+</sup> 4516 4517on(type: 'keyRequest', callback: KeyRequestCallback): void 4518 4519在线DRM资源投播时,设置许可证请求的事件监听。 4520 4521**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4522 4523**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4524 4525**参数:** 4526 4527| 参数名 | 类型 | 必填 | 说明 | 4528| ------ | ------ | ---- | ----------------------------------------- | 4529| type | string | 是 | 事件回调类型,支持事件`'keyRequest'`:当DRM资源播放需要许可证时,触发该事件。 | 4530| callback | [KeyRequestCallback](#keyrequestcallback12) | 是 | 回调函数,媒体资源及许可证请求数据。| 4531 4532 4533**错误码:** 4534 4535以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4536 4537| 错误码ID | 错误信息 | 4538| -------- | ---------------- | 4539| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4540| 6600101 | Session service exception. | 4541 4542**示例:** 4543 4544```ts 4545let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 4546 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 4547} 4548aVCastController.on('keyRequest', keyRequestCallback); 4549``` 4550### off('keyRequest')<sup>12+</sup> 4551 4552off(type: 'keyRequest', callback?: KeyRequestCallback): void 4553 4554取消监听许可证请求的事件。 4555 4556**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4557 4558**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4559 4560**参数:** 4561 4562| 参数名 | 类型 | 必填 | 说明 | 4563| ------ | ------ | ---- | ----------------------------------------- | 4564| type | string | 是 | 取消对应的监听事件,支持的事件是`'keyRequest'`。 | 4565| callback | [KeyRequestCallback](#keyrequestcallback12) | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4566 4567**错误码:** 4568 4569以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 4570 4571| 错误码ID | 错误信息 | 4572| -------- | ---------------- | 4573| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4574| 6600101 | Session service exception. | 4575 4576**示例:** 4577 4578```ts 4579aVCastController.off('keyRequest'); 4580``` 4581## KeyRequestCallback<sup>12+</sup> 4582type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void 4583 4584许可证请求事件的回调函数。 4585 4586**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 4587 4588**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4589 4590**参数:** 4591 4592| 参数名 | 类型 | 必填 | 说明 | 4593| ------ | ------ | ---- | ----------------------------------------- | 4594| assetId | string | 是 | 媒体ID。 | 4595| requestData | Uint8Array | 是 | 媒体许可证请求数据。 | 4596 4597**示例:** 4598<!--code_no_check--> 4599```ts 4600let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 4601 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 4602} 4603``` 4604 4605### on('castControlGenericError')<sup>13+</sup> 4606 4607on(type: 'castControlGenericError', callback: ErrorCallback): void 4608 4609监听投播通用错误事件。 4610 4611**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4612 4613**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4614 4615**参数:** 4616 4617| 参数名 | 类型 | 必填 | 说明 | 4618| -------- | -------- | ---- | ------------------------------------------------------------ | 4619| type | string | 是 | 错误事件回调类型,支持的事件:'castControlGenericError'。 | 4620| callback | ErrorCallback | 是 | 投播通用错误事件回调方法。 | 4621 4622**错误码:** 4623 4624| 错误码ID | 错误信息 | 4625| -------- | --------------------- | 4626| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4627| 6611000 | The error code for cast control is unspecified. | 4628| 6611001 | An unspecified error occurs in the remote player. | 4629| 6611002 | The playback position falls behind the live window. | 4630| 6611003 | The process of cast control times out. | 4631| 6611004 | The runtime check failed. | 4632| 6611100 | Cross-device data transmission is locked. | 4633| 6611101 | The specified seek mode is not supported. | 4634| 6611102 | The position to seek to is out of the range of the media asset or the specified seek mode is not supported. | 4635| 6611103 | The specified playback mode is not supported. | 4636| 6611104 | The specified playback speed is not supported. | 4637| 6611105 | The action failed because either the media source device or the media sink device has been revoked. | 4638| 6611106 | The parameter is invalid, for example, the url is illegal to play. | 4639| 6611107 | Allocation of memory failed. | 4640| 6611108 | Operation is not allowed. | 4641 4642**示例:** 4643 4644```ts 4645aVCastController.on('castControlGenericError', (error: BusinessError) => { 4646 console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`) 4647}) 4648``` 4649 4650### off('castControlGenericError')<sup>13+</sup> 4651 4652off(type: 'castControlGenericError', callback?: ErrorCallback): void 4653 4654取消监听投播通用的错误事件。 4655 4656**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4657 4658**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4659 4660**参数:** 4661 4662| 参数名 | 类型 | 必填 | 说明 | 4663| -------- | -------- | ---- | ------------------------------------------------------------ | 4664| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlGenericError'。 | 4665| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4666 4667**错误码:** 4668 4669| 错误码ID | 错误信息 | 4670| -------- | --------------------- | 4671| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4672 4673**示例:** 4674 4675```ts 4676aVCastController.off('castControlGenericError'); 4677``` 4678 4679### on('castControlIoError')<sup>13+</sup> 4680 4681on(type: 'castControlIoError', callback: ErrorCallback): void 4682 4683监听投播输入/输出的错误事件。 4684 4685**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4686 4687**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4688 4689**参数:** 4690 4691| 参数名 | 类型 | 必填 | 说明 | 4692| -------- | -------- | ---- | ------------------------------------------------------------ | 4693| type | string | 是 | 错误事件回调类型,支持的事件:'castControlIoError'。 | 4694| callback | ErrorCallback | 是 | 投播输入/输出的错误事件回调方法。 | 4695 4696**错误码:** 4697 4698| 错误码ID | 错误信息 | 4699| -------- | --------------------- | 4700| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4701| 6612000 | An unspecified input/output error occurs. | 4702| 6612001 | Network connection failure. | 4703| 6612002 | Network timeout. | 4704| 6612003 | Invalid "Content-Type" HTTP header. | 4705| 6612004 | The HTTP server returns an unexpected HTTP response status code. | 4706| 6612005 | The file does not exist. | 4707| 6612006 | No permission is granted to perform the IO operation. | 4708| 6612007 | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. | 4709| 6612008 | Reading data out of the data bound. | 4710| 6612100 | The media does not contain any contents that can be played. | 4711| 6612101 | The media cannot be read, for example, because of dust or scratches. | 4712| 6612102 | This resource is already in use. | 4713| 6612103 | The content using the validity interval has expired. | 4714| 6612104 | Using the requested content to play is not allowed. | 4715| 6612105 | The use of the allowed content cannot be verified. | 4716| 6612106 | The number of times this content has been used as requested has reached the maximum allowed number of uses. | 4717| 6612107 | An error occurs when sending packet from source device to sink device. | 4718 4719**示例:** 4720 4721```ts 4722aVCastController.on('castControlIoError', (error: BusinessError) => { 4723 console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`) 4724}) 4725``` 4726 4727### off('castControlIoError')<sup>13+</sup> 4728 4729off(type: 'castControlIoError', callback?: ErrorCallback): void 4730 4731取消监听投播输入/输出的错误事件。 4732 4733**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4734 4735**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4736 4737**参数:** 4738 4739| 参数名 | 类型 | 必填 | 说明 | 4740| -------- | -------- | ---- | ------------------------------------------------------------ | 4741| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlIoError'。 | 4742| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4743 4744**错误码:** 4745 4746| 错误码ID | 错误信息 | 4747| -------- | --------------------- | 4748| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4749 4750**示例:** 4751 4752```ts 4753aVCastController.off('castControlIoError'); 4754``` 4755 4756### on('castControlParsingError')<sup>13+</sup> 4757 4758on(type: 'castControlParsingError', callback: ErrorCallback): void 4759 4760监听投播解析的错误事件。 4761 4762**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4763 4764**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4765 4766**参数:** 4767 4768| 参数名 | 类型 | 必填 | 说明 | 4769| -------- | -------- | ---- | ------------------------------------------------------------ | 4770| type | string | 是 | 错误事件回调类型,支持的事件:'castControlParsingError'。 | 4771| callback | ErrorCallback | 是 | 投播解析的错误事件回调方法。 | 4772 4773**错误码:** 4774 4775| 错误码ID | 错误信息 | 4776| -------- | --------------------- | 4777| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4778| 6613000 | Unspecified error related to content parsing. | 4779| 6613001 | Parsing error associated with media container format bit streams. | 4780| 6613002 | Parsing error associated with the media manifest. | 4781| 6613003 | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature. | 4782| 6613004 | Unsupported feature in the media manifest. | 4783 4784**示例:** 4785 4786```ts 4787aVCastController.on('castControlParsingError', (error: BusinessError) => { 4788 console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`) 4789}) 4790``` 4791 4792### off('castControlParsingError')<sup>13+</sup> 4793 4794off(type: 'castControlParsingError', callback?: ErrorCallback): void 4795 4796取消监听投播解析的错误事件。 4797 4798**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4799 4800**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4801 4802**参数:** 4803 4804| 参数名 | 类型 | 必填 | 说明 | 4805| -------- | -------- | ---- | ------------------------------------------------------------ | 4806| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlParsingError'。 | 4807| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4808 4809**错误码:** 4810 4811| 错误码ID | 错误信息 | 4812| -------- | --------------------- | 4813| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4814 4815**示例:** 4816 4817```ts 4818aVCastController.off('castControlParsingError'); 4819``` 4820 4821### on('castControlDecodingError')<sup>13+</sup> 4822 4823on(type: 'castControlDecodingError', callback: ErrorCallback): void 4824 4825监听投播解码的错误事件。 4826 4827**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4828 4829**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4830 4831**参数:** 4832 4833| 参数名 | 类型 | 必填 | 说明 | 4834| -------- | -------- | ---- | ------------------------------------------------------------ | 4835| type | string | 是 | 错误事件回调类型,支持的事件:'castControlDecodingError'。 | 4836| callback | ErrorCallback | 是 | 投播解码的错误事件回调方法。 | 4837 4838**错误码:** 4839 4840| 错误码ID | 错误信息 | 4841| -------- | --------------------- | 4842| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4843| 6614000 | Unspecified decoding error. | 4844| 6614001 | Decoder initialization failed. | 4845| 6614002 | Decoder query failed. | 4846| 6614003 | Decoding the media samples failed. | 4847| 6614004 | The format of the content to decode exceeds the capabilities of the device. | 4848| 6614005 | The format of the content to decode is not supported. | 4849 4850**示例:** 4851 4852```ts 4853aVCastController.on('castControlDecodingError', (error: BusinessError) => { 4854 console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`) 4855}) 4856``` 4857### off('castControlDecodingError')<sup>13+</sup> 4858 4859off(type: 'castControlDecodingError', callback?: ErrorCallback): void 4860 4861取消监听投播解码的错误事件。 4862 4863**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4864 4865**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4866 4867**参数:** 4868 4869| 参数名 | 类型 | 必填 | 说明 | 4870| -------- | -------- | ---- | ------------------------------------------------------------ | 4871| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlDecodingError'。 | 4872| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4873 4874**错误码:** 4875 4876| 错误码ID | 错误信息 | 4877| -------- | --------------------- | 4878| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4879 4880**示例:** 4881 4882```ts 4883aVCastController.off('castControlDecodingError'); 4884``` 4885 4886### on('castControlAudioRendererError')<sup>13+</sup> 4887 4888on(type: 'castControlAudioRendererError', callback: ErrorCallback): void 4889 4890监听投播音频渲染器的错误事件。 4891 4892**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4893 4894**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4895 4896**参数:** 4897 4898| 参数名 | 类型 | 必填 | 说明 | 4899| -------- | -------- | ---- | ------------------------------------------------------------ | 4900| type | string | 是 | 错误事件回调类型,支持的事件:'castControlAudioRendererError'。 | 4901| callback | ErrorCallback | 是 | 投播音频渲染器的错误事件回调方法。 | 4902 4903**错误码:** 4904 4905以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。 4906 4907| 错误码ID | 错误信息 | 4908| -------- | --------------------- | 4909| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4910| 6615000 | Unspecified errors related to the audio renderer. | 4911| 6615001 | Initializing the audio renderer failed. | 4912| 6615002 | The audio renderer fails to write data. | 4913 4914**示例:** 4915 4916```ts 4917aVCastController.on('castControlAudioRendererError', (error: BusinessError) => { 4918 console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`) 4919}) 4920``` 4921### off('castControlAudioRendererError')<sup>13+</sup> 4922 4923off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void 4924 4925取消监听投播音频渲染器的错误事件。 4926 4927**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4928 4929**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4930 4931**参数:** 4932 4933| 参数名 | 类型 | 必填 | 说明 | 4934| -------- | -------- | ---- | ------------------------------------------------------------ | 4935| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlAudioRendererError'。 | 4936| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 4937 4938**错误码:** 4939 4940| 错误码ID | 错误信息 | 4941| -------- | --------------------- | 4942| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4943 4944**示例:** 4945 4946```ts 4947aVCastController.off('castControlAudioRendererError'); 4948``` 4949 4950### on('castControlDrmError')<sup>13+</sup> 4951 4952on(type: 'castControlDrmError', callback: ErrorCallback): void 4953 4954监听投播drm的错误事件。 4955 4956**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4957 4958**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 4959 4960**参数:** 4961 4962| 参数名 | 类型 | 必填 | 说明 | 4963| -------- | -------- | ---- | ------------------------------------------------------------ | 4964| type | string | 是 | 错误事件回调类型,支持的事件:'castControlDrmError'。 | 4965| callback | ErrorCallback | 是 | 投播drm的错误事件回调方法。 | 4966 4967**错误码:** 4968 4969| 错误码ID | 错误信息 | 4970| -------- | --------------------- | 4971| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4972| 6616000 | Unspecified error related to DRM. | 4973| 6616001 | The chosen DRM protection scheme is not supported by the device. | 4974| 6615002 | Device provisioning failed. | 4975| 6616003 | The DRM-protected content to play is incompatible. | 4976| 6616004 | Failed to obtain a license. | 4977| 6616005 | The operation is disallowed by the license policy. | 4978| 6616006 | An error occurs in the DRM system. | 4979| 6616007 | The device has revoked DRM privileges. | 4980| 6616008 | The DRM license being loaded into the open DRM session has expired. | 4981| 6616100 | An error occurs when the DRM processes the key response. | 4982 4983**示例:** 4984 4985```ts 4986aVCastController.on('castControlDrmError', (error: BusinessError) => { 4987 console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`) 4988}) 4989``` 4990 4991### off('castControlDrmError')<sup>13+</sup> 4992 4993off(type: 'castControlDrmError', callback?: ErrorCallback): void 4994 4995取消监听投播drm的错误事件。 4996 4997**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。 4998 4999**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5000 5001**参数:** 5002 5003| 参数名 | 类型 | 必填 | 说明 | 5004| -------- | -------- | ---- | ------------------------------------------------------------ | 5005| type | string | 是 | 取消对应的监听事件,支持的事件是'castControlDrmError'。 | 5006| callback | ErrorCallback | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 5007 5008**错误码:** 5009 5010| 错误码ID | 错误信息 | 5011| -------- | --------------------- | 5012| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 5013 5014**示例:** 5015 5016```ts 5017aVCastController.off('castControlDrmError'); 5018``` 5019 5020## CastDisplayState<sup>12+</sup> 5021 5022投播显示设备状态的枚举。 5023 5024**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5025 5026**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5027 5028| 名称 | 值 | 说明 | 5029| --------------------------- | ---- | ----------- | 5030| STATE_OFF | 1 | 设备断开,扩展屏不再显示内容。 | 5031| STATE_ON | 2 | 设备连接成功,扩展屏可用。 | 5032 5033 5034## CastDisplayInfo<sup>12+</sup> 5035 5036扩展屏投播显示设备相关属性。 5037 5038**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5039 5040**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5041 5042| 名称 | 类型 | 只读 | 可选 | 说明 | 5043| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 5044| id | number | 否 | 否 | 投播显示设备的ID,该参数应为整数。 | 5045| name | string | 否 | 否 | 投播显示设备的名称。 | 5046| state | [CastDisplayState](#castdisplaystate12) | 否 | 否 |投播显示设备状态。 | 5047| width | number | 否 | 否 | 投播显示设备的屏幕宽度,单位为px,该参数应为整数。 | 5048| height | number | 否 | 否 | 投播显示设备的屏幕高度,单位为px,该参数应为整数。 | 5049 5050## ConnectionState<sup>10+</sup> 5051 5052连接状态枚举。 5053 5054**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5055 5056**系统能力:** SystemCapability.Multimedia.AVSession.Core 5057 5058| 名称 | 值 | 说明 | 5059| --------------------------- | ---- | ----------- | 5060| STATE_CONNECTING | 0 | 设备连接中 | 5061| STATE_CONNECTED | 1 | 设备连接成功 | 5062| STATE_DISCONNECTED | 6 | 设备断开连接 | 5063 5064## AVMetadata<sup>10+</sup> 5065 5066媒体元数据的相关属性。 5067 5068**系统能力:** SystemCapability.Multimedia.AVSession.Core 5069 5070| 名称 | 类型 | 必填 | 说明 | 5071| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 5072| assetId | string | 是 | 媒体ID。歌曲的唯一标识,由应用自定义。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5073| title | string | 否 | 标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5074| artist | string | 否 | 艺术家。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5075| author | string | 否 | 专辑作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5076| avQueueName<sup>12+</sup> | string | 否 | 歌单(歌曲列表)名称。 | 5077| avQueueId<sup>11+</sup> | string | 否 | 歌单(歌曲列表)唯一标识Id。 | 5078| avQueueImage<sup>11+</sup> | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | string | 否 | 歌单(歌曲列表)封面图,图片的像素数据或者图片路径地址(本地路径或网络路径)。<br>应用通过setAVMetadata设置图片数据,当设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。设置为url图片路径,获取的亦为url图片路径 | 5079| album | string | 否 | 专辑名称。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5080| writer | string | 否 | 词作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5081| composer | string | 否 | 作曲者。 | 5082| duration | number | 否 | 媒体时长,单位毫秒(ms)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5083| mediaImage | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | string | 否 | 图片的像素数据或者图片路径地址(本地路径或网络路径)。<br>应用通过setAVMetadata设置图片数据,当设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。设置为url图片路径,获取的亦为url图片路径 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5084| publishDate | Date | 否 | 发行日期。 | 5085| subtitle | string | 否 | 子标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5086| description | string | 否 | 媒体描述。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5087| lyric | string | 否 | 媒体歌词内容。应用需将歌词内容拼接为一个字符串传入。<br>字符串长度需小于等于40960字节。<br>**说明:** 系统支持简单版的LRC格式(Simple LRC format)的歌词文本内容。当传入的歌词内容不规范(如出现重复的时间戳等),将导致解析失败以及在系统中显示异常。 | 5088| previousAssetId | string | 否 | 上一首媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5089| nextAssetId | string | 否 | 下一首媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5090| filter<sup>11+</sup> | number | 否 | 当前session支持的协议,默认为TYPE_CAST_PLUS_STREAM。具体取值参考[ProtocolType](#protocoltype11)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5091| drmSchemes<sup>12+</sup> | Array\<string> | 否 | 当前session支持的DRM方案,取值为DRM方案uuid。| 5092| skipIntervals<sup>11+</sup> | [SkipIntervals](#skipintervals11) | 否 | 快进快退支持的时间间隔,默认为SECONDS_15,即15秒。 | 5093|displayTags<sup>11+</sup> | number | 否 | 媒体资源的金标类型,取值参考[DisplayTag](#displaytag11)。 | 5094 5095## AVMediaDescription<sup>10+</sup> 5096 5097播放列表媒体元数据的相关属性。 5098 5099**系统能力:** SystemCapability.Multimedia.AVSession.Core 5100 5101| 名称 | 类型 | 必填 | 说明 | 5102| ------------ | ----------------------- | ---- | ----------------------- | 5103| assetId | string | 是 | 播放列表媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5104| title | string | 否 | 播放列表媒体标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5105| subtitle | string | 否 | 播放列表媒体子标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5106| description | string | 否 | 播放列表媒体描述的文本。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5107| mediaImage | image.PixelMap \| string | 否 | 播放列表媒体图片像素数据。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5108| extras | {[key: string]: Object} | 否 | 播放列表媒体额外字段。 | 5109| mediaUri | string | 否 | 播放列表媒体URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5110| mediaType | string | 否 | 播放列表媒体类型。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5111| mediaSize | number | 否 | 播放列表媒体的大小。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5112| albumTitle | string | 否 | 播放列表媒体专辑标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5113| albumCoverUri | string | 否 | 播放列表媒体专辑标题URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5114| lyricContent | string | 否 | 播放列表媒体歌词内容。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5115| lyricUri | string | 否 | 播放列表媒体歌词URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5116| artist | string | 否 | 播放列表媒体专辑作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5117| fdSrc | media.AVFileDescriptor | 否 | 播放列表媒体本地文件的句柄。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5118| dataSrc<sup>12+</sup> | media.AVDataSrcDescriptor | 否 | 播放列表数据源描述。 | 5119| drmScheme<sup>12+</sup> | string | 否 | 播放列表媒体支持的DRM方案,由uuid表示。 | 5120| duration | number | 否 | 播放列表媒体播放时长。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5121| startPosition | number | 否 | 播放列表媒体起始播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5122| creditsPosition | number | 否 | 播放列表媒体的片尾播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5123| appName | string | 否 | 播放列表提供的应用的名字。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5124|displayTags<sup>11+</sup> | number | 否 | 媒体资源的金标类型,取值参考[DisplayTag](#displaytag11)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5125 5126## AVQueueItem<sup>10+</sup> 5127 5128播放列表中单项的相关属性。 5129 5130**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5131 5132**系统能力:** SystemCapability.Multimedia.AVSession.Core 5133 5134| 名称 | 类型 | 必填 | 说明 | 5135| ------------ | ------------------------------------------ | ---- | --------------------------- | 5136| itemId | number | 是 | 播放列表中单项的ID。 | 5137| description | [AVMediaDescription](#avmediadescription10) | 否 | 播放列表中单项的媒体元数据。 | 5138 5139## AVPlaybackState<sup>10+</sup> 5140 5141媒体播放状态的相关属性。 5142 5143**系统能力:** SystemCapability.Multimedia.AVSession.Core 5144 5145| 名称 | 类型 | 必填 | 说明 | 5146| ------------ | ------------------------------------- | ---- | ------- | 5147| state | [PlaybackState](#playbackstate10) | 否 | 播放状态<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5148| speed | number | 否 | 播放倍速<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5149| position | [PlaybackPosition](#playbackposition10) | 否 | 播放位置<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5150| bufferedTime | number | 否 | 缓冲时间<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5151| loopMode | [LoopMode](#loopmode10) | 否 | 循环模式<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5152| isFavorite | boolean | 否 | 是否收藏<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5153| activeItemId<sup>10+</sup> | number | 否 | 正在播放的媒体Id<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5154| volume<sup>10+</sup> | number | 否 | 正在播放的媒体音量<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5155| maxVolume<sup>11+</sup> | number | 否 | 最大音量<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5156| muted<sup>11+</sup> | boolean | 否 | 当前静音状态,true表示静音<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5157| duration<sup>11+</sup> | number | 否 | 当前媒体资源的时长 | 5158| videoWidth<sup>11+</sup> | number | 否 | 媒体资源的视频宽度,单位为像素(px)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5159| videoHeight<sup>11+</sup> | number | 否 | 媒体资源的视频高度,单位为像素(px)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5160| extras<sup>10+</sup> | {[key: string]: Object} | 否 | 自定义媒体数据<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5161 5162## PlaybackPosition<sup>10+</sup> 5163 5164媒体播放位置的相关属性。 5165 5166**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5167 5168**系统能力:** SystemCapability.Multimedia.AVSession.Core 5169 5170| 名称 | 类型 | 必填 | 说明 | 5171| ----------- | ------ | ---- | ------------------ | 5172| elapsedTime | number | 是 | 已用时间,单位毫秒(ms)。 | 5173| updateTime | number | 是 | 更新时间,单位毫秒(ms)。 | 5174 5175## CallMetadata<sup>11+</sup> 5176 5177通话会话元数据相关属性。 5178 5179**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5180 5181**系统能力:** SystemCapability.Multimedia.AVSession.Core 5182 5183| 名称 | 类型 | 必填 | 说明 | 5184| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 5185| name | string | 否 | 来电人姓名(别名)。 | 5186| phoneNumber | string | 否 | 来电电话号码 | 5187| avatar | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 否 | 来电人头像。 | 5188 5189## AVCallState<sup>11+</sup> 5190 5191通话状态相关属性。 5192 5193**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5194 5195**系统能力:** SystemCapability.Multimedia.AVSession.Core 5196 5197| 名称 | 类型 | 必填 | 说明 | 5198| --------------- |------------------------- | ---- |---------------------------------------------------------------------| 5199| state | [CallState](#callstate11) | 是 | 当前通话状态。 | 5200| muted | boolean | 是 | 通话mic是否静音。 <br>true:静音。 <br>false:不是静音。| 5201 5202## CallState<sup>11+</sup> 5203 5204表示通话状态的枚举。 5205 5206**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5207 5208**系统能力:** SystemCapability.Multimedia.AVSession.Core 5209 5210| 名称 | 值 | 说明 | 5211| -------------------------- | ---- | -------- | 5212| CALL_STATE_IDLE | 0 | 空闲状态 | 5213| CALL_STATE_INCOMING | 1 | 来电 | 5214| CALL_STATE_ACTIVE | 2 | 接通 | 5215| CALL_STATE_DIALING | 3 | 响铃 | 5216| CALL_STATE_WAITING | 4 | 等待接通 | 5217| CALL_STATE_HOLDING | 5 | 保持 | 5218| CALL_STATE_DISCONNECTING | 6 | 挂断 | 5219 5220## DisplayTag<sup>11+</sup> 5221 5222枚举,表示当前媒体资源的金标,即应用媒体音源的特殊类型标识。 5223 5224**系统能力:** SystemCapability.Multimedia.AVSession.Core 5225 5226| 名称 | 值 | 说明 | 5227| -------------------------- | ---- | ------------ | 5228| TAG_AUDIO_VIVID | 1 | AUDIO VIVID | 5229 5230## AVCastCategory<sup>10+</sup> 5231 5232投播的类别枚举。 5233 5234**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5235 5236**系统能力:** SystemCapability.Multimedia.AVSession.AVCast 5237 5238| 名称 | 值 | 说明 | 5239| --------------------------- | ---- | ----------- | 5240| CATEGORY_LOCAL | 0 | 本地播放,默认播放设备,声音从本机或者连接的蓝牙耳机设备出声。 | 5241| CATEGORY_REMOTE | 1 | 远端播放,远端播放设备,声音从其他设备发出声音或者画面。 | 5242 5243## DeviceType<sup>10+</sup> 5244 5245播放设备的类型枚举。 5246 5247**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5248 5249| 名称 | 值 | 说明 | 5250| --------------------------- | ---- | ----------- | 5251| DEVICE_TYPE_LOCAL | 0 | 本地播放类型 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core| 5252| DEVICE_TYPE_BLUETOOTH | 10 | 蓝牙设备 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core | 5253| DEVICE_TYPE_TV | 2 | 电视 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast | 5254| DEVICE_TYPE_SMART_SPEAKER | 3 | 音箱设备 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast | 5255 5256## DeviceInfo<sup>10+</sup> 5257 5258播放设备的相关信息。 5259 5260| 名称 | 类型 | 必填 | 说明 | 5261| ---------- | -------------- | ---- | ---------------------- | 5262| castCategory | AVCastCategory | 是 | 投播的类别。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5263| deviceId | string | 是 | 播放设备的ID。<br> **系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5264| deviceName | string | 是 | 播放设备的名称。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5265| deviceType | DeviceType | 是 | 播放设备的类型。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。| 5266| supportedProtocols<sup>11+</sup> | number | 否 | 播放设备支持的协议。默认为TYPE_LOCAL。具体取值参考[ProtocolType](#protocoltype11)。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 5267| manufacturer<sup>13+</sup> | string | 否 | 播放设备生产厂家。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。| 5268| modelName<sup>13+</sup> | string | 否 | 播放设备型号名称。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。| 5269 5270## OutputDeviceInfo<sup>10+</sup> 5271 5272播放设备的相关信息。 5273 5274**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5275 5276**系统能力:** SystemCapability.Multimedia.AVSession.Core 5277 5278| 名称 | 类型 | 必填 | 说明 | 5279| ---------- | -------------- | ---- | ---------------------- | 5280| devices | Array\<DeviceInfo\> | 是 | 播放设备的集合。 | 5281 5282## LoopMode<sup>10+</sup> 5283 5284表示媒体播放循环模式的枚举。 5285 5286**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5287 5288**系统能力:** SystemCapability.Multimedia.AVSession.Core 5289 5290| 名称 | 值 | 说明 | 5291| ------------------ | ---- | -------- | 5292| LOOP_MODE_SEQUENCE | 0 | 顺序播放 | 5293| LOOP_MODE_SINGLE | 1 | 单曲循环 | 5294| LOOP_MODE_LIST | 2 | 表单循环 | 5295| LOOP_MODE_SHUFFLE | 3 | 随机播放 | 5296| LOOP_MODE_CUSTOM<sup>11+</sup> | 4 | 自定义播放 | 5297 5298## PlaybackState<sup>10+</sup> 5299 5300表示媒体播放状态的枚举。 5301 5302**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5303 5304**系统能力:** SystemCapability.Multimedia.AVSession.Core 5305 5306| 名称 | 值 | 说明 | 5307| --------------------------- | ---- | ----------- | 5308| PLAYBACK_STATE_INITIAL | 0 | 初始状态 | 5309| PLAYBACK_STATE_PREPARE | 1 | 播放准备状态 | 5310| PLAYBACK_STATE_PLAY | 2 | 正在播放 | 5311| PLAYBACK_STATE_PAUSE | 3 | 暂停 | 5312| PLAYBACK_STATE_FAST_FORWARD | 4 | 快进 | 5313| PLAYBACK_STATE_REWIND | 5 | 快退 | 5314| PLAYBACK_STATE_STOP | 6 | 停止 | 5315| PLAYBACK_STATE_COMPLETED | 7 | 播放完成 | 5316| PLAYBACK_STATE_RELEASED | 8 | 释放 | 5317| PLAYBACK_STATE_ERROR | 9 | 错误 | 5318| PLAYBACK_STATE_IDLE<sup>11+</sup> | 10 | 空闲 | 5319| PLAYBACK_STATE_BUFFERING<sup>11+</sup> | 11 | 缓冲 | 5320 5321## AVSessionController<sup>10+</sup> 5322 5323AVSessionController控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 5324 5325### 属性 5326 5327**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5328 5329**系统能力:** SystemCapability.Multimedia.AVSession.Core 5330 5331| 名称 | 类型 | 可读 | 可写 | 说明 | 5332| :-------- | :----- | :--- | :--- | :-------------------------------------- | 5333| sessionId | string | 是 | 否 | AVSessionController对象唯一的会话标识。 | 5334 5335 5336**示例:** 5337 5338```ts 5339import { BusinessError } from '@kit.BasicServicesKit'; 5340 5341let AVSessionController: avSession.AVSessionController; 5342avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => { 5343 AVSessionController = controller; 5344}).catch((err: BusinessError) => { 5345 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 5346}); 5347``` 5348 5349### getAVPlaybackState<sup>10+</sup> 5350 5351getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 5352 5353获取当前的远端播放状态。结果通过callback异步回调方式返回。 5354 5355**系统能力:** SystemCapability.Multimedia.AVSession.Core 5356 5357**参数:** 5358 5359| 参数名 | 类型 | 必填 | 说明 | 5360| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 5361| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | 是 | 回调函数,返回远端播放状态。 | 5362 5363**错误码:** 5364 5365以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5366 5367| 错误码ID | 错误信息 | 5368| -------- | ---------------------------------------- | 5369| 6600101 | Session service exception. | 5370| 6600102 | The session does not exist. | 5371| 6600103 | The session controller does not exist. | 5372 5373**示例:** 5374 5375```ts 5376import { BusinessError } from '@kit.BasicServicesKit'; 5377 5378avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 5379 if (err) { 5380 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5381 } else { 5382 console.info('getAVPlaybackState : SUCCESS'); 5383 } 5384}); 5385``` 5386 5387### getAVPlaybackState<sup>10+</sup> 5388 5389getAVPlaybackState(): Promise\<AVPlaybackState> 5390 5391获取当前的远端播放状态。结果通过Promise异步回调方式返回。 5392 5393**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5394 5395**系统能力:** SystemCapability.Multimedia.AVSession.Core 5396 5397**返回值:** 5398 5399| 类型 | 说明 | 5400| --------- | ------------------------------------------------------------ | 5401| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise对象。返回远端播放状态。 | 5402 5403**错误码:** 5404 5405以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5406 5407| 错误码ID | 错误信息 | 5408| -------- | ---------------------------------------- | 5409| 6600101 | Session service exception. | 5410| 6600102 | The session does not exist. | 5411| 6600103 | The session controller does not exist. | 5412 5413**示例:** 5414 5415```ts 5416import { BusinessError } from '@kit.BasicServicesKit'; 5417 5418avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 5419 console.info('getAVPlaybackState : SUCCESS'); 5420}).catch((err: BusinessError) => { 5421 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5422}); 5423``` 5424 5425### getAVMetadata<sup>10+</sup> 5426 5427getAVMetadata(): Promise\<AVMetadata> 5428 5429获取会话元数据。结果通过Promise异步回调方式返回。 5430 5431**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5432 5433**系统能力:** SystemCapability.Multimedia.AVSession.Core 5434 5435**返回值:** 5436 5437| 类型 | 说明 | 5438| ----------------------------------- | ----------------------------- | 5439| Promise<[AVMetadata](#avmetadata10)\> | Promise对象,返回会话元数据。 | 5440 5441**错误码:** 5442 5443以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5444 5445| 错误码ID | 错误信息 | 5446| -------- | ---------------------------------------- | 5447| 6600101 | Session service exception. | 5448| 6600102 | The session does not exist. | 5449| 6600103 | The session controller does not exist. | 5450 5451**示例:** 5452 5453```ts 5454import { BusinessError } from '@kit.BasicServicesKit'; 5455 5456avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => { 5457 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5458}).catch((err: BusinessError) => { 5459 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5460}); 5461``` 5462 5463### getAVMetadata<sup>10+</sup> 5464 5465getAVMetadata(callback: AsyncCallback\<AVMetadata>): void 5466 5467获取会话元数据。结果通过callback异步回调方式返回。 5468 5469**系统能力:** SystemCapability.Multimedia.AVSession.Core 5470 5471**参数:** 5472 5473| 参数名 | 类型 | 必填 | 说明 | 5474| -------- | ----------------------------------------- | ---- | -------------------------- | 5475| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | 是 | 回调函数,返回会话元数据。 | 5476 5477**错误码:** 5478 5479以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5480 5481| 错误码ID | 错误信息 | 5482| -------- | ---------------------------------------- | 5483| 6600101 | Session service exception. | 5484| 6600102 | The session does not exist. | 5485| 6600103 | The session controller does not exist. | 5486 5487**示例:** 5488 5489```ts 5490import { BusinessError } from '@kit.BasicServicesKit'; 5491 5492avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => { 5493 if (err) { 5494 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5495 } else { 5496 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5497 } 5498}); 5499``` 5500 5501### getAVQueueTitle<sup>10+</sup> 5502 5503getAVQueueTitle(): Promise\<string> 5504 5505获取当前会话播放列表的名称。结果通过Promise异步回调方式返回。 5506 5507**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5508 5509**系统能力:** SystemCapability.Multimedia.AVSession.Core 5510 5511**返回值:** 5512 5513| 类型 | 说明 | 5514| ---------------- | ----------------------------- | 5515| Promise<string\> | Promise对象。返回播放列表名称。 | 5516 5517**错误码:** 5518 5519以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5520 5521| 错误码ID | 错误信息 | 5522| -------- | ---------------------------------------- | 5523| 6600101 | Session service exception. | 5524| 6600102 | The session does not exist. | 5525| 6600103 | The session controller does not exist. | 5526 5527**示例:** 5528 5529```ts 5530import { BusinessError } from '@kit.BasicServicesKit'; 5531 5532avsessionController.getAVQueueTitle().then((title: string) => { 5533 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 5534}).catch((err: BusinessError) => { 5535 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 5536}); 5537``` 5538 5539### getAVQueueTitle<sup>10+</sup> 5540 5541getAVQueueTitle(callback: AsyncCallback\<string>): void 5542 5543获取当前播放列表的名称。结果通过callback异步回调方式返回。 5544 5545**系统能力:** SystemCapability.Multimedia.AVSession.Core 5546 5547**参数:** 5548 5549| 参数名 | 类型 | 必填 | 说明 | 5550| -------- | ---------------------- | ---- | ------------------------- | 5551| callback | AsyncCallback<string\> | 是 | 回调函数,返回播放列表名称。 | 5552 5553**错误码:** 5554 5555以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5556 5557| 错误码ID | 错误信息 | 5558| -------- | ---------------------------------------- | 5559| 6600101 | Session service exception. | 5560| 6600102 | The session does not exist. | 5561| 6600103 | The session controller does not exist. | 5562 5563**示例:** 5564 5565```ts 5566import { BusinessError } from '@kit.BasicServicesKit'; 5567 5568avsessionController.getAVQueueTitle((err: BusinessError, title: string) => { 5569 if (err) { 5570 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 5571 } else { 5572 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 5573 } 5574}); 5575``` 5576 5577### getAVQueueItems<sup>10+</sup> 5578 5579getAVQueueItems(): Promise\<Array\<AVQueueItem>> 5580 5581获取当前会话播放列表相关信息。结果通过Promise异步回调方式返回。 5582 5583**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5584 5585**系统能力:** SystemCapability.Multimedia.AVSession.Core 5586 5587**返回值:** 5588 5589| 类型 | 说明 | 5590| --------------------------------------------- | ----------------------------- | 5591| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise对象。返回播放列表队列。 | 5592 5593**错误码:** 5594 5595以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5596 5597| 错误码ID | 错误信息 | 5598| -------- | ---------------------------------------- | 5599| 6600101 | Session service exception. | 5600| 6600102 | The session does not exist. | 5601| 6600103 | The session controller does not exist. | 5602 5603**示例:** 5604 5605```ts 5606import { BusinessError } from '@kit.BasicServicesKit'; 5607 5608avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => { 5609 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 5610}).catch((err: BusinessError) => { 5611 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 5612}); 5613``` 5614 5615### getAVQueueItems<sup>10+</sup> 5616 5617getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void 5618 5619获取当前播放列表相关信息。结果通过callback异步回调方式返回。 5620 5621**系统能力:** SystemCapability.Multimedia.AVSession.Core 5622 5623**参数:** 5624 5625| 参数名 | 类型 | 必填 | 说明 | 5626| -------- | --------------------------------------------------- | ---- | ------------------------- | 5627| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | 是 | 回调函数,返回播放列表队列。 | 5628 5629**错误码:** 5630 5631以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5632 5633| 错误码ID | 错误信息 | 5634| -------- | ---------------------------------------- | 5635| 6600101 | Session service exception. | 5636| 6600102 | The session does not exist. | 5637| 6600103 | The session controller does not exist. | 5638 5639**示例:** 5640 5641```ts 5642import { BusinessError } from '@kit.BasicServicesKit'; 5643 5644avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => { 5645 if (err) { 5646 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 5647 } else { 5648 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 5649 } 5650}); 5651``` 5652 5653### skipToQueueItem<sup>10+</sup> 5654 5655skipToQueueItem(itemId: number): Promise\<void> 5656 5657设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过Promise异步回调方式返回。 5658 5659**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5660 5661**系统能力:** SystemCapability.Multimedia.AVSession.Core 5662 5663**参数:** 5664 5665| 参数名 | 类型 | 必填 | 说明 | 5666| ------ | ------- | ---- | ------------------------------------------- | 5667| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | 5668 5669**返回值:** 5670 5671| 类型 | 说明 | 5672| -------------- | --------------------------------------------------------------- | 5673| Promise\<void> | Promise对象。当播放列表单项ID设置成功,无返回结果,否则返回错误对象。 | 5674 5675**错误码:** 5676 5677以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5678 5679| 错误码ID | 错误信息 | 5680| -------- | ---------------------------------------- | 5681| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5682| 6600101 | Session service exception. | 5683| 6600102 | The session does not exist. | 5684| 6600103 | The session controller does not exist. | 5685 5686**示例:** 5687 5688```ts 5689import { BusinessError } from '@kit.BasicServicesKit'; 5690 5691let queueItemId = 0; 5692avsessionController.skipToQueueItem(queueItemId).then(() => { 5693 console.info('SkipToQueueItem successfully'); 5694}).catch((err: BusinessError) => { 5695 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 5696}); 5697``` 5698 5699### skipToQueueItem<sup>10+</sup> 5700 5701skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void 5702 5703设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过callback异步回调方式返回。 5704 5705**系统能力:** SystemCapability.Multimedia.AVSession.Core 5706 5707**参数:** 5708 5709| 参数名 | 类型 | 必填 | 说明 | 5710| -------- | --------------------- | ---- | ----------------------------------------------------------- | 5711| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | 5712| callback | AsyncCallback\<void> | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | 5713 5714**错误码:** 5715 5716以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5717 5718| 错误码ID | 错误信息 | 5719| -------- | ---------------------------------------- | 5720| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5721| 6600101 | Session service exception. | 5722| 6600102 | The session does not exist. | 5723| 6600103 | The session controller does not exist. | 5724 5725**示例:** 5726 5727```ts 5728import { BusinessError } from '@kit.BasicServicesKit'; 5729 5730let queueItemId = 0; 5731avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => { 5732 if (err) { 5733 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 5734 } else { 5735 console.info('SkipToQueueItem successfully'); 5736 } 5737}); 5738``` 5739 5740### getOutputDevice<sup>10+</sup> 5741 5742getOutputDevice(): Promise\<OutputDeviceInfo> 5743 5744获取播放设备信息。结果通过Promise异步回调方式返回。 5745 5746**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5747 5748**系统能力:** SystemCapability.Multimedia.AVSession.Core 5749 5750**返回值:** 5751 5752| 类型 | 说明 | 5753| ----------------------------------------------- | --------------------------------- | 5754| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise对象,返回播放设备信息。 | 5755 5756**错误码:** 5757 5758以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5759 5760| 错误码ID | 错误信息 | 5761| -------- | ---------------------------------------- | 5762| 600101 | Session service exception. | 5763| 600103 | The session controller does not exist. | 5764 5765**示例:** 5766 5767```ts 5768import { BusinessError } from '@kit.BasicServicesKit'; 5769 5770avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => { 5771 console.info('GetOutputDevice : SUCCESS'); 5772}).catch((err: BusinessError) => { 5773 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 5774}); 5775``` 5776 5777### getOutputDevice<sup>10+</sup> 5778 5779getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 5780 5781获取播放设备信息。结果通过callback异步回调方式返回。 5782 5783**系统能力:** SystemCapability.Multimedia.AVSession.Core 5784 5785**参数:** 5786 5787| 参数名 | 类型 | 必填 | 说明 | 5788| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 5789| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是 | 回调函数,返回播放设备信息。 | 5790 5791**错误码:** 5792 5793以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5794 5795| 错误码ID | 错误信息 | 5796| -------- | ---------------------------------------- | 5797| 600101 | Session service exception. | 5798| 600103 | The session controller does not exist. | 5799 5800**示例:** 5801 5802```ts 5803import { BusinessError } from '@kit.BasicServicesKit'; 5804 5805avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => { 5806 if (err) { 5807 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 5808 } else { 5809 console.info('GetOutputDevice : SUCCESS'); 5810 } 5811}); 5812``` 5813 5814### sendAVKeyEvent<sup>10+</sup> 5815 5816sendAVKeyEvent(event: KeyEvent): Promise\<void> 5817 5818发送按键事件到控制器对应的会话。结果通过Promise异步回调方式返回。 5819 5820**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5821 5822**系统能力:** SystemCapability.Multimedia.AVSession.Core 5823 5824**参数:** 5825 5826| 参数名 | 类型 | 必填 | 说明 | 5827| ------ | ------------------------------------------------------------ | ---- | ---------- | 5828| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | 是 | 按键事件。 | 5829 5830**错误码:** 5831 5832以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5833 5834| 错误码ID | 错误信息 | 5835| -------- | ---------------------------------------- | 5836| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5837| 600101 | Session service exception. | 5838| 600102 | The session does not exist. | 5839| 600103 | The session controller does not exist. | 5840| 600105 | Invalid session command. | 5841| 600106 | The session is not activated. | 5842 5843**返回值:** 5844 5845| 类型 | 说明 | 5846| -------------- | ----------------------------- | 5847| Promise\<void> | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 | 5848 5849**示例:** 5850 5851```ts 5852import { Key, KeyEvent } from '@kit.InputKit'; 5853import { BusinessError } from '@kit.BasicServicesKit'; 5854 5855let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 5856let 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}; 5857 5858 5859avsessionController.sendAVKeyEvent(event).then(() => { 5860 console.info('SendAVKeyEvent Successfully'); 5861}).catch((err: BusinessError) => { 5862 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 5863}); 5864``` 5865 5866### sendAVKeyEvent<sup>10+</sup> 5867 5868sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void 5869 5870发送按键事件到会话。结果通过callback异步回调方式返回。 5871 5872**系统能力:** SystemCapability.Multimedia.AVSession.Core 5873 5874**参数:** 5875 5876| 参数名 | 类型 | 必填 | 说明 | 5877| -------- | ------------------------------------------------------------ | ---- | ---------- | 5878| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | 是 | 按键事件。 | 5879| callback | AsyncCallback\<void> | 是 | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 | 5880 5881**错误码:** 5882 5883以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5884 5885| 错误码ID | 错误信息 | 5886| -------- | ---------------------------------------- | 5887| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5888| 600101 | Session service exception. | 5889| 600102 | The session does not exist. | 5890| 600103 | The session controller does not exist. | 5891| 600105 | Invalid session command. | 5892| 600106 | The session is not activated. | 5893 5894**示例:** 5895 5896```ts 5897import { Key, KeyEvent } from '@kit.InputKit'; 5898import { BusinessError } from '@kit.BasicServicesKit'; 5899 5900let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 5901let 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}; 5902avsessionController.sendAVKeyEvent(event, (err: BusinessError) => { 5903 if (err) { 5904 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 5905 } else { 5906 console.info('SendAVKeyEvent Successfully'); 5907 } 5908}); 5909``` 5910 5911### getLaunchAbility<sup>10+</sup> 5912 5913getLaunchAbility(): Promise\<WantAgent> 5914 5915获取应用在会话中保存的WantAgent对象。结果通过Promise异步回调方式返回。 5916 5917**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5918 5919**系统能力:** SystemCapability.Multimedia.AVSession.Core 5920 5921**返回值:** 5922 5923| 类型 | 说明 | 5924| ------------------------------------------------------- | ------------------------------------------------------------ | 5925| Promise<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | Promise对象,返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 5926 5927**错误码:** 5928 5929以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5930 5931| 错误码ID | 错误信息 | 5932| -------- | ---------------------------------------- | 5933| 6600101 | Session service exception. | 5934| 6600102 | The session does not exist. | 5935| 6600103 | The session controller does not exist. | 5936 5937**示例:** 5938 5939```ts 5940import { BusinessError } from '@kit.BasicServicesKit'; 5941 5942avsessionController.getLaunchAbility().then((agent: object) => { 5943 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 5944}).catch((err: BusinessError) => { 5945 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 5946}); 5947``` 5948 5949### getLaunchAbility<sup>10+</sup> 5950 5951getLaunchAbility(callback: AsyncCallback\<WantAgent>): void 5952 5953获取应用在会话中保存的WantAgent对象。结果通过callback异步回调方式返回。 5954 5955**系统能力:** SystemCapability.Multimedia.AVSession.Core 5956 5957**参数:** 5958 5959| 参数名 | 类型 | 必填 | 说明 | 5960| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 5961| callback | AsyncCallback<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | 是 | 回调函数。返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | 5962 5963**错误码:** 5964 5965以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 5966 5967| 错误码ID | 错误信息 | 5968| -------- | ---------------------------------------- | 5969| 6600101 | Session service exception. | 5970| 6600102 | The session does not exist. | 5971| 6600103 | The session controller does not exist. | 5972 5973**示例:** 5974 5975```ts 5976import { BusinessError } from '@kit.BasicServicesKit'; 5977 5978avsessionController.getLaunchAbility((err: BusinessError, agent: object) => { 5979 if (err) { 5980 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 5981 } else { 5982 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 5983 } 5984}); 5985``` 5986 5987### getRealPlaybackPositionSync<sup>10+</sup> 5988 5989getRealPlaybackPositionSync(): number 5990 5991获取当前播放位置。 5992 5993**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 5994 5995**系统能力:** SystemCapability.Multimedia.AVSession.Core 5996 5997**返回值:** 5998 5999| 类型 | 说明 | 6000| ------ | ------------------ | 6001| number | 时间节点,毫秒数。 | 6002 6003**错误码:** 6004 6005以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6006 6007| 错误码ID | 错误信息 | 6008| -------- | ---------------------------------------- | 6009| 6600101 | Session service exception. | 6010| 6600103 | The session controller does not exist. | 6011 6012**示例:** 6013 6014```ts 6015let time: number = avsessionController.getRealPlaybackPositionSync(); 6016``` 6017 6018### isActive<sup>10+</sup> 6019 6020isActive(): Promise\<boolean> 6021 6022获取会话是否被激活。结果通过Promise异步回调方式返回。 6023 6024**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6025 6026**系统能力:** SystemCapability.Multimedia.AVSession.Core 6027 6028**返回值:** 6029 6030| 类型 | 说明 | 6031| ----------------- | ------------------------------------------------------------ | 6032| Promise<boolean\> | Promise对象,返回会话是否为激活状态,true表示被激活,false表示禁用。 | 6033 6034**错误码:** 6035 6036以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6037 6038| 错误码ID | 错误信息 | 6039| -------- | ---------------------------------------- | 6040| 6600101 | Session service exception. | 6041| 6600102 | The session does not exist. | 6042| 6600103 | The session controller does not exist. | 6043 6044**示例:** 6045 6046```ts 6047import { BusinessError } from '@kit.BasicServicesKit'; 6048 6049avsessionController.isActive().then((isActive: boolean) => { 6050 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6051}).catch((err: BusinessError) => { 6052 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6053}); 6054``` 6055 6056### isActive<sup>10+</sup> 6057 6058isActive(callback: AsyncCallback\<boolean>): void 6059 6060判断会话是否被激活。结果通过callback异步回调方式返回。 6061 6062**系统能力:** SystemCapability.Multimedia.AVSession.Core 6063 6064**参数:** 6065 6066| 参数名 | 类型 | 必填 | 说明 | 6067| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 6068| callback | AsyncCallback<boolean\> | 是 | 回调函数,返回会话是否为激活状态,true表示被激活,false表示禁用。 | 6069 6070**错误码:** 6071 6072以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6073 6074| 错误码ID | 错误信息 | 6075| -------- | ---------------------------------------- | 6076| 6600101 | Session service exception. | 6077| 6600102 | The session does not exist. | 6078| 6600103 | The session controller does not exist. | 6079 6080**示例:** 6081 6082```ts 6083import { BusinessError } from '@kit.BasicServicesKit'; 6084 6085avsessionController.isActive((err: BusinessError, isActive: boolean) => { 6086 if (err) { 6087 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6088 } else { 6089 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6090 } 6091}); 6092``` 6093 6094### destroy<sup>10+</sup> 6095 6096destroy(): Promise\<void> 6097 6098销毁当前控制器,销毁后当前控制器不可再用。结果通过Promise异步回调方式返回。 6099 6100**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6101 6102**系统能力:** SystemCapability.Multimedia.AVSession.Core 6103 6104**返回值:** 6105 6106| 类型 | 说明 | 6107| -------------- | ----------------------------- | 6108| Promise\<void> | Promise对象。当控制器销毁成功,无返回结果,否则返回错误对象。 | 6109 6110**错误码:** 6111 6112以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6113 6114| 错误码ID | 错误信息 | 6115| -------- | ---------------------------------------- | 6116| 6600101 | Session service exception. | 6117| 6600103 | The session controller does not exist. | 6118 6119**示例:** 6120 6121```ts 6122import { BusinessError } from '@kit.BasicServicesKit'; 6123 6124avsessionController.destroy().then(() => { 6125 console.info('Destroy : SUCCESS '); 6126}).catch((err: BusinessError) => { 6127 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6128}); 6129``` 6130 6131### destroy<sup>10+</sup> 6132 6133destroy(callback: AsyncCallback\<void>): void 6134 6135销毁当前控制器,销毁后当前控制器不可再用。结果通过callback异步回调方式返回。 6136 6137**系统能力:** SystemCapability.Multimedia.AVSession.Core 6138 6139**参数:** 6140 6141| 参数名 | 类型 | 必填 | 说明 | 6142| -------- | -------------------- | ---- | ---------- | 6143| callback | AsyncCallback\<void> | 是 | 回调函数。当控制器销毁成功,err为undefined,否则返回错误对象。 | 6144 6145**错误码:** 6146 6147以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6148 6149| 错误码ID | 错误信息 | 6150| -------- | ---------------------------------------- | 6151| 6600101 | Session service exception. | 6152| 6600103 | The session controller does not exist. | 6153 6154**示例:** 6155 6156```ts 6157import { BusinessError } from '@kit.BasicServicesKit'; 6158 6159avsessionController.destroy((err: BusinessError) => { 6160 if (err) { 6161 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6162 } else { 6163 console.info('Destroy : SUCCESS '); 6164 } 6165}); 6166``` 6167 6168### getValidCommands<sup>10+</sup> 6169 6170getValidCommands(): Promise\<Array\<AVControlCommandType>> 6171 6172获取会话支持的有效命令。结果通过Promise异步回调方式返回。 6173 6174**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6175 6176**系统能力:** SystemCapability.Multimedia.AVSession.Core 6177 6178**返回值:** 6179 6180| 类型 | 说明 | 6181| ------------------------------------------------------------ | --------------------------------- | 6182| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise对象。返回有效命令的集合。 | 6183 6184**错误码:** 6185 6186以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6187 6188| 错误码ID | 错误信息 | 6189| -------- | ---------------------------------------- | 6190| 6600101 | Session service exception. | 6191| 6600102 | The session does not exist. | 6192| 6600103 | The session controller does not exist. | 6193 6194**示例:** 6195 6196```ts 6197import { BusinessError } from '@kit.BasicServicesKit'; 6198 6199avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => { 6200 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6201}).catch((err: BusinessError) => { 6202 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6203}); 6204``` 6205 6206### getValidCommands<sup>10+</sup> 6207 6208getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void 6209 6210获取会话支持的有效命令。结果通过callback异步回调方式返回。 6211 6212**系统能力:** SystemCapability.Multimedia.AVSession.Core 6213 6214**参数:** 6215 6216| 参数名 | 类型 | 必填 | 说明 | 6217| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 6218| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | 是 | 回调函数,返回有效命令的集合。 | 6219 6220**错误码:** 6221 6222以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6223 6224| 错误码ID | 错误信息 | 6225| -------- | ---------------------------------------- | 6226| 6600101 | Session service exception. | 6227| 6600102 | The session does not exist. | 6228| 6600103 | The session controller does not exist. | 6229 6230**示例:** 6231 6232```ts 6233import { BusinessError } from '@kit.BasicServicesKit'; 6234 6235avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => { 6236 if (err) { 6237 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6238 } else { 6239 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6240 } 6241}); 6242``` 6243 6244### sendControlCommand<sup>10+</sup> 6245 6246sendControlCommand(command: AVControlCommand): Promise\<void> 6247 6248通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 6249 6250> **说明:** 6251> 6252> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。 6253 6254**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6255 6256**系统能力:** SystemCapability.Multimedia.AVSession.Core 6257 6258**参数:** 6259 6260| 参数名 | 类型 | 必填 | 说明 | 6261| ------- | ------------------------------------- | ---- | ------------------------------ | 6262| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 6263 6264**返回值:** 6265 6266| 类型 | 说明 | 6267| -------------- | ----------------------------- | 6268| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 6269 6270**错误码:** 6271 6272以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6273 6274| 错误码ID | 错误信息 | 6275| -------- | ---------------------------------------- | 6276| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6277| 6600101 | Session service exception. | 6278| 6600102 | The session does not exist. | 6279| 6600103 | The session controller does not exist. | 6280| 6600105 | Invalid session command. | 6281| 6600106 | The session is not activated. | 6282| 6600107 | Too many commands or events. | 6283 6284**示例:** 6285 6286```ts 6287import { BusinessError } from '@kit.BasicServicesKit'; 6288 6289let avCommand: avSession.AVControlCommand = {command:'play'}; 6290avsessionController.sendControlCommand(avCommand).then(() => { 6291 console.info('SendControlCommand successfully'); 6292}).catch((err: BusinessError) => { 6293 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6294}); 6295``` 6296 6297### sendControlCommand<sup>10+</sup> 6298 6299sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void 6300 6301通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 6302 6303> **说明:** 6304> 6305> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。 6306 6307**系统能力:** SystemCapability.Multimedia.AVSession.Core 6308 6309**参数:** 6310 6311| 参数名 | 类型 | 必填 | 说明 | 6312| -------- | ------------------------------------- | ---- | ------------------------------ | 6313| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | 6314| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 6315 6316**错误码:** 6317 6318以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6319 6320| 错误码ID | 错误信息 | 6321| -------- | ------------------------------- | 6322| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6323| 6600101 | Session service exception. | 6324| 6600102 | The session does not exist. | 6325| 6600103 | The session controller does not exist. | 6326| 6600105 | Invalid session command. | 6327| 6600106 | The session is not activated. | 6328| 6600107 | Too many commands or events. | 6329 6330**示例:** 6331 6332```ts 6333import { BusinessError } from '@kit.BasicServicesKit'; 6334 6335let avCommand: avSession.AVControlCommand = {command:'play'}; 6336avsessionController.sendControlCommand(avCommand, (err: BusinessError) => { 6337 if (err) { 6338 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6339 } else { 6340 console.info('SendControlCommand successfully'); 6341 } 6342}); 6343``` 6344 6345### sendCommonCommand<sup>10+</sup> 6346 6347sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void> 6348 6349通过会话控制器发送自定义控制命令到其对应的会话。结果通过Promise异步回调方式返回。 6350 6351**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6352 6353**系统能力:** SystemCapability.Multimedia.AVSession.Core 6354 6355**参数:** 6356 6357| 参数名 | 类型 | 必填 | 说明 | 6358| ------- | ------------------------------------- | ---- | ------------------------------ | 6359| command | string | 是 | 需要设置的自定义控制命令的名称 | 6360| args | {[key: string]: Object} | 是 | 需要传递的控制命令键值对 | 6361 6362> **说明:** 6363> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 6364 6365**返回值:** 6366 6367| 类型 | 说明 | 6368| -------------- | ----------------------------- | 6369| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | 6370 6371**错误码:** 6372 6373以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6374 6375| 错误码ID | 错误信息 | 6376| -------- | ---------------------------------------- | 6377| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6378| 6600101 | Session service exception. | 6379| 6600102 | The session does not exist. | 6380| 6600103 | The session controller does not exist. | 6381| 6600105 | Invalid session command. | 6382| 6600106 | The session is not activated. | 6383| 6600107 | Too many commands or events. | 6384 6385**示例:** 6386 6387```ts 6388import { BusinessError } from '@kit.BasicServicesKit'; 6389 6390let avSessionController: avSession.AVSessionController | undefined = undefined; 6391let currentAVSession: avSession.AVSession | undefined = undefined; 6392let tag = "createNewSession"; 6393let context: Context = getContext(this); 6394let sessionId: string = ""; 6395avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6396 if (err) { 6397 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6398 } else { 6399 currentAVSession = data; 6400 } 6401}); 6402if (currentAVSession !== undefined) { 6403 sessionId = (currentAVSession as avSession.AVSession).sessionId; 6404 avSession.createController(sessionId).then((controller: avSession.AVSessionController) => { 6405 avSessionController = controller; 6406 }).catch((err: BusinessError) => { 6407 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6408 }); 6409} 6410 6411let commandName = "my_command"; 6412if (avSessionController !== undefined) { 6413 (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => { 6414 console.info('SendCommonCommand successfully'); 6415 }).catch((err: BusinessError) => { 6416 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6417 }) 6418} 6419``` 6420 6421### sendCommonCommand<sup>10+</sup> 6422 6423sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 6424 6425通过会话控制器发送自定义命令到其对应的会话。结果通过callback异步回调方式返回。 6426 6427**系统能力:** SystemCapability.Multimedia.AVSession.Core 6428 6429**参数:** 6430 6431| 参数名 | 类型 | 必填 | 说明 | 6432| ------- | ------------------------------------- | ---- | ------------------------------ | 6433| command | string | 是 | 需要设置的自定义控制命令的名称 | 6434| args | {[key: string]: Object} | 是 | 需要传递的控制命令键值对 | 6435| callback | AsyncCallback\<void> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | 6436 6437> **说明:** 6438> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 6439 6440**错误码:** 6441 6442以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6443 6444| 错误码ID | 错误信息 | 6445| -------- | ------------------------------- | 6446| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.| 6447| 6600101 | Session service exception. | 6448| 6600102 | The session does not exist. | 6449| 6600103 | The session controller does not exist. | 6450| 6600105 | Invalid session command. | 6451| 6600106 | The session is not activated. | 6452| 6600107 | Too many commands or events. | 6453 6454**示例:** 6455 6456```ts 6457import { BusinessError } from '@kit.BasicServicesKit'; 6458let avSessionController: avSession.AVSessionController | undefined = undefined; 6459let currentAVSession: avSession.AVSession | undefined = undefined; 6460let tag = "createNewSession"; 6461let context: Context = getContext(this); 6462 6463avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6464 if (err) { 6465 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6466 } else { 6467 currentAVSession = data; 6468 } 6469}); 6470if (currentAVSession !== undefined) { 6471 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 6472 avSessionController = controller; 6473 }).catch((err: BusinessError) => { 6474 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6475 }); 6476} 6477 6478let commandName = "my_command"; 6479if (avSessionController !== undefined) { 6480 (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => { 6481 if (err) { 6482 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6483 } 6484 }) 6485} 6486``` 6487 6488### getExtras<sup>10+</sup> 6489 6490getExtras(): Promise\<{[key: string]: Object}> 6491 6492获取媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。 6493 6494**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6495 6496**系统能力:** SystemCapability.Multimedia.AVSession.Core 6497 6498**返回值:** 6499 6500| 类型 | 说明 | 6501| ----------------------------------- | ----------------------------- | 6502| Promise<{[key: string]: Object}\> | Promise对象,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | 6503 6504**错误码:** 6505 6506以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6507 6508| 错误码ID | 错误信息 | 6509| -------- | ---------------------------------------- | 6510| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6511| 6600101 | Session service exception. | 6512| 6600102 | The session does not exist. | 6513| 6600103 | The session controller does not exist. | 6514| 6600105 | Invalid session command. | 6515| 6600107 | Too many commands or events. | 6516 6517**示例:** 6518 6519```ts 6520import { BusinessError } from '@kit.BasicServicesKit'; 6521 6522let avSessionController: avSession.AVSessionController | undefined = undefined; 6523let currentAVSession: avSession.AVSession | undefined = undefined; 6524let tag = "createNewSession"; 6525let context: Context = getContext(this); 6526 6527avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6528 if (err) { 6529 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6530 } else { 6531 currentAVSession = data; 6532 } 6533}); 6534if (currentAVSession !== undefined) { 6535 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 6536 avSessionController = controller; 6537 }).catch((err: BusinessError) => { 6538 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6539 }); 6540} 6541 6542if (avSessionController !== undefined) { 6543 (avSessionController as avSession.AVSessionController).getExtras().then((extras) => { 6544 console.info(`getExtras : SUCCESS : ${extras}`); 6545 }).catch((err: BusinessError) => { 6546 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 6547 }); 6548} 6549``` 6550 6551### getExtras<sup>10+</sup> 6552 6553getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void 6554 6555获取媒体提供方设置的自定义媒体数据包,结果通过callback异步回调方式返回。 6556 6557**系统能力:** SystemCapability.Multimedia.AVSession.Core 6558 6559**参数:** 6560 6561| 参数名 | 类型 | 必填 | 说明 | 6562| -------- | ----------------------------------------- | ---- | -------------------------- | 6563| callback | AsyncCallback<{[key: string]: Object}\> | 是 | 回调函数,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | 6564 6565**错误码:** 6566 6567以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6568 6569| 错误码ID | 错误信息 | 6570| -------- | ---------------------------------------- | 6571| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6572| 6600101 | Session service exception. | 6573| 6600102 | The session does not exist. | 6574| 6600103 | The session controller does not exist. | 6575| 6600105 | Invalid session command. | 6576| 6600107 | Too many commands or events. | 6577 6578**示例:** 6579 6580```ts 6581import { BusinessError } from '@kit.BasicServicesKit'; 6582 6583let avSessionController: avSession.AVSessionController | undefined = undefined; 6584let currentAVSession: avSession.AVSession | undefined = undefined; 6585let tag = "createNewSession"; 6586let context: Context = getContext(this); 6587 6588avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6589 if (err) { 6590 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6591 } else { 6592 currentAVSession = data; 6593 } 6594}); 6595if (currentAVSession !== undefined) { 6596 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 6597 avSessionController = controller; 6598 }).catch((err: BusinessError) => { 6599 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6600 }); 6601} 6602 6603if (avSessionController !== undefined) { 6604 (avSessionController as avSession.AVSessionController).getExtras((err, extras) => { 6605 if (err) { 6606 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 6607 } else { 6608 console.info(`getExtras : SUCCESS : ${extras}`); 6609 } 6610 }); 6611} 6612``` 6613 6614### on('metadataChange')<sup>10+</sup> 6615 6616on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void) 6617 6618设置元数据变化的监听事件。 6619 6620**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6621 6622**系统能力:** SystemCapability.Multimedia.AVSession.Core 6623 6624**参数:** 6625 6626| 参数名 | 类型 | 必填 | 说明 | 6627| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6628| type | string | 是 | 事件回调类型,支持事件`'metadataChange'`:当元数据变化时,触发该事件。 | 6629| filter | Array\<keyof [AVMetadata](#avmetadata10)\> | 'all' | 是 | 'all' 表示关注元数据所有字段变化;Array<keyof [AVMetadata](#avmetadata10)\> 表示关注Array中的字段变化。 | 6630| callback | (data: [AVMetadata](#avmetadata10)) => void | 是 | 回调函数,参数data是变化后的元数据。 | 6631 6632**错误码:** 6633 6634以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6635 6636| 错误码ID | 错误信息 | 6637| -------- | ------------------------------ | 6638| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6639| 6600101 | Session service exception. | 6640| 6600103 | The session controller does not exist. | 6641 6642**示例:** 6643 6644```ts 6645avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => { 6646 console.info(`on metadataChange assetId : ${metadata.assetId}`); 6647}); 6648 6649avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => { 6650 console.info(`on metadataChange assetId : ${metadata.assetId}`); 6651}); 6652 6653``` 6654 6655### off('metadataChange')<sup>10+</sup> 6656 6657off(type: 'metadataChange', callback?: (data: AVMetadata) => void) 6658 6659媒体控制器取消监听元数据变化的事件。 6660 6661**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6662 6663**系统能力:** SystemCapability.Multimedia.AVSession.Core 6664 6665**参数:** 6666 6667| 参数名 | 类型 | 必填 | 说明 | 6668| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | 6669| type | string | 是 | 取消对应的监听事件,支持事件`'metadataChange'`。 | 6670| callback | (data: [AVMetadata](#avmetadata10)) => void | 否 | 回调函数,参数data是变化后的元数据。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 6671 6672**错误码:** 6673 6674以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6675 6676| 错误码ID | 错误信息 | 6677| -------- | ---------------- | 6678| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6679| 6600101 | Session service exception. | 6680| 6600103 | The session controller does not exist. | 6681 6682**示例:** 6683 6684```ts 6685avsessionController.off('metadataChange'); 6686``` 6687 6688### on('playbackStateChange')<sup>10+</sup> 6689 6690on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void) 6691 6692设置播放状态变化的监听事件。 6693 6694**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6695 6696**系统能力:** SystemCapability.Multimedia.AVSession.Core 6697 6698**参数:** 6699 6700| 参数名 | 类型 | 必填 | 说明 | 6701| --------| -----------|-----|------------| 6702| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | 6703| filter | Array\<keyof [AVPlaybackState](#avplaybackstate10)\> | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array<keyof [AVPlaybackState](#avplaybackstate10)\> 表示关注Array中的字段变化。 | 6704| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。| 6705 6706**错误码:** 6707 6708以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6709 6710| 错误码ID | 错误信息 | 6711| -------- | ------------------------------ | 6712| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6713| 6600101 | Session service exception. | 6714| 6600103 | The session controller does not exist. | 6715 6716**示例:** 6717 6718```ts 6719avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 6720 console.info(`on playbackStateChange state : ${playbackState.state}`); 6721}); 6722 6723avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => { 6724 console.info(`on playbackStateChange state : ${playbackState.state}`); 6725}); 6726``` 6727 6728### off('playbackStateChange')<sup>10+</sup> 6729 6730off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) 6731 6732媒体控制器取消监听播放状态变化的事件。 6733 6734**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6735 6736**系统能力:** SystemCapability.Multimedia.AVSession.Core 6737 6738**参数:** 6739 6740| 参数名 | 类型 | 必填 | 说明 | 6741| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 6742| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | 6743| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 6744 6745**错误码:** 6746 6747以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6748 6749| 错误码ID | 错误信息 | 6750| -------- | ---------------- | 6751| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6752| 6600101 | Session service exception. | 6753| 6600103 | The session controller does not exist. | 6754 6755**示例:** 6756 6757```ts 6758avsessionController.off('playbackStateChange'); 6759``` 6760 6761### on('callMetadataChange')<sup>11+</sup> 6762 6763on(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void; 6764 6765设置通话元数据变化的监听事件。 6766 6767**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6768 6769**系统能力:** SystemCapability.Multimedia.AVSession.Core 6770 6771**参数:** 6772 6773| 参数名 | 类型 | 必填 | 说明 | 6774| --------| -----------|-----|------------| 6775| type | string | 是 | 事件回调类型,支持事件`'callMetadataChange'`:当通话元数据变化时,触发该事件。 | 6776| filter | Array\<keyof [CallMetadata](#callmetadata11)\> | 'all' | 是 | 'all' 表示关注通话元数据所有字段变化;Array<keyof [CallMetadata](#callmetadata11)\> 表示关注Array中的字段变化。 | 6777| callback | Callback<[CallMetadata](#callmetadata11)\>\> | 是 | 回调函数,参数callmetadata是变化后的通话元数据。| 6778 6779**错误码:** 6780 6781以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6782 6783| 错误码ID | 错误信息 | 6784| -------- | ------------------------------ | 6785| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6786| 6600101 | Session service exception. | 6787| 6600103 | The session controller does not exist. | 6788 6789**示例:** 6790 6791```ts 6792avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => { 6793 console.info(`on callMetadataChange state : ${callmetadata.name}`); 6794}); 6795 6796avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => { 6797 console.info(`on callMetadataChange state : ${callmetadata.name}`); 6798}); 6799``` 6800 6801### off('callMetadataChange')<sup>11+</sup> 6802 6803off(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void; 6804 6805取消设置通话元数据变化的监听事件。 6806 6807**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6808 6809**系统能力:** SystemCapability.Multimedia.AVSession.Core 6810 6811**参数:** 6812 6813| 参数名 | 类型 | 必填 | 说明 | 6814| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 6815| type | string | 是 | 取消对应的监听事件,支持事件`'callMetadataChange'`。 | 6816| callback | Callback<[CallMetadata](#callmetadata11)\> | 否 | 回调函数,参数calldata是变化后的通话原数据。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 6817 6818**错误码:** 6819 6820以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6821 6822| 错误码ID | 错误信息 | 6823| -------- | ---------------- | 6824| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6825| 6600101 | Session service exception. | 6826| 6600103 | The session controller does not exist. | 6827 6828**示例:** 6829 6830```ts 6831avsessionController.off('callMetadataChange'); 6832``` 6833 6834### on('callStateChange')<sup>11+</sup> 6835 6836on(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void; 6837 6838设置通话状态变化的监听事件。 6839 6840**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6841 6842**系统能力:** SystemCapability.Multimedia.AVSession.Core 6843 6844**参数:** 6845 6846| 参数名 | 类型 | 必填 | 说明 | 6847| --------| -----------|-----|------------| 6848| type | string | 是 | 事件回调类型,支持事件`'callStateChange'`:当通话状态变化时,触发该事件。 | 6849| filter | Array<keyof [AVCallState](#avcallstate11)\> | 'all' | 是 | 'all' 表示关注通话状态所有字段变化;Array<keyof [AVCallState](#avcallstate11)\> 表示关注Array中的字段变化。 | 6850| callback | Callback<[AVCallState](#avcallstate11)\> | 是 | 回调函数,参数callstate是变化后的通话状态。| 6851 6852**错误码:** 6853 6854以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6855 6856| 错误码ID | 错误信息 | 6857| -------- | ------------------------------ | 6858| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6859| 6600101 | Session service exception. | 6860| 6600103 | The session controller does not exist. | 6861 6862**示例:** 6863 6864```ts 6865avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => { 6866 console.info(`on callStateChange state : ${callstate.state}`); 6867}); 6868 6869avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => { 6870 console.info(`on callStateChange state : ${callstate.state}`); 6871}); 6872``` 6873 6874### off('callStateChange')<sup>11+</sup> 6875 6876off(type: 'callStateChange', callback?: Callback\<AVCallState>): void; 6877 6878取消设置通话状态变化的监听事件。 6879 6880**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6881 6882**系统能力:** SystemCapability.Multimedia.AVSession.Core 6883 6884**参数:** 6885 6886| 参数名 | 类型 | 必填 | 说明 | 6887| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 6888| type | string | 是 | 取消对应的监听事件,支持事件`'callStateChange'`。 | 6889| callback | Callback<[AVCallState](#avcallstate11)\> | 否 | 回调函数,参数callstate是变化后的通话状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 6890 6891**错误码:** 6892 6893以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6894 6895| 错误码ID | 错误信息 | 6896| -------- | ---------------- | 6897| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6898| 6600101 | Session service exception. | 6899| 6600103 | The session controller does not exist. | 6900 6901**示例:** 6902 6903```ts 6904avsessionController.off('callMetadataChange'); 6905``` 6906 6907### on('sessionDestroy')<sup>10+</sup> 6908 6909on(type: 'sessionDestroy', callback: () => void) 6910 6911会话销毁的监听事件。 6912 6913**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6914 6915**系统能力:** SystemCapability.Multimedia.AVSession.Core 6916 6917**参数:** 6918 6919| 参数名 | 类型 | 必填 | 说明 | 6920| -------- | ---------- | ---- | ------------------------------------------------------------ | 6921| type | string | 是 | 事件回调类型,支持事件`'sessionDestroy'`:当检测到会话销毁时,触发该事件)。 | 6922| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | 6923 6924**错误码:** 6925 6926以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6927 6928| 错误码ID | 错误信息 | 6929| -------- | ------------------------------ | 6930| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6931| 6600101 | Session service exception. | 6932| 6600103 | The session controller does not exist. | 6933 6934**示例:** 6935 6936```ts 6937avsessionController.on('sessionDestroy', () => { 6938 console.info('on sessionDestroy : SUCCESS '); 6939}); 6940``` 6941 6942### off('sessionDestroy')<sup>10+</sup> 6943 6944off(type: 'sessionDestroy', callback?: () => void) 6945 6946媒体控制器取消监听会话的销毁事件。 6947 6948**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6949 6950**系统能力:** SystemCapability.Multimedia.AVSession.Core 6951 6952**参数:** 6953 6954| 参数名 | 类型 | 必填 | 说明 | 6955| -------- | ---------- | ---- | ----------------------------------------------------- | 6956| type | string | 是 | 取消对应的监听事件,支持事件`'sessionDestroy'`。 | 6957| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 6958 6959**错误码:** 6960 6961以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6962 6963| 错误码ID | 错误信息 | 6964| -------- | ---------------- | 6965| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6966| 6600101 | Session service exception. | 6967| 6600103 | The session controller does not exist. | 6968 6969**示例:** 6970 6971```ts 6972avsessionController.off('sessionDestroy'); 6973``` 6974 6975### on('activeStateChange')<sup>10+</sup> 6976 6977on(type: 'activeStateChange', callback: (isActive: boolean) => void) 6978 6979会话的激活状态的监听事件。 6980 6981**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 6982 6983**系统能力:** SystemCapability.Multimedia.AVSession.Core 6984 6985**参数:** 6986 6987| 参数名 | 类型 | 必填 | 说明 | 6988| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 6989| type | string | 是 | 事件回调类型,支持事件`'activeStateChange'`:当检测到会话的激活状态发生改变时,触发该事件。 | 6990| callback | (isActive: boolean) => void | 是 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。 | 6991 6992**错误码:** 6993 6994以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 6995 6996| 错误码ID | 错误信息 | 6997| -------- | ----------------------------- | 6998| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6999| 6600101 | Session service exception. | 7000| 6600103 |The session controller does not exist. | 7001 7002**示例:** 7003 7004```ts 7005avsessionController.on('activeStateChange', (isActive: boolean) => { 7006 console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); 7007}); 7008``` 7009 7010### off('activeStateChange')<sup>10+</sup> 7011 7012off(type: 'activeStateChange', callback?: (isActive: boolean) => void) 7013 7014媒体控制器取消监听会话激活状态变化的事件。 7015 7016**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7017 7018**系统能力:** SystemCapability.Multimedia.AVSession.Core 7019 7020**参数:** 7021 7022| 参数名 | 类型 | 必填 | 说明 | 7023| -------- | --------------------------- | ---- | ----------------------------------------------------- | 7024| type | string | 是 | 取消对应的监听事件,支持事件`'activeStateChange'`。 | 7025| callback | (isActive: boolean) => void | 否 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7026 7027**错误码:** 7028 7029以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7030 7031| 错误码ID | 错误信息 | 7032| -------- | ---------------- | 7033| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7034| 6600101 | Session service exception. | 7035| 6600103 | The session controller does not exist. | 7036 7037**示例:** 7038 7039```ts 7040avsessionController.off('activeStateChange'); 7041``` 7042 7043### on('validCommandChange')<sup>10+</sup> 7044 7045on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void) 7046 7047会话支持的有效命令变化监听事件。 7048 7049**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7050 7051**系统能力:** SystemCapability.Multimedia.AVSession.Core 7052 7053**参数:** 7054 7055| 参数名 | 类型 | 必填 | 说明 | 7056| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7057| type | string | 是 | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 | 7058| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 是 | 回调函数。参数commands是有效命令的集合。 | 7059 7060**错误码:** 7061 7062以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7063 7064| 错误码ID | 错误信息 | 7065| -------- | ------------------------------ | 7066| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7067| 6600101 | Session service exception. | 7068| 6600103 | The session controller does not exist. | 7069 7070**示例:** 7071 7072```ts 7073avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => { 7074 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 7075 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 7076}); 7077``` 7078 7079### off('validCommandChange')<sup>10+</sup> 7080 7081off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void) 7082 7083媒体控制器取消监听会话有效命令变化的事件。 7084 7085**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7086 7087**系统能力:** SystemCapability.Multimedia.AVSession.Core 7088 7089**参数:** 7090 7091| 参数名 | 类型 | 必填 | 说明 | 7092| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 7093| type | string | 是 | 取消对应的监听事件,支持事件`'validCommandChange'`。 | 7094| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 否 | 回调函数。参数commands是有效命令的集合。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7095 7096**错误码:** 7097 7098以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7099 7100| 错误码ID | 错误信息 | 7101| -------- | ---------------- | 7102| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7103| 6600101 | Session service exception. | 7104| 6600103 | The session controller does not exist. | 7105 7106**示例:** 7107 7108```ts 7109avsessionController.off('validCommandChange'); 7110``` 7111 7112### on('outputDeviceChange')<sup>10+</sup> 7113 7114on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7115 7116设置播放设备变化的监听事件。 7117 7118**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7119 7120**系统能力:** SystemCapability.Multimedia.AVSession.Core 7121 7122**参数:** 7123 7124| 参数名 | 类型 | 必填 | 说明 | 7125| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 7126| type | string | 是 | 事件回调类型,支持事件为`'outputDeviceChange'`:当播放设备变化时,触发该事件)。 | 7127| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是 | 回调函数,参数device是设备相关信息。 | 7128 7129**错误码:** 7130 7131以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7132 7133| 错误码ID | 错误信息 | 7134| -------- | ----------------------- | 7135| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7136| 6600101 | Session service exception. | 7137| 6600103 | The session controller does not exist. | 7138 7139**示例:** 7140 7141```ts 7142avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 7143 console.info(`on outputDeviceChange state: ${state}, device : ${device}`); 7144}); 7145``` 7146 7147### off('outputDeviceChange')<sup>10+</sup> 7148 7149off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7150 7151媒体控制器取消监听分布式设备变化的事件。 7152 7153**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7154 7155**系统能力:** SystemCapability.Multimedia.AVSession.Core 7156 7157**参数:** 7158 7159| 参数名 | 类型 | 必填 | 说明 | 7160| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 7161| type | string | 是 | 取消对应的监听事件,支持事件`'outputDeviceChange'`。 | 7162| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否 | 回调函数,参数device是设备相关信息。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7163 7164**错误码:** 7165 7166以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7167 7168| 错误码ID | 错误信息 | 7169| -------- | ---------------- | 7170| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7171| 6600101 | Session service exception. | 7172| 6600103 | The session controller does not exist. | 7173 7174**示例:** 7175 7176```ts 7177avsessionController.off('outputDeviceChange'); 7178``` 7179 7180### on('sessionEvent')<sup>10+</sup> 7181 7182on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void 7183 7184媒体控制器设置会话自定义事件变化的监听器。 7185 7186**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7187 7188**系统能力:** SystemCapability.Multimedia.AVSession.Core 7189 7190**参数:** 7191 7192| 参数名 | 类型 | 必填 | 说明 | 7193| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7194| type | string | 是 | 事件回调类型,支持事件`'sessionEvent'`:当会话事件变化时,触发该事件。 | 7195| callback | (sessionEvent: string, args: {[key:string]: object}) => void | 是 | 回调函数,sessionEvent为变化的会话事件名,args为事件的参数。 | 7196 7197**错误码:** 7198 7199以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7200 7201| 错误码ID | 错误信息 | 7202| -------- | ------------------------------ | 7203| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7204| 6600101 | Session service exception. | 7205| 6600103 | The session controller does not exist. | 7206 7207**示例:** 7208 7209```ts 7210import { BusinessError } from '@kit.BasicServicesKit'; 7211 7212let avSessionController: avSession.AVSessionController | undefined = undefined; 7213let currentAVSession: avSession.AVSession | undefined = undefined; 7214let tag = "createNewSession"; 7215let context: Context = getContext(this); 7216 7217avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 7218 if (err) { 7219 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 7220 } else { 7221 currentAVSession = data; 7222 } 7223}); 7224if (currentAVSession !== undefined) { 7225 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 7226 avSessionController = controller; 7227 }).catch((err: BusinessError) => { 7228 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 7229 }); 7230} 7231 7232if (avSessionController !== undefined) { 7233 (avSessionController as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => { 7234 console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); 7235 }); 7236} 7237``` 7238 7239### off('sessionEvent')<sup>10+</sup> 7240 7241off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void 7242 7243媒体控制器取消监听会话事件的变化通知。 7244 7245**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7246 7247**系统能力:** SystemCapability.Multimedia.AVSession.Core 7248 7249**参数:** 7250 7251| 参数名 | 类型 | 必填 | 说明 | 7252| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7253| type | string | 是 | 取消对应的监听事件,支持事件`'sessionEvent'`。 | 7254| callback | (sessionEvent: string, args: {[key:string]: Object}) => void | 否 | 回调函数,参数sessionEvent是变化的事件名,args为事件的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对sessionEvent事件的监听。 | 7255 7256**错误码:** 7257 7258以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7259 7260| 错误码ID | 错误信息 | 7261| -------- | ---------------- | 7262| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7263| 6600101 | Session service exception. | 7264| 6600103 | The session controller does not exist. | 7265 7266**示例:** 7267 7268```ts 7269avsessionController.off('sessionEvent'); 7270``` 7271 7272### on('queueItemsChange')<sup>10+</sup> 7273 7274on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7275 7276媒体控制器设置会话自定义播放列表变化的监听器。 7277 7278**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7279 7280**系统能力:** SystemCapability.Multimedia.AVSession.Core 7281 7282**参数:** 7283 7284| 参数名 | 类型 | 必填 | 说明 | 7285| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | 7286| type | string | 是 | 事件回调类型,支持事件`'queueItemsChange'`:当session修改播放列表时,触发该事件。 | 7287| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 是 | 回调函数,items为变化的播放列表。 | 7288 7289**错误码:** 7290 7291以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7292 7293| 错误码ID | 错误信息 | 7294| -------- | ------------------------------ | 7295| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7296| 6600101 | Session service exception. | 7297| 6600103 | The session controller does not exist. | 7298 7299**示例:** 7300 7301```ts 7302avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => { 7303 console.info(`OnQueueItemsChange, items length is ${items.length}`); 7304}); 7305``` 7306 7307### off('queueItemsChange')<sup>10+</sup> 7308 7309off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7310 7311媒体控制器取消监听播放列表变化的事件。 7312 7313**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7314 7315**系统能力:** SystemCapability.Multimedia.AVSession.Core 7316 7317**参数:** 7318 7319| 参数名 | 类型 | 必填 | 说明 | 7320| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | 7321| type | string | 是 | 取消对应的监听事件,支持事件`'queueItemsChange'`。 | 7322| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 否 | 回调函数,参数items是变化的播放列表。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7323 7324**错误码:** 7325 7326以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7327 7328| 错误码ID | 错误信息 | 7329| -------- | ---------------- | 7330| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7331| 6600101 | Session service exception. | 7332| 6600103 | The session controller does not exist. | 7333 7334**示例:** 7335 7336```ts 7337avsessionController.off('queueItemsChange'); 7338``` 7339 7340### on('queueTitleChange')<sup>10+</sup> 7341 7342on(type: 'queueTitleChange', callback: (title: string) => void): void 7343 7344媒体控制器设置会话自定义播放列表的名称变化的监听器。 7345 7346**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7347 7348**系统能力:** SystemCapability.Multimedia.AVSession.Core 7349 7350**参数:** 7351 7352| 参数名 | 类型 | 必填 | 说明 | 7353| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | 7354| type | string | 是 | 事件回调类型,支持事件`'queueTitleChange'`:当session修改播放列表名称时,触发该事件。 | 7355| callback | (title: string) => void | 是 | 回调函数,title为变化的播放列表名称。 | 7356 7357**错误码:** 7358 7359以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7360 7361| 错误码ID | 错误信息 | 7362| -------- | ------------------------------ | 7363| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7364| 6600101 | Session service exception. | 7365| 6600103 | The session controller does not exist. | 7366 7367**示例:** 7368 7369```ts 7370avsessionController.on('queueTitleChange', (title: string) => { 7371 console.info(`queueTitleChange, title is ${title}`); 7372}); 7373``` 7374 7375### off('queueTitleChange')<sup>10+</sup> 7376 7377off(type: 'queueTitleChange', callback?: (title: string) => void): void 7378 7379媒体控制器取消监听播放列表名称变化的事件。 7380 7381**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7382 7383**系统能力:** SystemCapability.Multimedia.AVSession.Core 7384 7385**参数:** 7386 7387| 参数名 | 类型 | 必填 | 说明 | 7388| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7389| type | string | 是 | 取消对应的监听事件,支持事件`'queueTitleChange'`。 | 7390| callback | (title: string) => void | 否 | 回调函数,参数items是变化的播放列表名称。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | 7391 7392**错误码:** 7393 7394以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7395 7396| 错误码ID | 错误信息 | 7397| -------- | ---------------- | 7398| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7399| 6600101 | Session service exception. | 7400| 6600103 | The session controller does not exist. | 7401 7402**示例:** 7403 7404```ts 7405avsessionController.off('queueTitleChange'); 7406``` 7407 7408### on('extrasChange')<sup>10+</sup> 7409 7410on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void 7411 7412媒体控制器设置自定义媒体数据包事件变化的监听器。 7413 7414**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7415 7416**系统能力:** SystemCapability.Multimedia.AVSession.Core 7417 7418**参数:** 7419 7420| 参数名 | 类型 | 必填 | 说明 | 7421| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7422| type | string | 是 | 事件回调类型,支持事件`'extrasChange'`:当媒体提供方设置自定义媒体数据包时,触发该事件。 | 7423| callback | (extras: {[key:string]: object}) => void | 是 | 回调函数,extras为媒体提供方新设置的自定义媒体数据包,该自定义媒体数据包与dispatchSessionEvent方法设置的数据包完全一致。 | 7424 7425**错误码:** 7426 7427以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7428 7429| 错误码ID | 错误信息 | 7430| -------- | ------------------------------ | 7431| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7432| 6600101 | Session service exception. | 7433| 6600103 | The session controller does not exist. | 7434 7435**示例:** 7436 7437```ts 7438import { BusinessError } from '@kit.BasicServicesKit'; 7439 7440let avSessionController: avSession.AVSessionController | undefined = undefined; 7441let currentAVSession: avSession.AVSession | undefined = undefined; 7442let tag = "createNewSession"; 7443let context: Context = getContext(this); 7444 7445avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 7446 if (err) { 7447 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 7448 } else { 7449 currentAVSession = data; 7450 } 7451}); 7452if (currentAVSession !== undefined) { 7453 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 7454 avSessionController = controller; 7455 }).catch((err: BusinessError) => { 7456 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 7457 }); 7458} 7459 7460if (avSessionController !== undefined) { 7461 (avSessionController as avSession.AVSessionController).on('extrasChange', (extras) => { 7462 console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); 7463 }); 7464} 7465``` 7466 7467### off('extrasChange')<sup>10+</sup> 7468 7469off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void 7470 7471媒体控制器取消监听自定义媒体数据包变化事件。 7472 7473**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7474 7475**系统能力:** SystemCapability.Multimedia.AVSession.Core 7476 7477**参数:** 7478 7479| 参数名 | 类型 | 必填 | 说明 | 7480| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7481| type | string | 是 | 取消对应的监听事件,支持事件`'extrasChange'`。 | 7482| callback | ({[key:string]: Object}) => void | 否 | 注册监听事件时的回调函数。<br>该参数为可选参数,若不填写该参数,则认为取消会话所有与此事件相关的监听。 | 7483 7484**错误码:** 7485 7486以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7487 7488| 错误码ID | 错误信息 | 7489| -------- | ---------------- | 7490| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7491| 6600101 | Session service exception. | 7492| 6600103 | The session controller does not exist. | 7493 7494**示例:** 7495 7496```ts 7497avsessionController.off('extrasChange'); 7498``` 7499 7500### getAVPlaybackStateSync<sup>10+</sup> 7501 7502getAVPlaybackStateSync(): AVPlaybackState; 7503 7504使用同步方法获取当前会话的播放状态。 7505 7506**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7507 7508**系统能力:** SystemCapability.Multimedia.AVSession.Core 7509 7510**返回值:** 7511 7512| 类型 | 说明 | 7513| --------- | ------------------------------------------------------------ | 7514| [AVPlaybackState](#avplaybackstate10) | 当前会话的播放状态。 | 7515 7516**错误码:** 7517 7518以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7519 7520| 错误码ID | 错误信息 | 7521| -------- | ---------------------------------------- | 7522| 6600101 | Session service exception. | 7523| 6600102 | The session does not exist. | 7524| 6600103 | The session controller does not exist. | 7525 7526**示例:** 7527 7528```ts 7529import { BusinessError } from '@kit.BasicServicesKit'; 7530 7531try { 7532 let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync(); 7533} catch (err) { 7534 let error = err as BusinessError; 7535 console.info(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`); 7536} 7537``` 7538 7539### getAVMetadataSync<sup>10+</sup> 7540 7541getAVMetadataSync(): AVMetadata 7542 7543使用同步方法获取会话元数据。 7544 7545**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7546 7547**系统能力:** SystemCapability.Multimedia.AVSession.Core 7548 7549**返回值:** 7550 7551| 类型 | 说明 | 7552| ----------------------------------- | ----------------------------- | 7553| [AVMetadata](#avmetadata10) | 会话元数据。 | 7554 7555**错误码:** 7556 7557以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7558 7559| 错误码ID | 错误信息 | 7560| -------- | ---------------------------------------- | 7561| 6600101 | Session service exception. | 7562| 6600102 | The session does not exist. | 7563| 6600103 | The session controller does not exist. | 7564 7565**示例:** 7566```ts 7567import { BusinessError } from '@kit.BasicServicesKit'; 7568 7569try { 7570 let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync(); 7571} catch (err) { 7572 let error = err as BusinessError; 7573 console.info(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`); 7574} 7575``` 7576 7577### getAVCallState<sup>11+</sup> 7578 7579getAVCallState(): Promise\<AVCallState> 7580 7581获取通话状态数据。结果通过Promise异步回调方式返回。 7582 7583**系统能力:** SystemCapability.Multimedia.AVSession.Core 7584 7585**返回值:** 7586 7587| 类型 | 说明 | 7588| ----------------------------------- | ----------------------------- | 7589| Promise<[AVCallState](#avcallstate11)\> | Promise对象,返回通话状态。 | 7590 7591**错误码:** 7592 7593以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7594 7595| 错误码ID | 错误信息 | 7596| -------- | ---------------------------------------- | 7597| 6600101 | Session service exception. | 7598| 6600102 | The session does not exist. | 7599| 6600103 | The session controller does not exist. | 7600 7601**示例:** 7602 7603```ts 7604import { BusinessError } from '@kit.BasicServicesKit'; 7605 7606avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => { 7607 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 7608}).catch((err: BusinessError) => { 7609 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 7610}); 7611``` 7612 7613### getAVCallState<sup>11+</sup> 7614 7615getAVCallState(callback: AsyncCallback\<AVCallState>): void 7616 7617获取通话状态数据。结果通过callback异步回调方式返回。 7618 7619**系统能力:** SystemCapability.Multimedia.AVSession.Core 7620 7621**参数:** 7622 7623| 参数名 | 类型 | 必填 | 说明 | 7624| -------- | ----------------------------------------- | ---- | -------------------------- | 7625| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | 是 | 回调函数,返回通话状态。 | 7626 7627**错误码:** 7628 7629以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7630 7631| 错误码ID | 错误信息 | 7632| -------- | ---------------------------------------- | 7633| 6600101 | Session service exception. | 7634| 6600102 | The session does not exist. | 7635| 6600103 | The session controller does not exist. | 7636 7637**示例:** 7638 7639```ts 7640import { BusinessError } from '@kit.BasicServicesKit'; 7641 7642avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => { 7643 if (err) { 7644 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 7645 } else { 7646 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 7647 } 7648}); 7649``` 7650 7651### getCallMetadata<sup>11+</sup> 7652 7653getCallMetadata(): Promise\<CallMetadata> 7654 7655获取通话会话的元数据。结果通过Promise异步回调方式返回。 7656 7657**系统能力:** SystemCapability.Multimedia.AVSession.Core 7658 7659**返回值:** 7660 7661| 类型 | 说明 | 7662| ----------------------------------- | ----------------------------- | 7663| Promise<[CallMetadata](#callmetadata11)\> | Promise对象,返回会话元数据。 | 7664 7665**错误码:** 7666 7667以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7668 7669| 错误码ID | 错误信息 | 7670| -------- | ---------------------------------------- | 7671| 6600101 | Session service exception. | 7672| 6600102 | The session does not exist. | 7673| 6600103 | The session controller does not exist. | 7674 7675**示例:** 7676 7677```ts 7678import { BusinessError } from '@kit.BasicServicesKit'; 7679 7680avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => { 7681 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 7682}).catch((err: BusinessError) => { 7683 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 7684}); 7685``` 7686 7687### getCallMetadata<sup>11+</sup> 7688 7689getCallMetadata(callback: AsyncCallback\<CallMetadata>): void 7690 7691获取通话会话的元数据。结果通过callback异步回调方式返回。 7692 7693**系统能力:** SystemCapability.Multimedia.AVSession.Core 7694 7695**参数:** 7696 7697| 参数名 | 类型 | 必填 | 说明 | 7698| -------- | ----------------------------------------- | ---- | -------------------------- | 7699| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | 是 | 回调函数,返回会话元数据。 | 7700 7701**错误码:** 7702 7703以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7704 7705| 错误码ID | 错误信息 | 7706| -------- | ---------------------------------------- | 7707| 6600101 | Session service exception. | 7708| 6600102 | The session does not exist. | 7709| 6600103 | The session controller does not exist. | 7710 7711**示例:** 7712 7713```ts 7714import { BusinessError } from '@kit.BasicServicesKit'; 7715 7716avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => { 7717 if (err) { 7718 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 7719 } else { 7720 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 7721 } 7722}); 7723``` 7724 7725### getAVQueueTitleSync<sup>10+</sup> 7726 7727getAVQueueTitleSync(): string 7728 7729使用同步方法获取当前会话播放列表的名称。 7730 7731**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7732 7733**系统能力:** SystemCapability.Multimedia.AVSession.Core 7734 7735**返回值:** 7736 7737| 类型 | 说明 | 7738| ---------------- | ----------------------------- | 7739| string | 当前会话播放列表名称。 | 7740 7741**错误码:** 7742 7743以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7744 7745| 错误码ID | 错误信息 | 7746| -------- | ---------------------------------------- | 7747| 6600101 | Session service exception. | 7748| 6600102 | The session does not exist. | 7749| 6600103 | The session controller does not exist. | 7750 7751**示例:** 7752 7753```ts 7754import { BusinessError } from '@kit.BasicServicesKit'; 7755 7756try { 7757 let currentQueueTitle: string = avsessionController.getAVQueueTitleSync(); 7758} catch (err) { 7759 let error = err as BusinessError; 7760 console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`); 7761} 7762``` 7763 7764### getAVQueueItemsSync<sup>10+</sup> 7765 7766getAVQueueItemsSync(): Array\<AVQueueItem\> 7767 7768使用同步方法获取当前会话播放列表相关信息。 7769 7770**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7771 7772**系统能力:** SystemCapability.Multimedia.AVSession.Core 7773 7774**返回值:** 7775 7776| 类型 | 说明 | 7777| --------------------------------------------- | ----------------------------- | 7778| Array<[AVQueueItem](#avqueueitem10)\> | 当前会话播放列表队列。 | 7779 7780**错误码:** 7781 7782以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7783 7784| 错误码ID | 错误信息 | 7785| -------- | ---------------------------------------- | 7786| 6600101 | Session service exception. | 7787| 6600102 | The session does not exist. | 7788| 6600103 | The session controller does not exist. | 7789 7790**示例:** 7791 7792```ts 7793import { BusinessError } from '@kit.BasicServicesKit'; 7794 7795try { 7796 let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync(); 7797} catch (err) { 7798 let error = err as BusinessError; 7799 console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`); 7800} 7801``` 7802 7803### getOutputDeviceSync<sup>10+</sup> 7804 7805getOutputDeviceSync(): OutputDeviceInfo 7806 7807使用同步方法获取当前输出设备信息。 7808 7809**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7810 7811**系统能力:** SystemCapability.Multimedia.AVSession.Core 7812 7813**返回值:** 7814 7815| 类型 | 说明 | 7816| ----------------------------------------------- | --------------------------------- | 7817| [OutputDeviceInfo](#outputdeviceinfo10) | 当前输出设备信息。 | 7818 7819**错误码:** 7820 7821以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7822 7823| 错误码ID | 错误信息 | 7824| -------- | ---------------------------------------- | 7825| 6600101 | Session service exception. | 7826| 6600103 | The session controller does not exist. | 7827 7828**示例:** 7829 7830```ts 7831import { BusinessError } from '@kit.BasicServicesKit'; 7832 7833try { 7834 let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync(); 7835} catch (err) { 7836 let error = err as BusinessError; 7837 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 7838} 7839``` 7840 7841### isActiveSync<sup>10+</sup> 7842 7843isActiveSync(): boolean 7844 7845使用同步方法判断会话是否被激活。 7846 7847**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7848 7849**系统能力:** SystemCapability.Multimedia.AVSession.Core 7850 7851**返回值:** 7852 7853| 类型 | 说明 | 7854| ----------------- | ------------------------------------------------------------ | 7855| boolean | 会话是否为激活状态,true表示被激活,false表示禁用。 | 7856 7857**错误码:** 7858 7859以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7860 7861| 错误码ID | 错误信息 | 7862| -------- | ---------------------------------------- | 7863| 6600101 | Session service exception. | 7864| 6600102 | The session does not exist. | 7865| 6600103 | The session controller does not exist. | 7866 7867**示例:** 7868 7869```ts 7870import { BusinessError } from '@kit.BasicServicesKit'; 7871 7872try { 7873 let isActive: boolean = avsessionController.isActiveSync(); 7874} catch (err) { 7875 let error = err as BusinessError; 7876 console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`); 7877} 7878``` 7879 7880### getValidCommandsSync<sup>10+</sup> 7881 7882getValidCommandsSync(): Array\<AVControlCommandType\> 7883 7884使用同步方法获取会话支持的有效命令。 7885 7886**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7887 7888**系统能力:** SystemCapability.Multimedia.AVSession.Core 7889 7890**返回值:** 7891 7892| 类型 | 说明 | 7893| ------------------------------------------------------------ | --------------------------------- | 7894| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | 会话支持的有效命令的集合。 | 7895 7896**错误码:** 7897 7898以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。 7899 7900| 错误码ID | 错误信息 | 7901| -------- | ---------------------------------------- | 7902| 6600101 | Session service exception. | 7903| 6600102 | The session does not exist. | 7904| 6600103 | The session controller does not exist. | 7905 7906**示例:** 7907 7908```ts 7909import { BusinessError } from '@kit.BasicServicesKit'; 7910 7911try { 7912 let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync(); 7913} catch (err) { 7914 let error = err as BusinessError; 7915 console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`); 7916} 7917``` 7918 7919## AVControlCommandType<sup>10+</sup> 7920 7921type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 7922 'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'answer' | 'hangUp' | 'toggleCallMute' 7923 7924会话可传递的命令。 7925 7926该类型可取的值为下表字符串的并集。 7927 7928**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7929 7930**系统能力:** SystemCapability.Multimedia.AVSession.Core 7931 7932| 类型 | 说明 | 7933| ---------------- | ------------ | 7934| 'play' | 播放 | 7935| 'pause' | 暂停 | 7936| 'stop' | 停止 | 7937| 'playNext' | 下一首 | 7938| 'playPrevious' | 上一首 | 7939| 'fastForward' | 快进 | 7940| 'rewind' | 快退 | 7941| 'seek' | 跳转某一节点 | 7942| 'setSpeed' | 设置播放倍速 | 7943| 'setLoopMode' | 设置循环模式 | 7944| 'toggleFavorite' | 是否收藏 | 7945| 'playFromAssetId'| 播放指定的assetid | 7946|'answer' | 接听 | 7947| 'hangUp' | 挂断 | 7948|'toggleCallMute' | 设置通话静音状态 | 7949 7950## AVControlCommand<sup>10+</sup> 7951 7952会话接受的命令的对象描述。 7953 7954**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 7955 7956**系统能力:** SystemCapability.Multimedia.AVSession.Core 7957 7958| 名称 | 类型 | 必填 | 说明 | 7959| --------- | ------------------------------------------------- | ---- | -------------- | 7960| command | [AVControlCommandType](#avcontrolcommandtype10) | 是 | 命令 | 7961| parameter | [LoopMode](#loopmode10) | string | number | 否 | 命令对应的参数 | 7962 7963## AVSessionErrorCode<sup>10+</sup> 7964 7965会话发生错误时的错误码。 7966 7967| 名称 | 值 | 说明 | 7968| -------------------------------------- | ------- | ------------------------------- | 7969| ERR_CODE_SERVICE_EXCEPTION | 6600101 | 会话服务端异常。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core| 7970| ERR_CODE_SESSION_NOT_EXIST | 6600102 | 会话不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 7971| ERR_CODE_CONTROLLER_NOT_EXIST | 6600103 | 会话控制器不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 7972| ERR_CODE_REMOTE_CONNECTION_ERR | 6600104 | 远端会话连接失败。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core| 7973| ERR_CODE_COMMAND_INVALID | 6600105 | 无效会话命令。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core| 7974| ERR_CODE_SESSION_INACTIVE | 6600106 | 会话未激活。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 7975| ERR_CODE_MESSAGE_OVERLOAD | 6600107 | 命令&消息过载。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 7976| ERR_CODE_DEVICE_CONNECTION_FAILED | 6600108 | 设备连接失败。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 7977| ERR_CODE_REMOTE_CONNECTION_NOT_EXIST | 6600109 | 远端会话不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core | 7978| ERR_CODE_CAST_CONTROL_UNSPECIFIED | 6611000 | 未被定义的投播错误码。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7979| ERR_CODE_CAST_CONTROL_REMOTE_ERROR | 6611001 | 远端播放器中发生不明错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7980| ERR_CODE_CAST_CONTROL_BEHIND_LIVE_WINDOW | 6611002 | 播放出现延迟。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7981| ERR_CODE_CAST_CONTROL_TIMEOUT | 6611003 | 投播控制进程超时。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7982| ERR_CODE_CAST_CONTROL_RUNTIME_CHECK_FAILED | 6611004 | 运行时检查失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7983| ERR_CODE_CAST_CONTROL_PLAYER_NOT_WORKING | 6611100 | 跨设备数据传输被锁定。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7984| ERR_CODE_CAST_CONTROL_SEEK_MODE_UNSUPPORTED | 6611101 | 不支持指定的查找模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7985| ERR_CODE_CAST_CONTROL_ILLEGAL_SEEK_TARGET | 6611102 | 要搜索的位置超出媒体的范围,或者不支持当前搜索模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7986| ERR_CODE_CAST_CONTROL_PLAY_MODE_UNSUPPORTED | 6611103 | 不支持指定的播放模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7987| ERR_CODE_CAST_CONTROL_PLAY_SPEED_UNSUPPORTED | 6611104 | 不支持指定的播放速度。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7988| ERR_CODE_CAST_CONTROL_DEVICE_MISSING | 6611105 | 操作失败,因为媒体源设备或媒体接收器设备已被销毁。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7989| ERR_CODE_CAST_CONTROL_INVALID_PARAM | 6611106 | 该参数无效。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7990| ERR_CODE_CAST_CONTROL_NO_MEMORY | 6611107 | 内存分配失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7991| ERR_CODE_CAST_CONTROL_OPERATION_NOT_ALLOWED | 6611108 | 不被允许的操作。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7992| ERR_CODE_CAST_CONTROL_IO_UNSPECIFIED | 6612000 | 未指定的输入/输出错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7993| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_FAILED | 6612001 | 网络连接失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7994| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_TIMEOUT | 6612002 | 网络连接超时。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7995| ERR_CODE_CAST_CONTROL_IO_INVALID_HTTP_CONTENT_TYPE | 6612003 | 无效的"Content-Type"。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7996| ERR_CODE_CAST_CONTROL_IO_BAD_HTTP_STATUS | 6612004 | HTTP服务器返回一个意外的HTTP响应状态码。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7997| ERR_CODE_CAST_CONTROL_IO_FILE_NOT_FOUND | 6612005 | 文件不存在。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7998| ERR_CODE_CAST_CONTROL_IO_NO_PERMISSION | 6612006 | 不允许执行输入/输出的IO操作。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 7999| ERR_CODE_CAST_CONTROL_IO_CLEARTEXT_NOT_PERMITTED | 6612007 | 应用的网络安全配置不允许访问明文HTTP流量。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8000| ERR_CODE_CAST_CONTROL_IO_READ_POSITION_OUT_OF_RANGE | 6612008 | 从数据绑定中读取数据。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8001| ERR_CODE_CAST_CONTROL_IO_NO_CONTENTS | 6612100 | 媒体中没有可播放的内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8002| ERR_CODE_CAST_CONTROL_IO_READ_ERROR | 6612101 | 媒体无法读取。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8003| ERR_CODE_CAST_CONTROL_IO_CONTENT_BUSY | 6612102 | 该资源正在使用中。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8004| ERR_CODE_CAST_CONTROL_IO_CONTENT_EXPIRED | 6612103 | 输入/输出的IO请求内容已过期。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8005| ERR_CODE_CAST_CONTROL_IO_USE_FORBIDDEN | 6612104 | 不允许播放请求内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8006| ERR_CODE_CAST_CONTROL_IO_NOT_VERIFIED | 6612105 | 无法验证所允许的内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8007| ERR_CODE_CAST_CONTROL_IO_EXHAUSTED_ALLOWED_USES | 6612106 | 此内容已达到允许的最大使用次数。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8008| ERR_CODE_CAST_CONTROL_IO_NETWORK_PACKET_SENDING_FAILED | 6612107 | 从源设备发送数据包到接收设备时出现错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8009| ERR_CODE_CAST_CONTROL_PARSING_UNSPECIFIED | 6613000 | 未指定的内容解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8010| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_MALFORMED | 6613001 | 媒体容器比特流的格式解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8011| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_MALFORMED | 6613002 | 媒体清单解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8012| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_UNSUPPORTED | 6613003 | 文件的媒体容器格式/媒体容器特性不被支持。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8013| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_UNSUPPORTED | 6613004 | 媒体清单中不支持的特性。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8014| ERR_CODE_CAST_CONTROL_DECODING_UNSPECIFIED | 6614000 | 未指定的解码错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8015| ERR_CODE_CAST_CONTROL_DECODING_INIT_FAILED | 6614001 | 解码器初始化失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8016| ERR_CODE_CAST_CONTROL_DECODING_QUERY_FAILED | 6614002 | 解码器查询失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8017| ERR_CODE_CAST_CONTROL_DECODING_FAILED | 6614003 | 媒体样本解码失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8018| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_EXCEEDS_CAPABILITIES | 6614004 | 设备的能力无法解码当前格式。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8019| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_UNSUPPORTED | 6614005 | 不支持的解码格式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8020| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_UNSPECIFIED | 6615000 | 未指定的音频渲染器错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8021| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_INIT_FAILED | 6615001 | 音频渲染器初始化失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8022| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_WRITE_FAILED | 6615002 | 音频渲染器写入数据失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8023| ERR_CODE_CAST_CONTROL_DRM_UNSPECIFIED | 6616000 | 未指定的DRM相关错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8024| ERR_CODE_CAST_CONTROL_DRM_SCHEME_UNSUPPORTED | 6616001 | 设备不支持所选择的DRM保护方案。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8025| ERR_CODE_CAST_CONTROL_DRM_PROVISIONING_FAILED | 6616002 | 设备配置失败。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8026| ERR_CODE_CAST_CONTROL_DRM_CONTENT_ERROR | 6616003 | 受DRM保护的内容无法播放。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8027| ERR_CODE_CAST_CONTROL_DRM_LICENSE_ACQUISITION_FAILED | 6616004 | 获取许可证失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8028| ERR_CODE_CAST_CONTROL_DRM_DISALLOWED_OPERATION | 6616005 | 许可证策略不允许该操作。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8029| ERR_CODE_CAST_CONTROL_DRM_SYSTEM_ERROR | 6616006 | DRM系统中发生错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8030| ERR_CODE_CAST_CONTROL_DRM_DEVICE_REVOKED | 6616007 | 设备已撤销DRM权限。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8031| ERR_CODE_CAST_CONTROL_DRM_LICENSE_EXPIRED | 6616008 | 加载中的DRM许可证已过期。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8032| ERR_CODE_CAST_CONTROL_DRM_PROVIDE_KEY_RESPONSE_ERROR | 6616100 | DRM处理密钥响应时发生错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast| 8033 8034## SkipIntervals<sup>11+</sup> 8035 8036表示session支持的快进快退时间间隔的枚举。 8037 8038**系统能力:** SystemCapability.Multimedia.AVSession.Core 8039 8040| 名称 | 值 | 说明 | 8041| ---------------------- | -- | ----------------------- | 8042| SECONDS_10 | 10 | 时间为10秒。 | 8043| SECONDS_15 | 15 | 时间为15秒。 | 8044| SECONDS_30 | 30 | 时间为30秒。 | 8045