1/* 2* Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15 16import type { ErrorCallback, AsyncCallback, Callback } from './@ohos.base'; 17import { WantAgent } from './@ohos.wantAgent'; 18import { KeyEvent } from './@ohos.multimodalInput.keyEvent'; 19import { ElementName } from './bundleManager/ElementName'; 20import image from './@ohos.multimedia.image'; 21import audio from './@ohos.multimedia.audio'; 22import type media from './@ohos.multimedia.media'; 23import type Context from './application/BaseContext'; 24 25/** 26 * @namespace avSession 27 * @syscap SystemCapability.Multimedia.AVSession.Core 28 * @since 9 29 */ 30declare namespace avSession { 31 /** 32 * Create an AVSession instance. An ability can only create one AVSession 33 * @param { Context } context - The context of application 34 * @param { string } tag - A user-defined name for this session 35 * @param { AVSessionType } type - The type of session {@link AVSessionType} 36 * @param { AsyncCallback<AVSession> } callback - async callback for AVSession. 37 * @throws { BusinessError } 401 - parameter check failed 38 * @throws { BusinessError } 6600101 - Session service exception. 39 * @syscap SystemCapability.Multimedia.AVSession.Core 40 * @since 10 41 */ 42 function createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback<AVSession>): void; 43 44 /** 45 * Create an AVSession instance. An ability can only create one AVSession 46 * @param { Context } context - The context of application 47 * @param { string } tag - A user-defined name for this session 48 * @param { AVSessionType } type - The type of session {@link AVSessionType} 49 * @returns { Promise<AVSession> } Promise for AVSession 50 * @throws { BusinessError } 401 - parameter check failed 51 * @throws { BusinessError } 6600101 - Session service exception. 52 * @syscap SystemCapability.Multimedia.AVSession.Core 53 * @since 10 54 */ 55 function createAVSession(context: Context, tag: string, type: AVSessionType): Promise<AVSession>; 56 57 /** 58 * Get all avsession descriptors of the system 59 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 60 * @param { AsyncCallback<Array<Readonly<AVSessionDescriptor>>> } callback - async callback for an array of AVSessionDescriptors. 61 * @throws { BusinessError } 201 - permission denied 62 * @throws { BusinessError } 6600101 - Session service exception. 63 * @syscap SystemCapability.Multimedia.AVSession.Manager 64 * @systemapi 65 * @since 9 66 */ 67 function getAllSessionDescriptors(callback: AsyncCallback<Array<Readonly<AVSessionDescriptor>>>): void; 68 69 /** 70 * Get all avsession descriptors of the system 71 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 72 * @returns { Promise<Array<Readonly<AVSessionDescriptor>>> } Promise for an array of AVSessionDescriptors 73 * @throws { BusinessError } 201 - permission denied 74 * @throws { BusinessError } 6600101 - Session service exception. 75 * @syscap SystemCapability.Multimedia.AVSession.Manager 76 * @systemapi 77 * @since 9 78 */ 79 function getAllSessionDescriptors(): Promise<Array<Readonly<AVSessionDescriptor>>>; 80 81 /** 82 * Get history avsession records. These sessions have been destroyed. 83 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 84 * @param { number } maxSize - Specifies the maximum size of the returned value array. 85 * @param { AsyncCallback<Array<Readonly<AVSessionDescriptor>>> } callback - async callback for an array of AVSessionDescriptors. 86 * If provided '0' or not provided, the maximum value is determined by the system. 87 * @throws { BusinessError } 401 - parameter check failed 88 * @throws { BusinessError } 6600101 - Session service exception. 89 * @syscap SystemCapability.Multimedia.AVSession.Manager 90 * @systemapi Hide this for inner system use 91 * @since 10 92 */ 93 function getHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback<Array<Readonly<AVSessionDescriptor>>>): void; 94 95 /** 96 * Get history avsession records. These sessions have been destroyed. 97 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 98 * @param { number } maxSize - Specifies the maximum size of the returned value array. 99 * If provided '0' or not provided, the maximum value is determined by the system. 100 * @returns { Promise<Array<Readonly<AVSessionDescriptor>>> } Promise for an array of AVSessionDescriptors 101 * @throws { BusinessError } 401 - parameter check failed 102 * @throws { BusinessError } 6600101 - Session service exception. 103 * @syscap SystemCapability.Multimedia.AVSession.Manager 104 * @systemapi Hide this for inner system use 105 * @since 10 106 */ 107 function getHistoricalSessionDescriptors(maxSize?: number): Promise<Array<Readonly<AVSessionDescriptor>>>; 108 109 /** 110 * Create an avsession controller 111 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 112 * @param { string } sessionId - Specifies the sessionId to create the controller. 113 * @param { AsyncCallback<AVSessionController> } callback - async callback for AVSessionController. 114 * If provided 'default', the system will create a default controller, Used to control the system default session 115 * @throws { BusinessError } 201 - permission denied 116 * @throws { BusinessError } 401 - parameter check failed 117 * @throws { BusinessError } 6600101 - Session service exception. 118 * @throws { BusinessError } 6600102 - The session does not exist. 119 * @syscap SystemCapability.Multimedia.AVSession.Manager 120 * @systemapi 121 * @since 9 122 */ 123 function createController(sessionId: string, callback: AsyncCallback<AVSessionController>): void; 124 125 /** 126 * Create an avsession controller 127 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 128 * @param { string } sessionId - Specifies the sessionId to create the controller. 129 * If provided 'default', the system will create a default controller, Used to control the system default session 130 * @returns { Promise<AVSessionController> } Promise for AVSessionController 131 * @throws { BusinessError } 201 - permission denied 132 * @throws { BusinessError } 401 - parameter check failed 133 * @throws { BusinessError } 6600101 - Session service exception. 134 * @throws { BusinessError } 6600102 - The session does not exist. 135 * @syscap SystemCapability.Multimedia.AVSession.Manager 136 * @systemapi 137 * @since 9 138 */ 139 function createController(sessionId: string): Promise<AVSessionController>; 140 141 /** 142 * Cast Audio to the remote devices or cast back local device 143 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 144 * @param { SessionToken | 'all' } session - Specifies the sessionId which to send to remote. 145 * @param { Array<audio.AudioDeviceDescriptor> } audioDevices - Specifies the audio devices to cast. 146 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 147 * 'all' means cast all the media audio of this device to remote. 148 * @throws { BusinessError } 201 - permission denied 149 * @throws { BusinessError } 401 - parameter check failed 150 * @throws { BusinessError } 6600101 - Session service exception. 151 * @throws { BusinessError } 6600102 - The session does not exist. 152 * @throws { BusinessError } 6600104 - The remote session connection failed. 153 * @syscap SystemCapability.Multimedia.AVSession.Manager 154 * @systemapi 155 * @since 9 156 */ 157 function castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>, callback: AsyncCallback<void>): void; 158 159 /** 160 * Cast Audio to the remote devices or cast back local device 161 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 162 * @param { SessionToken | 'all' } session - Specifies the sessionId which to send to remote. 163 * @param { Array<audio.AudioDeviceDescriptor> } audioDevices - Specifies the audio devices to cast. 164 * @returns { Promise<void> } void promise when executed successfully 165 * 'all' means cast all the media audio of this device to remote. 166 * @throws { BusinessError } 201 - permission denied 167 * @throws { BusinessError } 401 - parameter check failed 168 * @throws { BusinessError } 6600101 - Session service exception. 169 * @throws { BusinessError } 6600102 - The session does not exist. 170 * @throws { BusinessError } 6600104 - The remote session connection failed. 171 * @syscap SystemCapability.Multimedia.AVSession.Manager 172 * @systemapi 173 * @since 9 174 */ 175 function castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>): Promise<void>; 176 177 /** 178 * Session token. Used to judge the legitimacy of the session. 179 * @typedef SessionToken 180 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 181 * @syscap SystemCapability.Multimedia.AVSession.Manager 182 * @systemapi 183 * @since 9 184 */ 185 interface SessionToken { 186 /** 187 * The unique session id of the avsession object 188 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 189 * @type { string } 190 * @syscap SystemCapability.Multimedia.AVSession.Manager 191 * @systemapi 192 * @since 9 193 */ 194 sessionId: string; 195 196 /** 197 * Process id of session 198 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 199 * @type { ?number } 200 * @syscap SystemCapability.Multimedia.AVSession.Manager 201 * @systemapi 202 * @since 9 203 */ 204 pid?: number; 205 206 /** 207 * User id 208 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 209 * @type { ?number } 210 * @syscap SystemCapability.Multimedia.AVSession.Manager 211 * @systemapi 212 * @since 9 213 */ 214 uid?: number; 215 } 216 217 /** 218 * Register session create callback 219 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 220 * @param { 'sessionCreate' } type - Registration Type, 'sessionCreate' 221 * @param { function } callback - Used to handle ('sessionCreate' command) 222 * @throws { BusinessError } 201 - permission denied 223 * @throws { BusinessError } 401 - parameter check failed 224 * @throws { BusinessError } 6600101 - Session service exception. 225 * @syscap SystemCapability.Multimedia.AVSession.Manager 226 * @systemapi 227 * @since 9 228 */ 229 function on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): void; 230 231 /** 232 * Register session destroy callback 233 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 234 * @param { 'sessionDestroy' } type - Registration Type, 'sessionDestroy' 235 * @param { function } callback - Used to handle ('sessionDestroy' command) 236 * @throws { BusinessError } 201 - permission denied 237 * @throws { BusinessError } 401 - parameter check failed 238 * @throws { BusinessError } 6600101 - Session service exception. 239 * @syscap SystemCapability.Multimedia.AVSession.Manager 240 * @systemapi 241 * @since 9 242 */ 243 function on(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): void; 244 245 /** 246 * Register top session changed callback 247 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 248 * @param { 'topSessionChange' } type - Registration Type, top priority session change, 'topSessionChange' 249 * @param { function } callback - Used to handle ('topSessionChange' command) 250 * @throws { BusinessError } 201 - permission denied 251 * @throws { BusinessError } 401 - parameter check failed 252 * @throws { BusinessError } 6600101 - Session service exception. 253 * @syscap SystemCapability.Multimedia.AVSession.Manager 254 * @systemapi 255 * @since 9 256 */ 257 function on(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void; 258 259 /** 260 * Unregister session create callback 261 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 262 * @param { 'sessionCreate' } type - Registration Type, session creation, 'sessionCreate' 263 * @param { function } callback - Used to unregister listener for ('sessionCreate') command 264 * @throws { BusinessError } 201 - permission denied 265 * @throws { BusinessError } 401 - parameter check failed 266 * @throws { BusinessError } 6600101 - Session service exception. 267 * @syscap SystemCapability.Multimedia.AVSession.Manager 268 * @systemapi 269 * @since 9 270 */ 271 function off(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): void; 272 273 /** 274 * Unregister session destroy callback 275 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 276 * @param { 'sessionDestroy' } type - Registration Type, session deletion, 'sessionDestroy' 277 * @param { function } callback - Used to unregister listener for ('sessionDestroy') command 278 * @throws { BusinessError } 201 - permission denied 279 * @throws { BusinessError } 401 - parameter check failed 280 * @throws { BusinessError } 6600101 - Session service exception. 281 * @syscap SystemCapability.Multimedia.AVSession.Manager 282 * @systemapi 283 * @since 9 284 */ 285 function off(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void): void; 286 287 /** 288 * Unregister top session changed callback 289 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 290 * @param { 'topSessionChange' } type - Registration Type, top priority session change, 'topSessionChange' 291 * @param { function } callback - Used to unregister listener for ('topSessionChange') command 292 * @throws { BusinessError } 201 - permission denied 293 * @throws { BusinessError } 401 - parameter check failed 294 * @throws { BusinessError } 6600101 - Session service exception. 295 * @syscap SystemCapability.Multimedia.AVSession.Manager 296 * @systemapi 297 * @since 9 298 */ 299 function off(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void; 300 301 /** 302 * Register Session service death callback, notifying the application to clean up resources. 303 * @param { 'sessionServiceDie' } type - Registration Type, 'sessionServiceDie' 304 * @param { function } callback - Used to handle ('sessionServiceDie') command. 305 * @throws { BusinessError } 201 - permission denied 306 * @throws { BusinessError } 401 - parameter check failed 307 * @throws { BusinessError } 6600101 - Session service exception. 308 * @syscap SystemCapability.Multimedia.AVSession.Core 309 * @systemapi 310 * @since 9 311 */ 312 function on(type: 'sessionServiceDie', callback: () => void): void; 313 314 /** 315 * Unregister Session service death callback, notifying the application to clean up resources. 316 * @param { 'sessionServiceDie' } type - Registration Type, 'sessionServiceDie' 317 * @param { function } callback - Used to unregister listener for ('sessionServiceDie') command. 318 * @throws { BusinessError } 201 - permission denied 319 * @throws { BusinessError } 401 - parameter check failed 320 * @throws { BusinessError } 6600101 - Session service exception. 321 * @syscap SystemCapability.Multimedia.AVSession.Core 322 * @systemapi 323 * @since 9 324 */ 325 function off(type: 'sessionServiceDie', callback?: () => void): void; 326 327 /** 328 * Send system media key event.The system automatically selects the recipient. 329 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 330 * @param { KeyEvent } event - The key event to be sent 331 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 332 * @throws { BusinessError } 201 - permission denied 333 * @throws { BusinessError } 401 - parameter check failed 334 * @throws { BusinessError } 6600101 - Session service exception. 335 * @throws { BusinessError } 6600105 - Invalid session command. 336 * @syscap SystemCapability.Multimedia.AVSession.Manager 337 * @systemapi 338 * @since 9 339 */ 340 function sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback<void>): void; 341 342 /** 343 * Send system media key event.The system automatically selects the recipient. 344 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 345 * @param { KeyEvent } event - The key event to be sent 346 * @returns { Promise<void> } void promise when executed successfully 347 * @throws { BusinessError } 201 - permission denied 348 * @throws { BusinessError } 401 - parameter check failed 349 * @throws { BusinessError } 6600101 - Session service exception. 350 * @throws { BusinessError } 6600105 - Invalid session command. 351 * @syscap SystemCapability.Multimedia.AVSession.Manager 352 * @systemapi 353 * @since 9 354 */ 355 function sendSystemAVKeyEvent(event: KeyEvent): Promise<void>; 356 357 /** 358 * Send system control command.The system automatically selects the recipient. 359 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 360 * @param { AVControlCommand } command - The command to be sent. See {@link AVControlCommand} 361 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 362 * @throws { BusinessError } 201 - permission denied 363 * @throws { BusinessError } 401 - parameter check failed 364 * @throws { BusinessError } 6600101 - Session service exception. 365 * @throws { BusinessError } 6600105 - Invalid session command. 366 * @throws { BusinessError } 6600107 - Too many commands or events. 367 * @syscap SystemCapability.Multimedia.AVSession.Manager 368 * @systemapi 369 * @since 9 370 */ 371 function sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback<void>): void; 372 373 /** 374 * Send system control command.The system automatically selects the recipient. 375 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 376 * @param { AVControlCommand } command - The command to be sent. See {@link AVControlCommand} 377 * @returns { Promise<void> } void promise when executed successfully 378 * @throws { BusinessError } 201 - permission denied 379 * @throws { BusinessError } 401 - parameter check failed 380 * @throws { BusinessError } 6600101 - Session service exception. 381 * @throws { BusinessError } 6600105 - Invalid session command. 382 * @throws { BusinessError } 6600107 - Too many commands or events. 383 * @syscap SystemCapability.Multimedia.AVSession.Manager 384 * @systemapi 385 * @since 9 386 */ 387 function sendSystemControlCommand(command: AVControlCommand): Promise<void>; 388 389 /** 390 * Define different protocol capability 391 * @enum { number } 392 * @syscap SystemCapability.Multimedia.AVSession.AVCast 393 * @systemapi 394 * @since 10 395 */ 396 enum ProtocolType { 397 /** 398 * The default cast type "local", media can be routed on the same device, 399 * including internal speakers or audio jack on the device itself, A2DP devices. 400 * @syscap SystemCapability.Multimedia.AVSession.AVCast 401 * @systemapi 402 * @since 10 403 */ 404 TYPE_LOCAL = 0, 405 406 /** 407 * Cast+ mirror capability 408 * @syscap SystemCapability.Multimedia.AVSession.AVCast 409 * @systemapi 410 * @since 10 411 */ 412 TYPE_CAST_PLUS_MIRROR = 1, 413 414 /** 415 * The Cast+ Stream indicating the media is presenting on a different device 416 * the application need get an AVCastController to control remote playback. 417 * @syscap SystemCapability.Multimedia.AVSession.AVCast 418 * @systemapi 419 * @since 10 420 */ 421 TYPE_CAST_PLUS_STREAM = 2, 422 } 423 424 /** 425 * Start device discovery. 426 * @param { AsyncCallback<void> } callback a callback function 427 * @syscap SystemCapability.Multimedia.AVSession.AVCast 428 * @systemapi 429 * @since 10 430 */ 431 function startCastDeviceDiscovery(callback: AsyncCallback<void>): void; 432 433 /** 434 * Start device discovery. 435 * @param { number } filter device filter when discovering, can be an union of {@link ProtocolType} 436 * @param { AsyncCallback<void> } callback a callback function 437 * @throws { BusinessError } 401 - parameter check failed 438 * @syscap SystemCapability.Multimedia.AVSession.AVCast 439 * @systemapi 440 * @since 10 441 */ 442 function startCastDeviceDiscovery(filter: number, callback: AsyncCallback<void>): void; 443 444 /** 445 * Start device discovery. 446 * @param { number } filter device filter when discovering, can be an union of {@link ProtocolType} 447 * @returns { Promise<void> } Promise for the result 448 * @throws { BusinessError } 401 - parameter check failed 449 * @syscap SystemCapability.Multimedia.AVSession.AVCast 450 * @systemapi 451 * @since 10 452 */ 453 function startCastDeviceDiscovery(filter?: number): Promise<void>; 454 455 /** 456 * Stop device discovery. 457 * @param { AsyncCallback<void> } callback a callback function 458 * @syscap SystemCapability.Multimedia.AVSession.AVCast 459 * @systemapi 460 * @since 10 461 */ 462 function stopCastDeviceDiscovery(callback: AsyncCallback<void>): void; 463 464 /** 465 * Stop device discovery. 466 * @returns { Promise<void> } Promise for the result 467 * @syscap SystemCapability.Multimedia.AVSession.AVCast 468 * @systemapi 469 * @since 10 470 */ 471 function stopCastDeviceDiscovery(): Promise<void>; 472 473 /** 474 * Enable or disable device to be discoverable, used at sink side. 475 * @param { boolean } enable true: can be discoverable, false: cannot be discoverable. 476 * @param { AsyncCallback<void> } callback a callback function 477 * @throws { BusinessError } 401 - parameter check failed 478 * @syscap SystemCapability.Multimedia.AVSession.AVCast 479 * @systemapi 480 * @since 10 481 */ 482 function setDiscoverable(enable: boolean, callback: AsyncCallback<void>): void; 483 484 /** 485 * Enable or disable device to be discoverable, used at sink side. 486 * @param { boolean } enable true: can be discoverable, false: cannot be discoverable. 487 * @returns { Promise<void> } Promise for the result 488 * @throws { BusinessError } 401 - parameter check failed 489 * @syscap SystemCapability.Multimedia.AVSession.AVCast 490 * @systemapi 491 * @since 10 492 */ 493 function setDiscoverable(enable: boolean): Promise<void>; 494 495 /** 496 * Register device discovery callback 497 * @param { 'deviceAvailable' } type Registration Type 498 * @param { function } callback Used to returns the device info 499 * @throws {BusinessError} 201 - permission denied 500 * @throws {BusinessError} 401 - parameter check failed 501 * @syscap SystemCapability.Multimedia.AVSession.AVCast 502 * @systemapi 503 * @since 10 504 */ 505 function on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void; 506 507 /** 508 * Unregister device discovery callback 509 * @param { 'deviceAvailable' } type Registration Type 510 * @param { function } callback Used to returns the device info 511 * @throws {BusinessError} 201 - permission denied 512 * @throws {BusinessError} 401 - parameter check failed 513 * @syscap SystemCapability.Multimedia.AVSession.AVCast 514 * @systemapi 515 * @since 10 516 */ 517 function off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void; 518 519 /** 520 * Register a callback to retrieve an avsession cast controller. 521 * This function can be used at both side to get the same controller to do the playback control. 522 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 523 * @param { string } sessionId Specifies the sessionId to get controller. 524 * @param { AsyncCallback<AVCastController> } callback - async callback for the AVCastController. 525 * @throws {BusinessError} 201 - permission denied 526 * @throws { BusinessError } 401 - parameter check failed 527 * @throws {BusinessError} 6600101 - Session service exception 528 * @throws {BusinessError} 6600102 - session does not exist 529 * @syscap SystemCapability.Multimedia.AVSession.AVCast 530 * @systemapi 531 * @since 10 532 */ 533 function getAVCastController(sessionId: string, callback: AsyncCallback<AVCastController>): void; 534 535 /** 536 * Get the current session's remote controller client. 537 * If the avsession is not under casting state, the controller will return null. 538 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 539 * @param { string } sessionId Specifies the sessionId to get controller. 540 * @returns { Promise<AVCastController> } Promise for the AVCastController 541 * @throws {BusinessError} 201 - permission denied 542 * @throws { BusinessError } 401 - parameter check failed 543 * @throws {BusinessError} 6600101 - server exception 544 * @throws {BusinessError} 6600102 - session does not exist 545 * @syscap SystemCapability.Multimedia.AVSession.AVCast 546 * @systemapi 547 * @since 10 548 */ 549 function getAVCastController(sessionId: string): Promise<AVCastController>; 550 551 /** 552 * Cast resource to remote device. 553 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 554 * @param { SessionToken } session Specifies the sessionId which is to be casted. 555 * @param { OutputDeviceInfo } device Specifies the device to cast. 556 * @param { AsyncCallback<void> } callback A callback instance used to return when start casting. 557 * @throws {BusinessError} 201 - permission denied 558 * @throws {BusinessError} 401 - parameter check failed 559 * @throws {BusinessError} 6600101 - Session service exception 560 * @throws {BusinessError} 6600108 - Device connecting failed 561 * @syscap SystemCapability.Multimedia.AVSession.AVCast 562 * @systemapi 563 * @since 10 564 */ 565 function startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback<void>): void; 566 567 /** 568 * Cast resource to remote device. 569 * @permission ohos.permission.MANAGE_MEDIA_RESOURCES 570 * @param { SessionToken } session Specifies the sessionId which is to be casted. 571 * @param { OutputDeviceInfo } device Specifies the device to cast. 572 * @returns { Promise<void> } Promise for the result 573 * @throws {BusinessError} 201 - permission denied 574 * @throws {BusinessError} 401 - parameter check failed 575 * @throws {BusinessError} 6600101 - Session service exception 576 * @throws {BusinessError} 6600108 - Device connecting failed 577 * @syscap SystemCapability.Multimedia.AVSession.AVCast 578 * @systemapi 579 * @since 10 580 */ 581 function startCasting(session: SessionToken, device: OutputDeviceInfo): Promise<void>; 582 583 /** 584 * Stop current cast and disconnect device connection. 585 * @param { SessionToken } session Specifies the sessionId which is to be stopped. 586 * @param { AsyncCallback<void> } callback A callback instance used to return when cast stopped completed. 587 * @throws { BusinessError } 401 - parameter check failed 588 * @throws { BusinessError } 6600109 - The remote connection is not established 589 * @syscap SystemCapability.Multimedia.AVSession.AVCast 590 * @systemapi 591 * @since 10 592 */ 593 function stopCasting(session: SessionToken, callback: AsyncCallback<void>): void; 594 595 /** 596 * Stop current cast and disconnect device connection. 597 * @param { SessionToken } session Specifies the sessionId which is to be stopped. 598 * @returns { Promise<void> } Promise for the result 599 * @throws { BusinessError } 401 - parameter check failed 600 * @throws { BusinessError } 6600109 - The remote connection is not established 601 * @syscap SystemCapability.Multimedia.AVSession.AVCast 602 * @systemapi 603 * @since 10 604 */ 605 function stopCasting(session: SessionToken): Promise<void>; 606 607 /** 608 * session type. 609 * @syscap SystemCapability.Multimedia.AVSession.Core 610 * @since 10 611 */ 612 type AVSessionType = 'audio' | 'video'; 613 614 /** 615 * AVSession object. 616 * @interface AVSession 617 * @syscap SystemCapability.Multimedia.AVSession.Core 618 * @since 10 619 */ 620 interface AVSession { 621 /** 622 * unique session Id 623 * @syscap SystemCapability.Multimedia.AVSession.Core 624 * @since 10 625 */ 626 readonly sessionId: string; 627 628 /** 629 * Get current session type 630 * @syscap SystemCapability.Multimedia.AVSession.Core 631 * @since 10 632 */ 633 readonly sessionType: AVSessionType; 634 635 /** 636 * Set the metadata of this session. 637 * In addition to the required properties, users can fill in partially supported properties 638 * @param { AVMetadata } data {@link AVMetadata} 639 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 640 * @throws { BusinessError } 401 - parameter check failed 641 * @throws { BusinessError } 6600101 - Session service exception. 642 * @throws { BusinessError } 6600102 - The session does not exist. 643 * @syscap SystemCapability.Multimedia.AVSession.Core 644 * @since 10 645 */ 646 setAVMetadata(data: AVMetadata, callback: AsyncCallback<void>): void; 647 648 /** 649 * Set the metadata of this session. 650 * In addition to the required properties, users can fill in partially supported properties 651 * @param { AVMetadata } data {@link AVMetadata} 652 * @returns { Promise<void> } void promise when executed successfully 653 * @throws { BusinessError } 401 - parameter check failed 654 * @throws { BusinessError } 6600101 - Session service exception. 655 * @throws { BusinessError } 6600102 - The session does not exist. 656 * @syscap SystemCapability.Multimedia.AVSession.Core 657 * @since 10 658 */ 659 setAVMetadata(data: AVMetadata): Promise<void>; 660 661 /** 662 * Set the playback state of this session. 663 * @param { AVPlaybackState } state {@link AVPlaybackState} 664 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 665 * @throws { BusinessError } 401 - parameter check failed 666 * @throws { BusinessError } 6600101 - Session service exception. 667 * @throws { BusinessError } 6600102 - The session does not exist. 668 * @syscap SystemCapability.Multimedia.AVSession.Core 669 * @since 10 670 */ 671 setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback<void>): void; 672 673 /** 674 * Set the playback state of this session. 675 * @param { AVPlaybackState } state {@link AVPlaybackState} 676 * @returns { Promise<void> } void promise when executed successfully 677 * @throws { BusinessError } 401 - parameter check failed 678 * @throws { BusinessError } 6600101 - Session service exception. 679 * @throws { BusinessError } 6600102 - The session does not exist. 680 * @syscap SystemCapability.Multimedia.AVSession.Core 681 * @since 10 682 */ 683 setAVPlaybackState(state: AVPlaybackState): Promise<void>; 684 685 /** 686 * Set the ability to start the session corresponding to 687 * @param { WantAgent } ability - The WantAgent for launch the ability 688 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 689 * @throws { BusinessError } 401 - parameter check failed 690 * @throws { BusinessError } 6600101 - Session service exception. 691 * @throws { BusinessError } 6600102 - The session does not exist. 692 * @syscap SystemCapability.Multimedia.AVSession.Core 693 * @since 10 694 */ 695 setLaunchAbility(ability: WantAgent, callback: AsyncCallback<void>): void; 696 697 /** 698 * Set the ability to start the session corresponding to 699 * @param { WantAgent } ability - The WantAgent for launch the ability 700 * @returns { Promise<void> } void promise when executed successfully 701 * @throws { BusinessError } 401 - parameter check failed 702 * @throws { BusinessError } 6600101 - Session service exception. 703 * @throws { BusinessError } 6600102 - The session does not exist. 704 * @syscap SystemCapability.Multimedia.AVSession.Core 705 * @since 10 706 */ 707 setLaunchAbility(ability: WantAgent): Promise<void>; 708 709 /** 710 * Dispatch the session event of this session. 711 * @param { string } event - Session event name to dispatch 712 * @param { object } args - The parameters of session event 713 * @param { AsyncCallback<void>} callback - The asyncCallback triggered when the command is executed successfully 714 * @throws { BusinessError } 401 - parameter check failed 715 * @throws { BusinessError } 6600101 - Session service exception. 716 * @throws { BusinessError } 6600102 - The session does not exist. 717 * @syscap SystemCapability.Multimedia.AVSession.Core 718 * @since 10 719 */ 720 dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback<void>): void; 721 722 /** 723 * Dispatch the session event of this session. 724 * @param { string } event - Session event name to dispatch 725 * @param { object } args - The parameters of session event 726 * @returns { Promise<void> } void promise when executed successfully 727 * @throws { BusinessError } 401 - parameter check failed 728 * @throws { BusinessError } 6600101 - Session service exception. 729 * @throws { BusinessError } 6600102 - The session does not exist. 730 * @syscap SystemCapability.Multimedia.AVSession.Core 731 * @since 10 732 */ 733 dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise<void>; 734 735 /** 736 * Set the playlist of queueItem. Identifies the content of the playlist presented by this session. 737 * @param { Array<AVQueueItem> } items - An array of the AVQueueItem 738 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully. 739 * @throws { BusinessError } 401 - parameter check failed 740 * @throws { BusinessError } 6600101 - Session service exception. 741 * @throws { BusinessError } 6600102 - The session does not exist. 742 * @syscap SystemCapability.Multimedia.AVSession.Core 743 * @since 10 744 */ 745 setAVQueueItems(items: Array<AVQueueItem>, callback: AsyncCallback<void>): void; 746 747 /** 748 * Set the playlist of queueItem. Identifies the content of the playlist presented by this session. 749 * @param { Array<AVQueueItem> } items - An array of the AVQueueItem 750 * @returns { Promise<void> } void promise when executed successfully 751 * @throws { BusinessError } 401 - parameter check failed 752 * @throws { BusinessError } 6600101 - Session service exception. 753 * @throws { BusinessError } 6600102 - The session does not exist. 754 * @syscap SystemCapability.Multimedia.AVSession.Core 755 * @since 10 756 */ 757 setAVQueueItems(items: Array<AVQueueItem>): Promise<void>; 758 759 /** 760 * Set the name of the playlist presented by this session. 761 * @param { string } title - The name of the playlist 762 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully. 763 * @throws { BusinessError } 401 - parameter check failed 764 * @throws { BusinessError } 6600101 - Session service exception. 765 * @throws { BusinessError } 6600102 - The session does not exist. 766 * @syscap SystemCapability.Multimedia.AVSession.Core 767 * @since 10 768 */ 769 setAVQueueTitle(title: string, callback: AsyncCallback<void>): void; 770 771 /** 772 * Set the name of the playlist presented by this session. 773 * @param { string } title - The name of the playlist 774 * @returns { Promise<void> } void promise when executed successfully 775 * @throws { BusinessError } 401 - parameter check failed 776 * @throws { BusinessError } 6600101 - Session service exception. 777 * @throws { BusinessError } 6600102 - The session does not exist. 778 * @syscap SystemCapability.Multimedia.AVSession.Core 779 * @since 10 780 */ 781 setAVQueueTitle(title: string): Promise<void>; 782 783 /** 784 * Set the custom media packets for this session. 785 * @param { object } extras - The custom media packets 786 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully. 787 * @throws { BusinessError } 401 - parameter check failed 788 * @throws { BusinessError } 6600101 - Session service exception. 789 * @throws { BusinessError } 6600102 - The session does not exist. 790 * @syscap SystemCapability.Multimedia.AVSession.Core 791 * @since 10 792 */ 793 setExtras(extras: {[key: string]: Object}, callback: AsyncCallback<void>): void; 794 795 /** 796 * Set the custom media packets for this session. 797 * @param { object } extras - The custom media packets 798 * @returns { Promise<void> } void promise when executed successfully 799 * @throws { BusinessError } 401 - parameter check failed 800 * @throws { BusinessError } 6600101 - Session service exception. 801 * @throws { BusinessError } 6600102 - The session does not exist. 802 * @syscap SystemCapability.Multimedia.AVSession.Core 803 * @since 10 804 */ 805 setExtras(extras: {[key: string]: Object}): Promise<void>; 806 807 /** 808 * Get the current session's own controller 809 * @param { AsyncCallback<AVSessionController> } callback - async callback for the AVSessionController. 810 * @throws { BusinessError } 6600101 - Session service exception. 811 * @throws { BusinessError } 6600102 - The session does not exist. 812 * @syscap SystemCapability.Multimedia.AVSession.Core 813 * @since 10 814 */ 815 getController(callback: AsyncCallback<AVSessionController>): void; 816 817 /** 818 * Get the current session's own controller 819 * @returns { Promise<AVSessionController> } Promise for the AVSessionController 820 * @throws { BusinessError } 6600101 - Session service exception. 821 * @throws { BusinessError } 6600102 - The session does not exist. 822 * @syscap SystemCapability.Multimedia.AVSession.Core 823 * @since 10 824 */ 825 getController(): Promise<AVSessionController>; 826 827 /** 828 * Get the cast controller when the session is casted to remote device. 829 * If the avsession is not under casting state, the controller will return null. 830 * @param { AsyncCallback<AVCastController> } callback - async callback for the AVCastController. 831 * @throws {BusinessError} 6600102 - {@link #ERR_CODE_SESSION_NOT_EXIST} - session does not exist 832 * @throws {BusinessError} 6600110 - 6600109 - remote connection does not exist 833 * @syscap SystemCapability.Multimedia.AVSession.AVCast 834 * @since 10 835 */ 836 getAVCastController(callback: AsyncCallback<AVCastController>): void; 837 838 /** 839 * Get the cast controller when the session is casted to remote device. 840 * If the avsession is not under casting state, the controller will return null. 841 * @returns { Promise<AVCastController> } Promise for the AVCastController 842 * @throws {BusinessError} 6600102 - {@link #ERR_CODE_SESSION_NOT_EXIST} session does not exist 843 * @throws {BusinessError} 6600110 - 6600109 - remote connection does not exist 844 * @syscap SystemCapability.Multimedia.AVSession.AVCast 845 * @since 10 846 */ 847 getAVCastController(): Promise<AVCastController>; 848 849 /** 850 * Get output device information 851 * @param { AsyncCallback<OutputDeviceInfo> } callback - async callback for the OutputDeviceInfo. 852 * @throws { BusinessError } 6600101 - Session service exception. 853 * @throws { BusinessError } 6600102 - The session does not exist. 854 * @syscap SystemCapability.Multimedia.AVSession.Core 855 * @since 10 856 */ 857 getOutputDevice(callback: AsyncCallback<OutputDeviceInfo>): void; 858 859 /** 860 * Get output device information 861 * @returns { Promise<OutputDeviceInfo> } Promise for the OutputDeviceInfo 862 * @throws { BusinessError } 6600101 - Session service exception. 863 * @throws { BusinessError } 6600102 - The session does not exist. 864 * @syscap SystemCapability.Multimedia.AVSession.Core 865 * @since 10 866 */ 867 getOutputDevice(): Promise<OutputDeviceInfo>; 868 869 /** 870 * Get output device information 871 * @returns { OutputDeviceInfo } the OutputDeviceInfo 872 * @throws { BusinessError } 6600101 - Session service exception. 873 * @throws { BusinessError } 6600102 - The session does not exist. 874 * @syscap SystemCapability.Multimedia.AVSession.Core 875 * @since 10 876 */ 877 getOutputDeviceSync(): OutputDeviceInfo; 878 879 /** 880 * Register play command callback. 881 * As long as it is registered, it means that the ability supports this command. 882 * If you cancel the callback, you need to call off {@link off} 883 * When canceling the callback, need to update the supported commands list. 884 * Each playback command only supports registering one callback, 885 * and the new callback will replace the previous one. 886 * @param { 'play' } type - Command to register 'play'. 887 * @param { function } callback - Used to handle ('play') command 888 * @throws { BusinessError } 401 - parameter check failed 889 * @throws { BusinessError } 6600101 - Session service exception. 890 * @throws { BusinessError } 6600102 - The session does not exist. 891 * @syscap SystemCapability.Multimedia.AVSession.Core 892 * @since 10 893 */ 894 on(type: 'play', callback: () => void): void; 895 896 /** 897 * Register pause command callback. 898 * As long as it is registered, it means that the ability supports this command. 899 * If you cancel the callback, you need to call off {@link off} 900 * When canceling the callback, need to update the supported commands list. 901 * Each playback command only supports registering one callback, 902 * and the new callback will replace the previous one. 903 * @param { 'pause' } type - Command to register 'pause'. 904 * @param { function } callback - Used to handle ('pause') command 905 * @throws { BusinessError } 401 - parameter check failed 906 * @throws { BusinessError } 6600101 - Session service exception. 907 * @throws { BusinessError } 6600102 - The session does not exist. 908 * @syscap SystemCapability.Multimedia.AVSession.Core 909 * @since 10 910 */ 911 on(type: 'pause', callback: () => void): void; 912 913 /** 914 * Register stop command callback. 915 * As long as it is registered, it means that the ability supports this command. 916 * If you cancel the callback, you need to call off {@link off} 917 * When canceling the callback, need to update the supported commands list. 918 * Each playback command only supports registering one callback, 919 * and the new callback will replace the previous one. 920 * @param { 'stop' } type - Command to register 'stop'. 921 * @param { function } callback - Used to handle ('stop') command 922 * @throws { BusinessError } 401 - parameter check failed 923 * @throws { BusinessError } 6600101 - Session service exception. 924 * @throws { BusinessError } 6600102 - The session does not exist. 925 * @syscap SystemCapability.Multimedia.AVSession.Core 926 * @since 10 927 */ 928 on(type: 'stop', callback: () => void): void; 929 930 /** 931 * Register playNext command callback. 932 * As long as it is registered, it means that the ability supports this command. 933 * If you cancel the callback, you need to call off {@link off} 934 * When canceling the callback, need to update the supported commands list. 935 * Each playback command only supports registering one callback, 936 * and the new callback will replace the previous one. 937 * @param { 'playNext' } type - Command to register 'playNext'. 938 * @param { function } callback - Used to handle ('playNext') command 939 * @throws { BusinessError } 401 - parameter check failed 940 * @throws { BusinessError } 6600101 - Session service exception. 941 * @throws { BusinessError } 6600102 - The session does not exist. 942 * @syscap SystemCapability.Multimedia.AVSession.Core 943 * @since 10 944 */ 945 on(type: 'playNext', callback: () => void): void; 946 947 /** 948 * Register playPrevious command callback. 949 * As long as it is registered, it means that the ability supports this command. 950 * If you cancel the callback, you need to call off {@link off} 951 * When canceling the callback, need to update the supported commands list. 952 * Each playback command only supports registering one callback, 953 * and the new callback will replace the previous one. 954 * @param { 'playPrevious' } type - Command to register 'playPrevious'. 955 * @param { function } callback - Used to handle ('playPrevious') command 956 * @throws { BusinessError } 401 - parameter check failed 957 * @throws { BusinessError } 6600101 - Session service exception. 958 * @throws { BusinessError } 6600102 - The session does not exist. 959 * @syscap SystemCapability.Multimedia.AVSession.Core 960 * @since 10 961 */ 962 on(type: 'playPrevious', callback: () => void): void; 963 964 /** 965 * Register fastForward command callback. 966 * As long as it is registered, it means that the ability supports this command. 967 * If you cancel the callback, you need to call off {@link off} 968 * When canceling the callback, need to update the supported commands list. 969 * Each playback command only supports registering one callback, 970 * and the new callback will replace the previous one. 971 * @param { 'fastForward' } type - Command to register 'fastForward'. 972 * @param { function } callback - Used to handle ('fastForward') command 973 * @throws { BusinessError } 401 - parameter check failed 974 * @throws { BusinessError } 6600101 - Session service exception. 975 * @throws { BusinessError } 6600102 - The session does not exist. 976 * @syscap SystemCapability.Multimedia.AVSession.Core 977 * @since 10 978 */ 979 on(type: 'fastForward', callback: () => void): void; 980 981 /** 982 * Register rewind command callback. 983 * As long as it is registered, it means that the ability supports this command. 984 * If you cancel the callback, you need to call off {@link off} 985 * When canceling the callback, need to update the supported commands list. 986 * Each playback command only supports registering one callback, 987 * and the new callback will replace the previous one. 988 * @param { 'rewind' } type - Command to register 'rewind'. 989 * @param { function } callback - Used to handle ('rewind') command 990 * @throws { BusinessError } 401 - parameter check failed 991 * @throws { BusinessError } 6600101 - Session service exception. 992 * @throws { BusinessError } 6600102 - The session does not exist. 993 * @syscap SystemCapability.Multimedia.AVSession.Core 994 * @since 10 995 */ 996 on(type: 'rewind', callback: () => void): void; 997 998 /** 999 * Unregister play command callback. 1000 * When canceling the callback, need to update the supported commands list. 1001 * @param { 'play' } type - Command to register 'play'. 1002 * @param { function } callback - Used to handle ('play') command 1003 * @throws { BusinessError } 401 - parameter check failed 1004 * @throws { BusinessError } 6600101 - Session service exception. 1005 * @throws { BusinessError } 6600102 - The session does not exist. 1006 * @syscap SystemCapability.Multimedia.AVSession.Core 1007 * @since 10 1008 */ 1009 off(type: 'play', callback?: () => void): void; 1010 1011 /** 1012 * Unregister pause command callback. 1013 * When canceling the callback, need to update the supported commands list. 1014 * @param { 'pause' } type - Command to register 'pause'. 1015 * @param { function } callback - Used to handle ('pause') command 1016 * @throws { BusinessError } 401 - parameter check failed 1017 * @throws { BusinessError } 6600101 - Session service exception. 1018 * @throws { BusinessError } 6600102 - The session does not exist. 1019 * @syscap SystemCapability.Multimedia.AVSession.Core 1020 * @since 10 1021 */ 1022 off(type: 'pause', callback?: () => void): void; 1023 1024 /** 1025 * Unregister stop command callback. 1026 * When canceling the callback, need to update the supported commands list. 1027 * @param { 'stop' } type - Command to register 'stop'. 1028 * @param { function } callback - Used to handle ('stop') command 1029 * @throws { BusinessError } 401 - parameter check failed 1030 * @throws { BusinessError } 6600101 - Session service exception. 1031 * @throws { BusinessError } 6600102 - The session does not exist. 1032 * @syscap SystemCapability.Multimedia.AVSession.Core 1033 * @since 10 1034 */ 1035 off(type: 'stop', callback?: () => void): void; 1036 1037 /** 1038 * Unregister playNext command callback. 1039 * When canceling the callback, need to update the supported commands list. 1040 * @param { 'playNext' } type - Command to register 'playNext'. 1041 * @param { function } callback - Used to handle ('playNext') command 1042 * @throws { BusinessError } 401 - parameter check failed 1043 * @throws { BusinessError } 6600101 - Session service exception. 1044 * @throws { BusinessError } 6600102 - The session does not exist. 1045 * @syscap SystemCapability.Multimedia.AVSession.Core 1046 * @since 10 1047 */ 1048 off(type: 'playNext', callback?: () => void): void; 1049 1050 /** 1051 * Unregister playPrevious command callback. 1052 * When canceling the callback, need to update the supported commands list. 1053 * @param { 'playPrevious' } type - Command to register 'playPrevious'. 1054 * @param { function } callback - Used to handle ('playPrevious') command 1055 * @throws { BusinessError } 401 - parameter check failed 1056 * @throws { BusinessError } 6600101 - Session service exception. 1057 * @throws { BusinessError } 6600102 - The session does not exist. 1058 * @syscap SystemCapability.Multimedia.AVSession.Core 1059 * @since 10 1060 */ 1061 off(type: 'playPrevious', callback?: () => void): void; 1062 1063 /** 1064 * Unregister fastForward command callback. 1065 * When canceling the callback, need to update the supported commands list. 1066 * @param { 'fastForward' } type - Command to register 'fastForward'. 1067 * @param { function } callback - Used to handle ('fastForward') command 1068 * @throws { BusinessError } 401 - parameter check failed 1069 * @throws { BusinessError } 6600101 - Session service exception. 1070 * @throws { BusinessError } 6600102 - The session does not exist. 1071 * @syscap SystemCapability.Multimedia.AVSession.Core 1072 * @since 10 1073 */ 1074 off(type: 'fastForward', callback?: () => void): void; 1075 1076 /** 1077 * Unregister rewind command callback. 1078 * When canceling the callback, need to update the supported commands list. 1079 * @param { 'rewind' } type - Command to register 'rewind'. 1080 * @param { function } callback - Used to handle ('rewind') command 1081 * @throws { BusinessError } 401 - parameter check failed 1082 * @throws { BusinessError } 6600101 - Session service exception. 1083 * @throws { BusinessError } 6600102 - The session does not exist. 1084 * @syscap SystemCapability.Multimedia.AVSession.Core 1085 * @since 10 1086 */ 1087 off(type: 'rewind', callback?: () => void): void; 1088 1089 /** 1090 * Register seek command callback 1091 * @param { 'seek' } type - Registration Type 'seek' 1092 * @param { function } callback - Used to handle seek command.The callback provides the seek time(ms) 1093 * @throws { BusinessError } 401 - parameter check failed 1094 * @throws { BusinessError } 6600101 - Session service exception. 1095 * @throws { BusinessError } 6600102 - The session does not exist. 1096 * @syscap SystemCapability.Multimedia.AVSession.Core 1097 * @since 10 1098 */ 1099 on(type: 'seek', callback: (time: number) => void): void; 1100 1101 /** 1102 * Unregister seek command callback 1103 * @param { 'seek' } type - Registration Type 'seek' 1104 * @param { function } callback - Used to handle seek command.The callback provides the seek time(ms) 1105 * @throws { BusinessError } 401 - parameter check failed 1106 * @throws { BusinessError } 6600101 - Session service exception. 1107 * @throws { BusinessError } 6600102 - The session does not exist. 1108 * @syscap SystemCapability.Multimedia.AVSession.Core 1109 * @since 10 1110 */ 1111 off(type: 'seek', callback?: (time: number) => void): void; 1112 1113 /** 1114 * Register setSpeed command callback 1115 * @param { 'setSpeed' } type - Registration Type 'setSpeed' 1116 * @param { function } callback - Used to handle setSpeed command.The callback provides the speed value 1117 * @throws { BusinessError } 401 - parameter check failed 1118 * @throws { BusinessError } 6600101 - Session service exception. 1119 * @throws { BusinessError } 6600102 - The session does not exist. 1120 * @syscap SystemCapability.Multimedia.AVSession.Core 1121 * @since 10 1122 */ 1123 on(type: 'setSpeed', callback: (speed: number) => void): void; 1124 1125 /** 1126 * Unregister setSpeed command callback 1127 * @param { 'setSpeed' } type - Registration Type 'setSpeed' 1128 * @param { function } callback - Used to handle setSpeed command.The callback provides the speed value 1129 * @throws { BusinessError } 401 - parameter check failed 1130 * @throws { BusinessError } 6600101 - Session service exception. 1131 * @throws { BusinessError } 6600102 - The session does not exist. 1132 * @syscap SystemCapability.Multimedia.AVSession.Core 1133 * @since 10 1134 */ 1135 off(type: 'setSpeed', callback?: (speed: number) => void): void; 1136 1137 /** 1138 * Register setLoopMode command callback 1139 * @param { 'setLoopMode' } type - Registration Type 'setLoopMode' 1140 * @param { function } callback - Used to handle setLoopMode command.The callback provides the {@link LoopMode} 1141 * @throws { BusinessError } 401 - parameter check failed 1142 * @throws { BusinessError } 6600101 - Session service exception. 1143 * @throws { BusinessError } 6600102 - The session does not exist. 1144 * @syscap SystemCapability.Multimedia.AVSession.Core 1145 * @since 10 1146 */ 1147 on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void; 1148 1149 /** 1150 * Unregister setLoopMode command callback 1151 * @param { 'setLoopMode' } type - Registration Type 'setLoopMode' 1152 * @param { function } callback - Used to handle setLoopMode command.The callback provides the {@link LoopMode} 1153 * @throws { BusinessError } 401 - parameter check failed 1154 * @throws { BusinessError } 6600101 - Session service exception. 1155 * @throws { BusinessError } 6600102 - The session does not exist. 1156 * @syscap SystemCapability.Multimedia.AVSession.Core 1157 * @since 10 1158 */ 1159 off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void; 1160 1161 /** 1162 * Register toggle favorite command callback 1163 * @param { 'toggleFavorite' } type - Registration Type 'toggleFavorite' 1164 * @param { function } callback - Used to handle toggleFavorite command.The callback provides 1165 * the assetId for which the favorite status needs to be switched. 1166 * @throws { BusinessError } 401 - parameter check failed 1167 * @throws { BusinessError } 6600101 - Session service exception. 1168 * @throws { BusinessError } 6600102 - The session does not exist. 1169 * @syscap SystemCapability.Multimedia.AVSession.Core 1170 * @since 10 1171 */ 1172 on(type: 'toggleFavorite', callback: (assetId: string) => void): void; 1173 1174 /** 1175 * Unregister toggle favorite command callback 1176 * @param { 'toggleFavorite' } type - Registration Type 'toggleFavorite' 1177 * @param { function } callback - Used to handle toggleFavorite command.The callback provides 1178 * the assetId for which the favorite status needs to be switched. 1179 * @throws { BusinessError } 401 - parameter check failed 1180 * @throws { BusinessError } 6600101 - Session service exception. 1181 * @throws { BusinessError } 6600102 - The session does not exist. 1182 * @syscap SystemCapability.Multimedia.AVSession.Core 1183 * @since 10 1184 */ 1185 off(type: 'toggleFavorite', callback?: (assetId: string) => void): void; 1186 1187 /** 1188 * Register media key handling callback 1189 * @param { 'handleKeyEvent' } type - Registration Type 'handleKeyEvent' 1190 * @param { function } callback - Used to handle key events.The callback provides the KeyEvent 1191 * @throws { BusinessError } 401 - parameter check failed 1192 * @throws { BusinessError } 6600101 - Session service exception. 1193 * @throws { BusinessError } 6600102 - The session does not exist. 1194 * @syscap SystemCapability.Multimedia.AVSession.Core 1195 * @since 10 1196 */ 1197 on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void; 1198 1199 /** 1200 * Unregister media key handling callback 1201 * @param { 'handleKeyEvent' } type - Registration Type 'handleKeyEvent' 1202 * @param { function } callback - Used to handle key events.The callback provides the KeyEvent 1203 * @throws { BusinessError } 401 - parameter check failed 1204 * @throws { BusinessError } 6600101 - Session service exception. 1205 * @throws { BusinessError } 6600102 - The session does not exist. 1206 * @syscap SystemCapability.Multimedia.AVSession.Core 1207 * @since 10 1208 */ 1209 off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void; 1210 1211 /** 1212 * Register session output device change callback 1213 * @param { 'outputDeviceChange' } type - Registration Type 'outputDeviceChange' 1214 * @param { function } callback - Used to handle output device changed. 1215 * The callback provide the new device info {@link OutputDeviceInfo} and related connection state {@link ConnectionState}. 1216 * @throws { BusinessError } 401 - parameter check failed 1217 * @throws { BusinessError } 6600101 - Session service exception 1218 * @throws { BusinessError } 6600102 - The session does not exist 1219 * @syscap SystemCapability.Multimedia.AVSession.Core 1220 * @since 10 1221 */ 1222 on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void; 1223 1224 /** 1225 * Unregister session output device change callback 1226 * @param { 'outputDeviceChange' } type - Registration Type 'outputDeviceChange' 1227 * @param { function } callback - Used to handle output device changed. 1228 * The callback provide the new device info {@link OutputDeviceInfo} and related connection state {@link ConnectionState}. 1229 * @throws { BusinessError } 401 - parameter check failed 1230 * @throws { BusinessError } 6600101 - Session service exception 1231 * @throws { BusinessError } 6600102 - The session does not exist 1232 * @syscap SystemCapability.Multimedia.AVSession.Core 1233 * @since 10 1234 */ 1235 off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void; 1236 1237 /** 1238 * Register session custom command change callback 1239 * @param { 'commonCommand' } type - Registration Type 'commonCommand' 1240 * @param { function } callback - Used to handle event when the common command is received 1241 * The callback provide the command name and command args 1242 * @throws { BusinessError } 401 - parameter check failed 1243 * @throws { BusinessError } 6600101 - Session service exception. 1244 * @throws { BusinessError } 6600102 - The session does not exist. 1245 * @syscap SystemCapability.Multimedia.AVSession.Core 1246 * @since 10 1247 */ 1248 on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void; 1249 1250 /** 1251 * Unregister session custom command change callback 1252 * @param { 'commonCommand' } type - Registration Type 'commonCommand' 1253 * @param { function } callback - Used to cancel a specific listener 1254 * The callback provide the command name and command args 1255 * @throws { BusinessError } 401 - parameter check failed 1256 * @throws { BusinessError } 6600101 - Session service exception. 1257 * @throws { BusinessError } 6600102 - The session does not exist. 1258 * @syscap SystemCapability.Multimedia.AVSession.Core 1259 * @since 10 1260 */ 1261 off(type: 'commonCommand', callback?: (command: string, args: {[key: string]: Object}) => void): void; 1262 1263 /** 1264 * Register the item to play from the playlist change callback 1265 * @param { 'skipToQueueItem' } type - Registration Type 'skipToQueueItem' 1266 * @param { function } callback - Used to handle the item to be played. 1267 * The callback provide the new device info {@link OutputDeviceInfo} 1268 * @throws { BusinessError } 401 - parameter check failed 1269 * @throws { BusinessError } 6600101 - Session service exception. 1270 * @throws { BusinessError } 6600102 - The session does not exist. 1271 * @syscap SystemCapability.Multimedia.AVSession.Core 1272 * @since 10 1273 */ 1274 on(type: 'skipToQueueItem', callback: (itemId: number) => void): void; 1275 1276 /** 1277 * Unregister the item to play from the playlist change callback 1278 * @param { 'skipToQueueItem' } type - Registration Type 'skipToQueueItem' 1279 * @param { function } callback - Used to handle the item to be played. 1280 * The callback provide the new device info {@link OutputDeviceInfo} 1281 * @throws { BusinessError } 401 - parameter check failed 1282 * @throws { BusinessError } 6600101 - Session service exception. 1283 * @throws { BusinessError } 6600102 - The session does not exist. 1284 * @syscap SystemCapability.Multimedia.AVSession.Core 1285 * @since 10 1286 */ 1287 off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void; 1288 1289 /** 1290 * Stop current cast and disconnect device connection. 1291 * @param { AsyncCallback<void> } callback A callback instance used to return when cast stopped completed. 1292 * @throws { BusinessError } 6600109 - The remote connection is not established 1293 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1294 * @since 10 1295 */ 1296 stopCasting(callback: AsyncCallback<void>): void; 1297 1298 /** 1299 * Stop current cast and disconnect device connection. 1300 * @returns { Promise<void> } void result promise when executed successfully 1301 * @throws { BusinessError } 6600109 - The remote connection is not established 1302 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1303 * @since 10 1304 */ 1305 stopCasting(): Promise<void>; 1306 1307 /** 1308 * Activate the session, indicating that the session can accept control commands 1309 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the session is activated. 1310 * @throws { BusinessError } 6600101 - Session service exception. 1311 * @throws { BusinessError } 6600102 - The session does not exist. 1312 * @syscap SystemCapability.Multimedia.AVSession.Core 1313 * @since 10 1314 */ 1315 activate(callback: AsyncCallback<void>): void; 1316 1317 /** 1318 * Activate the session, indicating that the session can accept control commands 1319 * @returns { Promise<void> } void result promise when executed successfully 1320 * @throws { BusinessError } 6600101 - Session service exception. 1321 * @throws { BusinessError } 6600102 - The session does not exist. 1322 * @syscap SystemCapability.Multimedia.AVSession.Core 1323 * @since 10 1324 */ 1325 activate(): Promise<void>; 1326 1327 /** 1328 * Deactivate the session, indicating that the session not ready to accept control commands 1329 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the session is deactivated. 1330 * @throws { BusinessError } 6600101 - Session service exception. 1331 * @throws { BusinessError } 6600102 - The session does not exist. 1332 * @syscap SystemCapability.Multimedia.AVSession.Core 1333 * @since 10 1334 */ 1335 deactivate(callback: AsyncCallback<void>): void; 1336 1337 /** 1338 * Deactivate the session, indicating that the session not ready to accept control commands 1339 * @returns { Promise<void> } void promise when executed successfully 1340 * @throws { BusinessError } 6600101 - Session service exception. 1341 * @throws { BusinessError } 6600102 - The session does not exist. 1342 * @syscap SystemCapability.Multimedia.AVSession.Core 1343 * @since 10 1344 */ 1345 deactivate(): Promise<void>; 1346 1347 /** 1348 * Destroy this session, the server will clean up the session resources 1349 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 1350 * @throws { BusinessError } 6600101 - Session service exception. 1351 * @throws { BusinessError } 6600102 - The session does not exist. 1352 * @syscap SystemCapability.Multimedia.AVSession.Core 1353 * @since 10 1354 */ 1355 destroy(callback: AsyncCallback<void>): void; 1356 1357 /** 1358 * Destroy this session, the server will clean up the session resources 1359 * @returns { Promise<void> } void promise when executed successfully 1360 * @throws { BusinessError } 6600101 - Session service exception. 1361 * @throws { BusinessError } 6600102 - The session does not exist. 1362 * @syscap SystemCapability.Multimedia.AVSession.Core 1363 * @since 10 1364 */ 1365 destroy(): Promise<void>; 1366 } 1367 1368 /** 1369 * The type of control command 1370 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1371 * @since 10 1372 */ 1373 type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 1374 'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite'; 1375 1376 /** 1377 * The definition of command to be sent to the session 1378 * @interface AVCastControlCommand 1379 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1380 * @since 10 1381 */ 1382 interface AVCastControlCommand { 1383 /** 1384 * The command value {@link AVCastControlCommandType} 1385 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1386 * @since 10 1387 */ 1388 command: AVCastControlCommandType; 1389 1390 /** 1391 * Parameter carried in the command. 1392 * The seek command must carry the number parameter. 1393 * The setVolume command must carry the number parameter. 1394 * The toggleFavorite command must carry the {@link AVMediaDescription.assetId} parameter. 1395 * The setSpeed command must carry the {@link #media.PlaybackSpeed} parameter. 1396 * The setLoopMode command must carry the {@link LoopMode} parameter. 1397 * Other commands do not need to carry parameters. 1398 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1399 * @since 10 1400 */ 1401 parameter?: media.PlaybackSpeed | number | string | LoopMode; 1402 } 1403 1404 /** 1405 * AVCastController definition used to implement a remote control when a cast is connected 1406 * @interface AVCastController 1407 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1408 * @since 10 1409 */ 1410 interface AVCastController { 1411 /** 1412 * Set a surface instance to display playing view, used at sink side. 1413 * @param { string } surfaceId - surface id, video player will use this id get a surface instance. 1414 * @param { AsyncCallback<void> } callback - A callback instance used to return when set surface completed. 1415 * @throws { BusinessError } 401 - parameter check failed 1416 * @throws { BusinessError } 6600109 - The remote connection is not established 1417 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1418 * @systemapi 1419 * @since 10 1420 */ 1421 setDisplaySurface(surfaceId: string, callback: AsyncCallback<void>): void; 1422 1423 /** 1424 * Set a surface instance to display playing view, used at sink side. 1425 * @param { string } surfaceId - surface id, video player will use this id get a surface instance. 1426 * @returns { Promise<void> } Promise used to return the result. 1427 * @throws { BusinessError } 401 - parameter check failed 1428 * @throws { BusinessError } 6600109 - The remote connection is not established 1429 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1430 * @systemapi 1431 * @since 10 1432 */ 1433 setDisplaySurface(surfaceId: string): Promise<void>; 1434 1435 /** 1436 * Get the playback status of the current player 1437 * @param { AsyncCallback<AVPlaybackState> } callback - The triggered asyncCallback when (getAVPlaybackState). 1438 * @throws { BusinessError } 6600101 - Session service exception 1439 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1440 * @since 10 1441 */ 1442 getAVPlaybackState(callback: AsyncCallback<AVPlaybackState>): void; 1443 1444 /** 1445 * Get the playback status of the current player 1446 * @returns { Promise<AVPlaybackState> } (AVPlaybackState) returned through promise 1447 * @throws { BusinessError } 6600101 - Session service exception 1448 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1449 * @since 10 1450 */ 1451 getAVPlaybackState(): Promise<AVPlaybackState>; 1452 1453 /** 1454 * Send control commands to remote player 1455 * @param { AVCastControlCommand } command The command to be send. 1456 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 1457 * @throws { BusinessError } 401 - parameter check failed 1458 * @throws { BusinessError } 6600101 - Session service exception 1459 * @throws { BusinessError } 6600105 - Invalid session command 1460 * @throws { BusinessError } 6600109 - The remote connection is not established 1461 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1462 * @since 10 1463 */ 1464 sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback<void>): void; 1465 1466 /** 1467 * Send control commands to remote player 1468 * @param { AVCastControlCommand } command The command to be send. 1469 * @returns { Promise<void> } Promise used to return the result. 1470 * @throws { BusinessError } 401 - parameter check failed 1471 * @throws { BusinessError } 6600101 - Session service exception 1472 * @throws { BusinessError } 6600105 - Invalid session command 1473 * @throws { BusinessError } 6600109 - The remote connection is not established 1474 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1475 * @since 10 1476 */ 1477 sendControlCommand(command: AVCastControlCommand): Promise<void>; 1478 1479 /** 1480 * Play the current item, should contain mediaUri otherwise the playback will fail. 1481 * @param { AVQueueItem } item media item info. 1482 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 1483 * @throws {BusinessError} 401 - parameter check failed 1484 * @throws {BusinessError} 6600101 - Session service exception 1485 * @throws {BusinessError} 6600109 - The remote connection is not established 1486 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1487 * @since 10 1488 */ 1489 start(item: AVQueueItem, callback: AsyncCallback<void>): void; 1490 1491 /** 1492 * Play the current item, should contain mediaUri otherwise the playback will fail. 1493 * @param { AVQueueItem } item media item info. 1494 * @returns { Promise<void> } Promise used to return the result. 1495 * @throws {BusinessError} 401 - parameter check failed 1496 * @throws {BusinessError} 6600101 - Session service exception 1497 * @throws {BusinessError} 6600109 - The remote connection is not established 1498 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1499 * @since 10 1500 */ 1501 start(item: AVQueueItem): Promise<void>; 1502 1503 /** 1504 * Load the current item and mediaUri can be null, this is needed for sink media information displaying 1505 * @param { AVQueueItem } item media item info. 1506 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 1507 * @throws {BusinessError} 401 - parameter check failed 1508 * @throws {BusinessError} 6600101 - Session service exception 1509 * @throws {BusinessError} 6600109 - The remote connection is not established 1510 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1511 * @since 10 1512 */ 1513 prepare(item: AVQueueItem, callback: AsyncCallback<void>): void; 1514 1515 /** 1516 * Load the current item and mediaUri can be null, this is needed for sink media information displaying 1517 * @param { AVQueueItem } item media item info. 1518 * @returns { Promise<void> } Promise used to return the result. 1519 * @throws {BusinessError} 401 - parameter check failed 1520 * @throws {BusinessError} 6600101 - Session service exception 1521 * @throws {BusinessError} 6600109 - The remote connection is not established 1522 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1523 * @since 10 1524 */ 1525 prepare(item: AVQueueItem): Promise<void>; 1526 1527 /** 1528 * Get the current playing item 1529 * @param { AsyncCallback<AVQueueItem> } callback - The triggered asyncCallback. 1530 * @throws { BusinessError } 6600101 - Session service exception 1531 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1532 * @since 10 1533 */ 1534 getCurrentItem(callback: AsyncCallback<AVQueueItem>): void; 1535 1536 /** 1537 * Get the current playing item 1538 * @returns { Promise<AVQueueItem> } (AVQueueItem) returned through promise 1539 * @throws { BusinessError } 6600101 - Session service exception 1540 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1541 * @since 10 1542 */ 1543 getCurrentItem(): Promise<AVQueueItem>; 1544 1545 /** 1546 * Register playback state changed callback 1547 * @param { 'playbackStateChange' } type 1548 * @param { Array<keyof AVPlaybackState> | 'all' } filter - The properties of {@link AVPlaybackState} that you cared about 1549 * @param { function } callback - The callback used to handle playback state changed event. 1550 * The callback function provides the {@link AVPlaybackState} parameter. 1551 * @throws { BusinessError } 401 - parameter check failed 1552 * @throws { BusinessError } 6600101 - Session service exception 1553 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1554 * @since 10 1555 */ 1556 on(type: 'playbackStateChange', filter: Array<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void; 1557 1558 /** 1559 * Unregister playback state changed callback 1560 * @param { 'playbackStateChange' } type 1561 * @param { function } callback - The callback used to handle playback state changed event. 1562 * The callback function provides the {@link AVPlaybackState} parameter. 1563 * @throws { BusinessError } 401 - parameter check failed 1564 * @throws { BusinessError } 6600101 - Session service exception 1565 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1566 * @since 10 1567 */ 1568 off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void; 1569 1570 /** 1571 * Register listener for current media item playback events. 1572 * @param { 'mediaItemChange' } type Type of the playback event to listen for. 1573 * @param { Callback<AVQueueItem> } callback Callback used to listen for current item changed. 1574 * @throws { BusinessError } 401 - parameter check failed 1575 * @throws { BusinessError } 6600101 - Session service exception 1576 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1577 * @since 10 1578 */ 1579 on(type: 'mediaItemChange', callback: Callback<AVQueueItem>): void; 1580 1581 /** 1582 * Unregister listener for current media item playback events. 1583 * @param { 'mediaItemChange' } type Type of the playback event to listen for. 1584 * @throws { BusinessError } 401 - parameter check failed 1585 * @throws { BusinessError } 6600101 - Session service exception 1586 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1587 * @since 10 1588 */ 1589 off(type: 'mediaItemChange'): void; 1590 1591 /** 1592 * Register playback command callback sent by remote side or media center. 1593 * Application needs update the new media resource when receive these commands by using playItem. 1594 * @param { 'playNext' } type - Type of the 'playback' event to listen for. 1595 * @param { Callback<void> } callback - Used to handle 'playNext' command 1596 * @throws { BusinessError } 401 - parameter check failed 1597 * @throws { BusinessError } 6600101 - Session service exception 1598 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1599 * @since 10 1600 */ 1601 on(type: 'playNext', callback: Callback<void>): void; 1602 1603 /** 1604 * Unregister playback command callback sent by remote side or media center. 1605 * When canceling the callback, need to update the supported commands list. 1606 * @param { 'playNext' } type - Type of the 'playback' event to listen for. 1607 * @throws { BusinessError } 401 - parameter check failed 1608 * @throws { BusinessError } 6600101 - Session service exception 1609 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1610 * @since 10 1611 */ 1612 off(type: 'playNext'): void; 1613 1614 /** 1615 * Register playback command callback sent by remote side or media center. 1616 * Application needs update the new media resource when receive these commands by using playItem. 1617 * @param { 'playPrevious' } type - Type of the 'playPrevious' to listen for. 1618 * @param { Callback<void> } callback - Used to handle 'playPrevious' command 1619 * @throws { BusinessError } 401 - parameter check failed 1620 * @throws { BusinessError } 6600101 - Session service exception 1621 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1622 * @since 10 1623 */ 1624 on(type: 'playPrevious', callback: Callback<void>): void; 1625 1626 /** 1627 * Unregister playback command callback sent by remote side or media center. 1628 * When canceling the callback, need to update the supported commands list. 1629 * @param { 'playPrevious' } type - Type of the 'playPrevious' to listen for. 1630 * @throws { BusinessError } 401 - parameter check failed 1631 * @throws { BusinessError } 6600101 - Session service exception 1632 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1633 * @since 10 1634 */ 1635 off(type: 'playPrevious'): void; 1636 1637 /** 1638 * Register listens for playback events. 1639 * @param { 'seekDone' } type - Type of the 'seekDone' to listen for. 1640 * @param { Callback<number> } callback - Callback used to listen for the playback seekDone event. 1641 * @throws { BusinessError } 401 - parameter check failed 1642 * @throws { BusinessError } 6600101 - Session service exception 1643 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1644 * @since 10 1645 */ 1646 on(type: 'seekDone', callback: Callback<number>): void; 1647 1648 /** 1649 * Unregister listens for playback events. 1650 * @param { 'seekDone' } type - Type of the 'seekDone' to listen for. 1651 * @throws { BusinessError } 401 - parameter check failed 1652 * @throws { BusinessError } 6600101 - Session service exception 1653 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1654 * @since 10 1655 */ 1656 off(type: 'seekDone'): void; 1657 1658 /** 1659 * Register listener for video size change event, used at remote side. 1660 * @param { 'videoSizeChange' } type - Type of the 'videoSizeChange' to listen for. 1661 * @param { function } callback - Callback used to return video size. 1662 * @throws { BusinessError } 401 - parameter check failed 1663 * @throws { BusinessError } 6600101 - Session service exception 1664 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1665 * @systemapi 1666 * @since 10 1667 */ 1668 on(type: 'videoSizeChange', callback: (width: number, height: number) => void): void; 1669 1670 /** 1671 * Unregister listener for video size change event, used at remote side. 1672 * @param { 'videoSizeChange' } type - Type of the 'videoSizeChange' to listen for. 1673 * @throws { BusinessError } 401 - parameter check failed 1674 * @throws { BusinessError } 6600101 - Session service exception 1675 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1676 * @systemapi 1677 * @since 10 1678 */ 1679 off(type: 'videoSizeChange'): void; 1680 1681 /** 1682 * Register listeners for playback error events. 1683 * @param { 'error' } type Type of the 'error' to listen for. 1684 * @param { ErrorCallback } callback Callback used to listen for the playback error event. 1685 * @throws { BusinessError } 401 - parameter check failed 1686 * @throws { BusinessError } 5400101 - No memory. 1687 * @throws { BusinessError } 5400102 - Operation not allowed. 1688 * @throws { BusinessError } 5400103 - I/O error. 1689 * @throws { BusinessError } 5400104 - Time out. 1690 * @throws { BusinessError } 5400105 - Service died. 1691 * @throws { BusinessError } 5400106 - Unsupport format. 1692 * @throws { BusinessError } 6600101 - Session service exception 1693 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1694 * @since 10 1695 */ 1696 1697 on(type: 'error', callback: ErrorCallback): void; 1698 1699 /** 1700 * Unregister listens for playback error events. 1701 * @param { 'error' } type Type of the 'error' to listen for. 1702 * @throws { BusinessError } 401 - parameter check failed 1703 * @throws { BusinessError } 5400101 - No memory. 1704 * @throws { BusinessError } 5400102 - Operation not allowed. 1705 * @throws { BusinessError } 5400103 - I/O error. 1706 * @throws { BusinessError } 5400104 - Time out. 1707 * @throws { BusinessError } 5400105 - Service died. 1708 * @throws { BusinessError } 5400106 - Unsupport format. 1709 * @throws { BusinessError } 6600101 - Session service exception 1710 * @syscap SystemCapability.Multimedia.AVSession.AVCast 1711 * @since 10 1712 */ 1713 off(type: 'error'): void; 1714 } 1715 1716 /** 1717 * Define the device connection state. 1718 * @enum { number } 1719 * @syscap SystemCapability.Multimedia.AVSession.Core 1720 * @since 10 1721 */ 1722 enum ConnectionState { 1723 /** 1724 * A connection state indicating the device is in the process of connecting. 1725 * @syscap SystemCapability.Multimedia.AVSession.Core 1726 * @since 10 1727 */ 1728 STATE_CONNECTING = 0, 1729 1730 /** 1731 * A connection state indicating the device is connected. 1732 * @syscap SystemCapability.Multimedia.AVSession.Core 1733 * @since 10 1734 */ 1735 STATE_CONNECTED = 1, 1736 1737 /** 1738 * The default connection state indicating the device is disconnected. 1739 * @syscap SystemCapability.Multimedia.AVSession.Core 1740 * @since 10 1741 */ 1742 STATE_DISCONNECTED = 6, 1743 } 1744 1745 /* 1746 * The metadata of the current media.Used to set the properties of the current media file 1747 * @interface AVMetadata 1748 * @syscap SystemCapability.Multimedia.AVSession.Core 1749 * @since 10 1750 */ 1751 interface AVMetadata { 1752 /** 1753 * Unique ID used to represent this media. 1754 * @type { string } 1755 * @syscap SystemCapability.Multimedia.AVSession.Core 1756 * @since 10 1757 */ 1758 assetId: string; 1759 1760 /** 1761 * The title of this media, for display in media center. 1762 * @type { ?string } 1763 * @syscap SystemCapability.Multimedia.AVSession.Core 1764 * @since 10 1765 */ 1766 title?: string; 1767 1768 /** 1769 * The artist of this media 1770 * @type { ?string } 1771 * @syscap SystemCapability.Multimedia.AVSession.Core 1772 * @since 10 1773 */ 1774 artist?: string; 1775 1776 /** 1777 * The author of this media 1778 * @type { ?string } 1779 * @syscap SystemCapability.Multimedia.AVSession.Core 1780 * @since 10 1781 */ 1782 author?: string; 1783 1784 /** 1785 * The album of this media 1786 * @type { ?string } 1787 * @syscap SystemCapability.Multimedia.AVSession.Core 1788 * @since 10 1789 */ 1790 album?: string; 1791 1792 /** 1793 * The writer of this media 1794 * @type { ?string } 1795 * @syscap SystemCapability.Multimedia.AVSession.Core 1796 * @since 10 1797 */ 1798 writer?: string; 1799 1800 /** 1801 * The composer of this media 1802 * @type { ?string } 1803 * @syscap SystemCapability.Multimedia.AVSession.Core 1804 * @since 10 1805 */ 1806 composer?: string; 1807 1808 /** 1809 * The duration of this media, used to automatically calculate playback position 1810 * @type { ?number } 1811 * @syscap SystemCapability.Multimedia.AVSession.Core 1812 * @since 10 1813 */ 1814 duration?: number; 1815 1816 /** 1817 * The image of the media as a {@link PixelMap} or an uri formatted String, 1818 * used to display in media center. 1819 * @syscap SystemCapability.Multimedia.AVSession.Core 1820 * @since 10 1821 */ 1822 mediaImage?: image.PixelMap | string; 1823 1824 /** 1825 * The publishDate of the media 1826 * @type { ?Date } 1827 * @syscap SystemCapability.Multimedia.AVSession.Core 1828 * @since 10 1829 */ 1830 publishDate?: Date; 1831 1832 /** 1833 * The subtitle of the media, used for display 1834 * @type { ?string } 1835 * @syscap SystemCapability.Multimedia.AVSession.Core 1836 * @since 10 1837 */ 1838 subtitle?: string; 1839 1840 /** 1841 * The discription of the media, used for display 1842 * @type { ?string } 1843 * @syscap SystemCapability.Multimedia.AVSession.Core 1844 * @since 10 1845 */ 1846 description?: string; 1847 1848 /** 1849 * The lyric of the media, it should be in standard lyric format 1850 * @type { ?string } 1851 * @syscap SystemCapability.Multimedia.AVSession.Core 1852 * @since 10 1853 */ 1854 lyric?: string; 1855 1856 /** 1857 * The previous playable media id. 1858 * Used to tell the controller if there is a previous playable media 1859 * @type { ?string } 1860 * @syscap SystemCapability.Multimedia.AVSession.Core 1861 * @since 10 1862 */ 1863 previousAssetId?: string; 1864 1865 /** 1866 * The next playable media id. 1867 * Used to tell the controller if there is a next playable media 1868 * @type { ?string } 1869 * @syscap SystemCapability.Multimedia.AVSession.Core 1870 * @since 10 1871 */ 1872 nextAssetId?: string; 1873 } 1874 1875 /** 1876 * The description of the media for an item in the playlist of the session 1877 * @interface AVMediaDescription 1878 * @syscap SystemCapability.Multimedia.AVSession.Core 1879 * @since 10 1880 */ 1881 interface AVMediaDescription { 1882 /** 1883 * Unique ID used to represent this media. 1884 * @type { string } 1885 * @syscap SystemCapability.Multimedia.AVSession.Core 1886 * @since 10 1887 */ 1888 assetId: string; 1889 /** 1890 * The title of this media, for display in media center. 1891 * @type { ?string } 1892 * @syscap SystemCapability.Multimedia.AVSession.Core 1893 * @since 10 1894 */ 1895 title?: string; 1896 1897 /** 1898 * The subtitle of the media, used for display 1899 * @type { ?string } 1900 * @syscap SystemCapability.Multimedia.AVSession.Core 1901 * @since 10 1902 */ 1903 subtitle?: string; 1904 1905 /** 1906 * The description of this media 1907 * @type { ?string } 1908 * @syscap SystemCapability.Multimedia.AVSession.Core 1909 * @since 10 1910 */ 1911 description?: string; 1912 1913 /** 1914 * The image of this media asset displayed in the media center. 1915 * It can be a {@link PixelMap} or a URI formatted string, 1916 * @syscap SystemCapability.Multimedia.AVSession.Core 1917 * @since 10 1918 */ 1919 mediaImage?: image.PixelMap | string; 1920 /** 1921 * Any additional attributes that can be represented as key-value pairs 1922 * @syscap SystemCapability.Multimedia.AVSession.Core 1923 * @since 10 1924 */ 1925 extras?: {[key: string]: Object}; 1926 1927 /** 1928 * The type of this media, such as video, audio and so on. 1929 * @type { ?string } 1930 * @syscap SystemCapability.Multimedia.AVSession.Core 1931 * @since 10 1932 */ 1933 mediaType?: string; 1934 1935 /** 1936 * The size of this media. 1937 * @type { ?number } 1938 * @syscap SystemCapability.Multimedia.AVSession.Core 1939 * @since 10 1940 */ 1941 mediaSize?: number; 1942 1943 /** 1944 * The album title of this media 1945 * @type { ?string } 1946 * @syscap SystemCapability.Multimedia.AVSession.Core 1947 * @since 10 1948 */ 1949 albumTitle?: string; 1950 1951 /** 1952 * The album cover uri of this media 1953 * @type { ?string } 1954 * @syscap SystemCapability.Multimedia.AVSession.Core 1955 * @since 10 1956 */ 1957 albumCoverUri?: string; 1958 1959 /** 1960 * The lyric content of the media, it should be in standard lyric format 1961 * @type { ?string } 1962 * @syscap SystemCapability.Multimedia.AVSession.Core 1963 * @since 10 1964 */ 1965 lyricContent?: string; 1966 1967 /** 1968 * The lyric uri of the media. 1969 * @type { ?string } 1970 * @syscap SystemCapability.Multimedia.AVSession.Core 1971 * @since 10 1972 */ 1973 lyricUri?: string; 1974 1975 /** 1976 * The artist of this media. 1977 * @type { ?string } 1978 * @syscap SystemCapability.Multimedia.AVSession.Core 1979 * @since 10 1980 */ 1981 artist?: string; 1982 1983 /** 1984 * The uri of the media, used to locate the media in some special cases 1985 * @type { ?string } 1986 * @syscap SystemCapability.Multimedia.AVSession.Core 1987 * @since 10 1988 */ 1989 mediaUri?: string; 1990 1991 /** 1992 * Media file descriptor. 1993 * @syscap SystemCapability.Multimedia.AVSession.Core 1994 * @since 10 1995 */ 1996 fdSrc?: media.AVFileDescriptor; 1997 1998 /** 1999 * The duration of this media 2000 * @type { ?number } 2001 * @syscap SystemCapability.Multimedia.AVSession.Core 2002 * @since 10 2003 */ 2004 duration?: number; 2005 2006 /** 2007 * Media start position, described by milliseconds. 2008 * @type { ?number } 2009 * @syscap SystemCapability.Multimedia.AVSession.Core 2010 * @since 10 2011 */ 2012 startPosition?: number; 2013 2014 /** 2015 * Media credits position, described by milliseconds. 2016 * @type { ?number } 2017 * @syscap SystemCapability.Multimedia.AVSession.Core 2018 * @since 10 2019 */ 2020 creditsPosition?: number; 2021 2022 /** 2023 * Application name. 2024 * @type { ?string } 2025 * @syscap SystemCapability.Multimedia.AVSession.Core 2026 * @since 10 2027 */ 2028 appName?: string; 2029 } 2030 2031 /** 2032 * The item in the playlist of the session 2033 * @interface AVQueueItem 2034 * @syscap SystemCapability.Multimedia.AVSession.Core 2035 * @since 10 2036 */ 2037 interface AVQueueItem { 2038 /** 2039 * Sequence number of the item in the playlist. 2040 * @type { number } 2041 * @syscap SystemCapability.Multimedia.AVSession.Core 2042 * @since 10 2043 */ 2044 itemId: number; 2045 2046 /** 2047 * The media description of the item in the playlist. 2048 * @syscap SystemCapability.Multimedia.AVSession.Core 2049 * @since 10 2050 */ 2051 description?: AVMediaDescription; 2052 } 2053 2054 /** 2055 * Used to indicate the playback state of the current media. 2056 * If the playback state of the media changes, it needs to be updated synchronously 2057 * @interface AVPlaybackState 2058 * @syscap SystemCapability.Multimedia.AVSession.Core 2059 * @since 10 2060 */ 2061 interface AVPlaybackState { 2062 /** 2063 * Current playback state. See {@link PlaybackState} 2064 * @syscap SystemCapability.Multimedia.AVSession.Core 2065 * @since 10 2066 */ 2067 state?: PlaybackState; 2068 2069 /** 2070 * Current playback speed 2071 * @type { ?number } 2072 * @syscap SystemCapability.Multimedia.AVSession.Core 2073 * @since 10 2074 */ 2075 speed?: number; 2076 2077 /** 2078 * Current playback position of this media. See {@link PlaybackPosition} 2079 * @syscap SystemCapability.Multimedia.AVSession.Core 2080 * @since 10 2081 */ 2082 position?: PlaybackPosition; 2083 2084 /** 2085 * The current buffered time, the maximum playable position 2086 * @type { ?number } 2087 * @syscap SystemCapability.Multimedia.AVSession.Core 2088 * @since 10 2089 */ 2090 bufferedTime?: number; 2091 2092 /** 2093 * Current playback loop mode. See {@link LoopMode} 2094 * @syscap SystemCapability.Multimedia.AVSession.Core 2095 * @since 10 2096 */ 2097 loopMode?: LoopMode; 2098 2099 /** 2100 * Current Favorite Status 2101 * @type { ?boolean } 2102 * @syscap SystemCapability.Multimedia.AVSession.Core 2103 * @since 10 2104 */ 2105 isFavorite?: boolean; 2106 2107 /** 2108 * Current active item id 2109 * @type { ?number } 2110 * @syscap SystemCapability.Multimedia.AVSession.Core 2111 * @since 10 2112 */ 2113 activeItemId?: number; 2114 2115 /** 2116 * Current player volume 2117 * @type { ?number } 2118 * @syscap SystemCapability.Multimedia.AVSession.Core 2119 * @since 10 2120 */ 2121 volume?: number; 2122 2123 /** 2124 * Current custom media packets 2125 * @syscap SystemCapability.Multimedia.AVSession.Core 2126 * @since 10 2127 */ 2128 extras?: {[key: string]: Object}; 2129 } 2130 2131 /** 2132 * Playback position definition 2133 * @interface PlaybackPosition 2134 * @syscap SystemCapability.Multimedia.AVSession.Core 2135 * @since 10 2136 */ 2137 interface PlaybackPosition { 2138 /** 2139 * Elapsed time(position) of this media set by the app. 2140 * @type { number } 2141 * @syscap SystemCapability.Multimedia.AVSession.Core 2142 * @since 10 2143 */ 2144 elapsedTime: number; 2145 2146 /** 2147 * Record the system time when elapsedTime is set. 2148 * @type { number } 2149 * @syscap SystemCapability.Multimedia.AVSession.Core 2150 * @since 10 2151 */ 2152 updateTime: number; 2153 } 2154 2155 /** 2156 * cast category indicating different playback scenes 2157 * @enum { number } 2158 * @syscap SystemCapability.Multimedia.AVSession.AVCast 2159 * @since 10 2160 */ 2161 enum AVCastCategory { 2162 /** 2163 * The default cast type "local", media can be routed on the same device, 2164 * including internal speakers or audio jack on the device itself, A2DP devices. 2165 * @syscap SystemCapability.Multimedia.AVSession.AVCast 2166 * @since 10 2167 */ 2168 CATEGORY_LOCAL = 0, 2169 2170 /** 2171 * The remote category indicating the media is presenting on a remote device, 2172 * the application needs to get an AVCastController to control remote playback. 2173 * @syscap SystemCapability.Multimedia.AVSession.AVCast 2174 * @since 10 2175 */ 2176 CATEGORY_REMOTE = 1, 2177 } 2178 /** 2179 * Device type definition 2180 * @enum { number } 2181 * @syscap SystemCapability.Multimedia.AVSession.Core 2182 * @since 10 2183 */ 2184 enum DeviceType { 2185 /** 2186 * A device type indicating the route is on internal speakers or audio jack on the device itself. 2187 * @syscap SystemCapability.Multimedia.AVSession.Core 2188 * @since 10 2189 */ 2190 DEVICE_TYPE_LOCAL = 0, 2191 2192 /** 2193 * A device type indicating the route is on a TV. 2194 * @syscap SystemCapability.Multimedia.AVSession.AVCast 2195 * @since 10 2196 */ 2197 DEVICE_TYPE_TV = 2, 2198 2199 /** 2200 * A device type indicating the route is on a smart speaker. 2201 * @syscap SystemCapability.Multimedia.AVSession.AVCast 2202 * @since 10 2203 */ 2204 DEVICE_TYPE_SMART_SPEAKER = 3, 2205 2206 /** 2207 * A device type indicating the route is on a bluetooth device. 2208 * @syscap SystemCapability.Multimedia.AVSession.Core 2209 * @since 10 2210 */ 2211 DEVICE_TYPE_BLUETOOTH = 10, 2212 } 2213 2214 /** 2215 * Device Information Definition 2216 * @interface DeviceInfo 2217 * @syscap SystemCapability.Multimedia.AVSession.Core 2218 * @since 10 2219 */ 2220 interface DeviceInfo { 2221 /** 2222 * The playback type supported by the device. See {@link AVCastCategory} 2223 * @syscap SystemCapability.Multimedia.AVSession.Core 2224 * @since 10 2225 */ 2226 castCategory: AVCastCategory; 2227 /** 2228 * Audio device id.The length of the audioDeviceId array is greater than 1 2229 * if output to multiple devices at the same time. 2230 * @syscap SystemCapability.Multimedia.AVSession.Core 2231 * @since 10 2232 */ 2233 deviceId: string; 2234 2235 /** 2236 * Device name. The length of the deviceName array is greater than 1 2237 * if output to multiple devices at the same time. 2238 * @syscap SystemCapability.Multimedia.AVSession.Core 2239 * @since 10 2240 */ 2241 deviceName: string; 2242 2243 /** 2244 * device type. 2245 * @syscap SystemCapability.Multimedia.AVSession.Core 2246 * @since 10 2247 */ 2248 deviceType: DeviceType; 2249 2250 /** 2251 * device ip address if available. 2252 * @syscap SystemCapability.Multimedia.AVSession.AVCast 2253 * @systemapi 2254 * @since 10 2255 */ 2256 ipAddress?: string; 2257 2258 /** 2259 * device provider which supplies the route capability. 2260 * @syscap SystemCapability.Multimedia.AVSession.AVCast 2261 * @systemapi 2262 * @since 10 2263 */ 2264 providerId?: number; 2265 } 2266 2267 /** 2268 * Target Device Information Definition 2269 * @interface OutputDeviceInfo 2270 * @syscap SystemCapability.Multimedia.AVSession.Core 2271 * @since 10 2272 */ 2273 interface OutputDeviceInfo { 2274 /** 2275 * Arrays of device information 2276 * @syscap SystemCapability.Multimedia.AVSession.Core 2277 * @since 10 2278 */ 2279 devices: Array<DeviceInfo>; 2280 } 2281 2282 /** 2283 * Loop Play Mode Definition 2284 * @enum { number } 2285 * @syscap SystemCapability.Multimedia.AVSession.Core 2286 * @since 10 2287 */ 2288 enum LoopMode { 2289 /** 2290 * The default mode is sequential playback 2291 * @syscap SystemCapability.Multimedia.AVSession.Core 2292 * @since 10 2293 */ 2294 LOOP_MODE_SEQUENCE = 0, 2295 2296 /** 2297 * Single loop mode 2298 * @syscap SystemCapability.Multimedia.AVSession.Core 2299 * @since 10 2300 */ 2301 LOOP_MODE_SINGLE = 1, 2302 2303 /** 2304 * List loop mode 2305 * @syscap SystemCapability.Multimedia.AVSession.Core 2306 * @since 10 2307 */ 2308 LOOP_MODE_LIST = 2, 2309 2310 /** 2311 * Shuffle playback mode 2312 * @syscap SystemCapability.Multimedia.AVSession.Core 2313 * @since 10 2314 */ 2315 LOOP_MODE_SHUFFLE = 3, 2316 } 2317 2318 /** 2319 * Definition of current playback state 2320 * @enum { number } 2321 * @syscap SystemCapability.Multimedia.AVSession.Core 2322 * @since 10 2323 */ 2324 enum PlaybackState { 2325 /** 2326 * Initial state. The initial state of media file 2327 * @syscap SystemCapability.Multimedia.AVSession.Core 2328 * @since 10 2329 */ 2330 PLAYBACK_STATE_INITIAL = 0, 2331 2332 /** 2333 * Preparing state. Indicates that the media file is not ready to play, 2334 * the media is loading or buffering 2335 * @syscap SystemCapability.Multimedia.AVSession.Core 2336 * @since 10 2337 */ 2338 PLAYBACK_STATE_PREPARE = 1, 2339 2340 /** 2341 * Playing state. 2342 * @syscap SystemCapability.Multimedia.AVSession.Core 2343 * @since 10 2344 */ 2345 PLAYBACK_STATE_PLAY = 2, 2346 2347 /** 2348 * Paused state. 2349 * @syscap SystemCapability.Multimedia.AVSession.Core 2350 * @since 10 2351 */ 2352 PLAYBACK_STATE_PAUSE = 3, 2353 2354 /** 2355 * Fast forwarding state. 2356 * @syscap SystemCapability.Multimedia.AVSession.Core 2357 * @since 10 2358 */ 2359 PLAYBACK_STATE_FAST_FORWARD = 4, 2360 2361 /** 2362 * Rewinding state. 2363 * @syscap SystemCapability.Multimedia.AVSession.Core 2364 * @since 10 2365 */ 2366 PLAYBACK_STATE_REWIND = 5, 2367 2368 /** 2369 * Stopped state.The server will clear the media playback position and other information. 2370 * @syscap SystemCapability.Multimedia.AVSession.Core 2371 * @since 10 2372 */ 2373 PLAYBACK_STATE_STOP = 6, 2374 2375 /** 2376 * Completed state. 2377 * @syscap SystemCapability.Multimedia.AVSession.Core 2378 * @since 10 2379 */ 2380 PLAYBACK_STATE_COMPLETED = 7, 2381 2382 /** 2383 * Released state. 2384 * @syscap SystemCapability.Multimedia.AVSession.Core 2385 * @since 10 2386 */ 2387 PLAYBACK_STATE_RELEASED = 8, 2388 2389 /** 2390 * error state. 2391 * @syscap SystemCapability.Multimedia.AVSession.Core 2392 * @since 10 2393 */ 2394 PLAYBACK_STATE_ERROR = 9, 2395 } 2396 2397 /** 2398 * The description of the session 2399 * @interface AVSessionDescriptor 2400 * @syscap SystemCapability.Multimedia.AVSession.Manager 2401 * @systemapi 2402 * @since 9 2403 */ 2404 interface AVSessionDescriptor { 2405 /** 2406 * Unique ID of the session 2407 * @type { string } 2408 * @syscap SystemCapability.Multimedia.AVSession.Manager 2409 * @systemapi 2410 * @since 9 2411 */ 2412 sessionId: string; 2413 2414 /** 2415 * Session type, currently supports audio or video 2416 * @syscap SystemCapability.Multimedia.AVSession.Manager 2417 * @systemapi 2418 * @since 9 2419 */ 2420 type: AVSessionType; 2421 2422 /** 2423 * The session tag set by the application 2424 * @type { string } 2425 * @syscap SystemCapability.Multimedia.AVSession.Manager 2426 * @systemapi 2427 * @since 9 2428 */ 2429 sessionTag: string; 2430 2431 /** 2432 * The elementName of the ability that created this session. See {@link ElementName} in bundle/elementName.d.ts 2433 * @syscap SystemCapability.Multimedia.AVSession.Manager 2434 * @systemapi 2435 * @since 9 2436 */ 2437 elementName: ElementName; 2438 2439 /** 2440 * Session active state 2441 * @type { boolean } 2442 * @syscap SystemCapability.Multimedia.AVSession.Manager 2443 * @systemapi 2444 * @since 9 2445 */ 2446 isActive: boolean; 2447 2448 /** 2449 * Is it the top priority session 2450 * @type { boolean } 2451 * @syscap SystemCapability.Multimedia.AVSession.Manager 2452 * @systemapi 2453 * @since 9 2454 */ 2455 isTopSession: boolean; 2456 2457 /** 2458 * The current output device information. 2459 * It will be undefined if this is a local session. 2460 * @syscap SystemCapability.Multimedia.AVSession.Manager 2461 * @systemapi 2462 * @since 9 2463 */ 2464 outputDevice: OutputDeviceInfo; 2465 } 2466 2467 /** 2468 * Session controller,used to control media playback and get media information 2469 * @interface AVSessionController 2470 * @syscap SystemCapability.Multimedia.AVSession.Core 2471 * @since 10 2472 */ 2473 interface AVSessionController { 2474 /** 2475 * Unique session Id 2476 * @syscap SystemCapability.Multimedia.AVSession.Core 2477 * @since 10 2478 */ 2479 readonly sessionId: string; 2480 2481 /** 2482 * Get the playback status of the current session 2483 * @param { AsyncCallback<AVPlaybackState> } callback - The triggered asyncCallback when (getAVPlaybackState). 2484 * @throws { BusinessError } 6600101 - Session service exception. 2485 * @throws { BusinessError } 6600102 - The session does not exist. 2486 * @throws { BusinessError } 6600103 - The session controller does not exist. 2487 * @syscap SystemCapability.Multimedia.AVSession.Core 2488 * @since 10 2489 */ 2490 getAVPlaybackState(callback: AsyncCallback<AVPlaybackState>): void; 2491 2492 /** 2493 * Get the playback status of the current session 2494 * @returns { Promise<AVPlaybackState> } (AVPlaybackState) returned through promise 2495 * @throws { BusinessError } 6600101 - Session service exception. 2496 * @throws { BusinessError } 6600102 - The session does not exist. 2497 * @throws { BusinessError } 6600103 - The session controller does not exist. 2498 * @syscap SystemCapability.Multimedia.AVSession.Core 2499 * @since 10 2500 */ 2501 getAVPlaybackState(): Promise<AVPlaybackState>; 2502 2503 /** 2504 * Get the playback status of the current session 2505 * @returns { AVPlaybackState } (AVPlaybackState) returned 2506 * @throws { BusinessError } 6600101 - Session service exception. 2507 * @throws { BusinessError } 6600102 - The session does not exist. 2508 * @throws { BusinessError } 6600103 - The session controller does not exist. 2509 * @syscap SystemCapability.Multimedia.AVSession.Core 2510 * @since 10 2511 */ 2512 getAVPlaybackStateSync(): AVPlaybackState; 2513 2514 /** 2515 * Get the metadata of the current session 2516 * @param { AsyncCallback<AVMetadata> } callback - The triggered asyncCallback when (getAVMetadata). 2517 * @throws { BusinessError } 6600101 - Session service exception. 2518 * @throws { BusinessError } 6600102 - The session does not exist. 2519 * @throws { BusinessError } 6600103 - The session controller does not exist. 2520 * @syscap SystemCapability.Multimedia.AVSession.Core 2521 * @since 10 2522 */ 2523 getAVMetadata(callback: AsyncCallback<AVMetadata>): void; 2524 2525 /** 2526 * Get the metadata of the current session 2527 * @returns { Promise<AVMetadata> } (AVMetadata) returned through promise 2528 * @throws { BusinessError } 6600101 - Session service exception. 2529 * @throws { BusinessError } 6600102 - The session does not exist. 2530 * @throws { BusinessError } 6600103 - The session controller does not exist. 2531 * @syscap SystemCapability.Multimedia.AVSession.Core 2532 * @since 10 2533 */ 2534 getAVMetadata(): Promise<AVMetadata>; 2535 2536 /** 2537 * Get the metadata of the current session 2538 * @returns { AVMetadata } (AVMetadata) returned 2539 * @throws { BusinessError } 6600101 - Session service exception. 2540 * @throws { BusinessError } 6600102 - The session does not exist. 2541 * @throws { BusinessError } 6600103 - The session controller does not exist. 2542 * @syscap SystemCapability.Multimedia.AVSession.Core 2543 * @since 10 2544 */ 2545 getAVMetadataSync(): AVMetadata; 2546 2547 /** 2548 * Get the name of the playlist of the current session 2549 * @param { AsyncCallback<string> } callback - The triggered asyncCallback when (getAVQueueTitle). 2550 * @throws { BusinessError } 6600101 - Session service exception. 2551 * @throws { BusinessError } 6600102 - The session does not exist. 2552 * @throws { BusinessError } 6600103 - The session controller does not exist. 2553 * @syscap SystemCapability.Multimedia.AVSession.Core 2554 * @since 10 2555 */ 2556 getAVQueueTitle(callback: AsyncCallback<string>): void; 2557 2558 /** 2559 * Get the name of the playlist of the current session 2560 * @returns { Promise<string> } (string) returned through promise 2561 * @throws { BusinessError } 6600101 - Session service exception. 2562 * @throws { BusinessError } 6600102 - The session does not exist. 2563 * @throws { BusinessError } 6600103 - The session controller does not exist. 2564 * @syscap SystemCapability.Multimedia.AVSession.Core 2565 * @since 10 2566 */ 2567 getAVQueueTitle(): Promise<string>; 2568 2569 /** 2570 * Get the name of the playlist of the current session 2571 * @returns { string } (string) returned 2572 * @throws { BusinessError } 6600101 - Session service exception. 2573 * @throws { BusinessError } 6600102 - The session does not exist. 2574 * @throws { BusinessError } 6600103 - The session controller does not exist. 2575 * @syscap SystemCapability.Multimedia.AVSession.Core 2576 * @since 10 2577 */ 2578 getAVQueueTitleSync(): string; 2579 2580 /** 2581 * Get the playlist of the current session 2582 * @param { AsyncCallback<Array<AVQueueItem>> } callback - The triggered asyncCallback when (getAVQueueItems). 2583 * @throws { BusinessError } 6600101 - Session service exception. 2584 * @throws { BusinessError } 6600102 - The session does not exist. 2585 * @throws { BusinessError } 6600103 - The session controller does not exist. 2586 * @syscap SystemCapability.Multimedia.AVSession.Core 2587 * @since 10 2588 */ 2589 getAVQueueItems(callback: AsyncCallback<Array<AVQueueItem>>): void; 2590 2591 /** 2592 * Get the playlist of the current session 2593 * @returns { Promise<Array<AVQueueItem>> } (Array<AVQueueItem>) returned through promise 2594 * @throws { BusinessError } 6600101 - Session service exception. 2595 * @throws { BusinessError } 6600102 - The session does not exist. 2596 * @throws { BusinessError } 6600103 - The session controller does not exist. 2597 * @syscap SystemCapability.Multimedia.AVSession.Core 2598 * @since 10 2599 */ 2600 getAVQueueItems(): Promise<Array<AVQueueItem>>; 2601 2602 /** 2603 * Get the playlist of the current session 2604 * @returns { Array<AVQueueItem> } (Array<AVQueueItem>) returned 2605 * @throws { BusinessError } 6600101 - Session service exception. 2606 * @throws { BusinessError } 6600102 - The session does not exist. 2607 * @throws { BusinessError } 6600103 - The session controller does not exist. 2608 * @syscap SystemCapability.Multimedia.AVSession.Core 2609 * @since 10 2610 */ 2611 getAVQueueItemsSync(): Array<AVQueueItem>; 2612 2613 /** 2614 * Set the item in the playlist to be played 2615 * @param { number } itemId - The serial number of the item to be played 2616 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully 2617 * @throws { BusinessError } 401 - parameter check failed 2618 * @throws { BusinessError } 6600101 - Session service exception. 2619 * @throws { BusinessError } 6600102 - The session does not exist. 2620 * @throws { BusinessError } 6600103 - The session controller does not exist. 2621 * @syscap SystemCapability.Multimedia.AVSession.Core 2622 * @since 10 2623 */ 2624 skipToQueueItem(itemId: number, callback: AsyncCallback<void>): void; 2625 2626 /** 2627 * Set the item in the playlist to be played 2628 * @param { number } itemId - The serial number of the item to be played 2629 * @returns { Promise<void> } void promise when executed successfully 2630 * @throws { BusinessError } 401 - parameter check failed 2631 * @throws { BusinessError } 6600101 - Session service exception. 2632 * @throws { BusinessError } 6600102 - The session does not exist. 2633 * @throws { BusinessError } 6600103 - The session controller does not exist. 2634 * @syscap SystemCapability.Multimedia.AVSession.Core 2635 * @since 10 2636 */ 2637 skipToQueueItem(itemId: number): Promise<void>; 2638 2639 /** 2640 * Get output device information 2641 * @param { AsyncCallback<OutputDeviceInfo> } callback - The triggered asyncCallback when (getOutputDevice). 2642 * @throws { BusinessError } 600101 - Session service exception. 2643 * @throws { BusinessError } 600103 - The session controller does not exist. 2644 * @syscap SystemCapability.Multimedia.AVSession.Core 2645 * @since 10 2646 */ 2647 getOutputDevice(callback: AsyncCallback<OutputDeviceInfo>): void; 2648 2649 /** 2650 * Get output device information 2651 * @returns { Promise<OutputDeviceInfo> } (OutputDeviceInfo) returned through promise 2652 * @throws { BusinessError } 600101 - Session service exception. 2653 * @throws { BusinessError } 600103 - The session controller does not exist. 2654 * @syscap SystemCapability.Multimedia.AVSession.Core 2655 * @since 10 2656 */ 2657 getOutputDevice(): Promise<OutputDeviceInfo>; 2658 2659 /** 2660 * Get output device information 2661 * @returns { OutputDeviceInfo } (OutputDeviceInfo) returned 2662 * @throws { BusinessError } 6600101 - Session service exception. 2663 * @throws { BusinessError } 6600103 - The session controller does not exist. 2664 * @syscap SystemCapability.Multimedia.AVSession.Core 2665 * @since 10 2666 */ 2667 getOutputDeviceSync(): OutputDeviceInfo; 2668 2669 /** 2670 * Send media key event to this session 2671 * @param { KeyEvent } event - The KeyEvent 2672 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully. 2673 * @throws { BusinessError } 401 - parameter check failed 2674 * @throws { BusinessError } 600101 - Session service exception. 2675 * @throws { BusinessError } 600102 - The session does not exist. 2676 * @throws { BusinessError } 600103 - The session controller does not exist. 2677 * @throws { BusinessError } 600105 - Invalid session command. 2678 * @throws { BusinessError } 600106 - The session is not activated. 2679 * @syscap SystemCapability.Multimedia.AVSession.Core 2680 * @since 10 2681 */ 2682 sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback<void>): void; 2683 2684 /** 2685 * Send media key event to this session 2686 * @param { KeyEvent } event - The KeyEvent 2687 * @returns { Promise<void> } void promise when executed successfully 2688 * @throws { BusinessError } 401 - parameter check failed 2689 * @throws { BusinessError } 600101 - Session service exception. 2690 * @throws { BusinessError } 600102 - The session does not exist. 2691 * @throws { BusinessError } 600103 - The session controller does not exist. 2692 * @throws { BusinessError } 600105 - Invalid session command. 2693 * @throws { BusinessError } 600106 - The session is not activated. 2694 * @syscap SystemCapability.Multimedia.AVSession.Core 2695 * @since 10 2696 */ 2697 sendAVKeyEvent(event: KeyEvent): Promise<void>; 2698 2699 /** 2700 * Get the {@link WantAgent} of this session that can launch the session ability 2701 * @param { AsyncCallback<WantAgent> } callback - The asyncCallback triggered when getting the WantAgent. 2702 * @throws { BusinessError } 6600101 - Session service exception. 2703 * @throws { BusinessError } 6600102 - The session does not exist. 2704 * @throws { BusinessError } 6600103 - The session controller does not exist. 2705 * @syscap SystemCapability.Multimedia.AVSession.Core 2706 * @since 10 2707 */ 2708 getLaunchAbility(callback: AsyncCallback<WantAgent>): void; 2709 2710 /** 2711 * Get the {@link WantAgent} of this session that can launch the session ability 2712 * @returns { Promise<WantAgent> } WantAgent promise 2713 * @throws { BusinessError } 6600101 - Session service exception. 2714 * @throws { BusinessError } 6600102 - The session does not exist. 2715 * @throws { BusinessError } 6600103 - The session controller does not exist. 2716 * @syscap SystemCapability.Multimedia.AVSession.Core 2717 * @since 10 2718 */ 2719 getLaunchAbility(): Promise<WantAgent>; 2720 2721 /** 2722 * Get the adjusted playback position. The time automatically calculated by the system 2723 * taking into account factors such as playback status, playback speed, and application update time. 2724 * @returns { number } current playback position in ms.Note that the returns value of each call will be different. 2725 * @throws { BusinessError } 6600101 - Session service exception. 2726 * @throws { BusinessError } 6600103 - The session controller does not exist. 2727 * @syscap SystemCapability.Multimedia.AVSession.Core 2728 * @since 10 2729 */ 2730 getRealPlaybackPositionSync(): number; 2731 2732 /** 2733 * Check if the current session is active 2734 * @param { AsyncCallback<boolean> } callback - The triggered asyncCallback when (isActive). 2735 * @throws { BusinessError } 6600101 - Session service exception. 2736 * @throws { BusinessError } 6600102 - The session does not exist. 2737 * @throws { BusinessError } 6600103 - The session controller does not exist. 2738 * @syscap SystemCapability.Multimedia.AVSession.Core 2739 * @since 10 2740 */ 2741 isActive(callback: AsyncCallback<boolean>): void; 2742 2743 /** 2744 * Check if the current session is active 2745 * @returns { Promise<boolean> } boolean promise 2746 * @throws { BusinessError } 6600101 - Session service exception. 2747 * @throws { BusinessError } 6600102 - The session does not exist. 2748 * @throws { BusinessError } 6600103 - The session controller does not exist. 2749 * @syscap SystemCapability.Multimedia.AVSession.Core 2750 * @since 10 2751 */ 2752 isActive(): Promise<boolean>; 2753 2754 /** 2755 * Check if the current session is active 2756 * @returns { boolean } boolean 2757 * @throws { BusinessError } 6600101 - Session service exception. 2758 * @throws { BusinessError } 6600102 - The session does not exist. 2759 * @throws { BusinessError } 6600103 - The session controller does not exist. 2760 * @syscap SystemCapability.Multimedia.AVSession.Core 2761 * @since 10 2762 */ 2763 isActiveSync(): boolean; 2764 2765 /** 2766 * Destroy the server controller 2767 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully. 2768 * @throws { BusinessError } 6600101 - Session service exception. 2769 * @throws { BusinessError } 6600103 - The session controller does not exist. 2770 * @syscap SystemCapability.Multimedia.AVSession.Core 2771 * @since 10 2772 */ 2773 destroy(callback: AsyncCallback<void>): void; 2774 2775 /** 2776 * Destroy the server controller 2777 * @returns { Promise<void> } void promise when executed successfully 2778 * @throws { BusinessError } 6600101 - Session service exception. 2779 * @throws { BusinessError } 6600103 - The session controller does not exist. 2780 * @syscap SystemCapability.Multimedia.AVSession.Core 2781 * @since 10 2782 */ 2783 destroy(): Promise<void>; 2784 2785 /** 2786 * Get commands supported by the current session 2787 * @param { AsyncCallback<Array<AVControlCommandType>> } callback - The triggered asyncCallback when (getValidCommands). 2788 * @throws { BusinessError } 6600101 - Session service exception. 2789 * @throws { BusinessError } 6600102 - The session does not exist. 2790 * @throws { BusinessError } 6600103 - The session controller does not exist. 2791 * @syscap SystemCapability.Multimedia.AVSession.Core 2792 * @since 10 2793 */ 2794 getValidCommands(callback: AsyncCallback<Array<AVControlCommandType>>): void; 2795 2796 /** 2797 * Get commands supported by the current session 2798 * @returns { Promise<Array<AVControlCommandType>> } array of AVControlCommandType promise 2799 * @throws { BusinessError } 6600101 - Session service exception. 2800 * @throws { BusinessError } 6600102 - The session does not exist. 2801 * @throws { BusinessError } 6600103 - The session controller does not exist. 2802 * @syscap SystemCapability.Multimedia.AVSession.Core 2803 * @since 10 2804 */ 2805 getValidCommands(): Promise<Array<AVControlCommandType>>; 2806 2807 /** 2808 * Get commands supported by the current session 2809 * @returns {Array<AVControlCommandType> } array of AVControlCommandType 2810 * @throws { BusinessError } 6600101 - Session service exception. 2811 * @throws { BusinessError } 6600102 - The session does not exist. 2812 * @throws { BusinessError } 6600103 - The session controller does not exist. 2813 * @syscap SystemCapability.Multimedia.AVSession.Core 2814 * @since 10 2815 */ 2816 getValidCommandsSync(): Array<AVControlCommandType>; 2817 2818 /** 2819 * Send control commands to this session 2820 * @param { AVControlCommand } command - The command to be sent. See {@link AVControlCommand} 2821 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully. 2822 * @throws { BusinessError } 401 - parameter check failed 2823 * @throws { BusinessError } 6600101 - Session service exception. 2824 * @throws { BusinessError } 6600102 - The session does not exist. 2825 * @throws { BusinessError } 6600103 - The session controller does not exist. 2826 * @throws { BusinessError } 6600105 - Invalid session command. 2827 * @throws { BusinessError } 6600106 - The session is not activated. 2828 * @throws { BusinessError } 6600107 - Too many commands or events. 2829 * @syscap SystemCapability.Multimedia.AVSession.Core 2830 * @since 10 2831 */ 2832 sendControlCommand(command: AVControlCommand, callback: AsyncCallback<void>): void; 2833 2834 /** 2835 * Send control commands to this session 2836 * @param { AVControlCommand } command - The command to be sent. See {@link AVControlCommand} 2837 * @returns { Promise<void> } void promise when executed successfully 2838 * @throws { BusinessError } 401 - parameter check failed 2839 * @throws { BusinessError } 6600101 - Session service exception. 2840 * @throws { BusinessError } 6600102 - The session does not exist. 2841 * @throws { BusinessError } 6600103 - The session controller does not exist. 2842 * @throws { BusinessError } 6600105 - Invalid session command. 2843 * @throws { BusinessError } 6600106 - The session is not activated. 2844 * @throws { BusinessError } 6600107 - Too many commands or events. 2845 * @syscap SystemCapability.Multimedia.AVSession.Core 2846 * @since 10 2847 */ 2848 sendControlCommand(command: AVControlCommand): Promise<void>; 2849 2850 /** 2851 * Send common commands to this session 2852 * @param { string } command - The command name to be sent. 2853 * @param { object } args - The parameters of session event 2854 * @param { AsyncCallback<void> } callback - The asyncCallback triggered when the command is executed successfully. 2855 * @throws { BusinessError } 401 - parameter check failed 2856 * @throws { BusinessError } 6600101 - Session service exception. 2857 * @throws { BusinessError } 6600102 - The session does not exist. 2858 * @throws { BusinessError } 6600103 - The session controller does not exist. 2859 * @throws { BusinessError } 6600105 - Invalid session command. 2860 * @throws { BusinessError } 6600106 - The session is not activated. 2861 * @throws { BusinessError } 6600107 - Too many commands or events. 2862 * @syscap SystemCapability.Multimedia.AVSession.Core 2863 * @since 10 2864 */ 2865 sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback<void>): void; 2866 2867 /** 2868 * Send common commands to this session 2869 * @param { string } command - The command name to be sent. 2870 * @param { object } args - The parameters of session event 2871 * @returns { Promise<void> } void promise when executed successfully 2872 * @throws { BusinessError } 401 - parameter check failed 2873 * @throws { BusinessError } 6600101 - Session service exception. 2874 * @throws { BusinessError } 6600102 - The session does not exist. 2875 * @throws { BusinessError } 6600103 - The session controller does not exist. 2876 * @throws { BusinessError } 6600105 - Invalid session command. 2877 * @throws { BusinessError } 6600106 - The session is not activated. 2878 * @throws { BusinessError } 6600107 - Too many commands or events. 2879 * @syscap SystemCapability.Multimedia.AVSession.Core 2880 * @since 10 2881 */ 2882 sendCommonCommand(command: string, args: {[key: string]: Object}): Promise<void>; 2883 2884 /** 2885 * Get custom media packets provided by the corresponding session 2886 * @param { AsyncCallback<{[key: string]: Object}> } callback - The triggered asyncCallback when (getExtras). 2887 * @throws { BusinessError } 401 - parameter check failed 2888 * @throws { BusinessError } 6600101 - Session service exception. 2889 * @throws { BusinessError } 6600102 - The session does not exist. 2890 * @throws { BusinessError } 6600103 - The session controller does not exist. 2891 * @throws { BusinessError } 6600105 - Invalid session command. 2892 * @throws { BusinessError } 6600107 - Too many commands or events. 2893 * @syscap SystemCapability.Multimedia.AVSession.Core 2894 * @since 10 2895 */ 2896 getExtras(callback: AsyncCallback<{[key: string]: Object}>): void; 2897 2898 /** 2899 * Get custom media packets provided by the corresponding session 2900 * @returns { Promise<{[key: string]: Object}> } the parameters of extras 2901 * @throws { BusinessError } 401 - parameter check failed 2902 * @throws { BusinessError } 6600101 - Session service exception. 2903 * @throws { BusinessError } 6600102 - The session does not exist. 2904 * @throws { BusinessError } 6600103 - The session controller does not exist. 2905 * @throws { BusinessError } 6600105 - Invalid session command. 2906 * @throws { BusinessError } 6600107 - Too many commands or events. 2907 * @syscap SystemCapability.Multimedia.AVSession.Core 2908 * @since 10 2909 */ 2910 getExtras(): Promise<{[key: string]: Object}>; 2911 2912 /** 2913 * Register metadata changed callback 2914 * @param { 'metadataChange' } type 2915 * @param { Array<keyof AVMetadata> | 'all' } filter - The properties of {@link AVMetadata} that you cared about 2916 * @param { function } callback - The callback used to handle metadata changed event. 2917 * The callback function provides the {@link AVMetadata} parameter. 2918 * It only contains the properties set in the filter. 2919 * @throws { BusinessError } 401 - parameter check failed 2920 * @throws { BusinessError } 6600101 - Session service exception. 2921 * @throws { BusinessError } 6600103 - The session controller does not exist. 2922 * @syscap SystemCapability.Multimedia.AVSession.Core 2923 * @since 10 2924 */ 2925 on(type: 'metadataChange', filter: Array<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void); 2926 2927 /** 2928 * Unregister metadata changed callback 2929 * @param { 'metadataChange' } type 2930 * @param { function } callback - The callback used to handle metadata changed event. 2931 * The callback function provides the {@link AVMetadata} parameter. 2932 * It only contains the properties set in the filter. 2933 * @throws { BusinessError } 401 - parameter check failed 2934 * @throws { BusinessError } 6600101 - Session service exception. 2935 * @throws { BusinessError } 6600103 - The session controller does not exist. 2936 * @syscap SystemCapability.Multimedia.AVSession.Core 2937 * @since 10 2938 */ 2939 off(type: 'metadataChange', callback?: (data: AVMetadata) => void); 2940 2941 /** 2942 * Register playback state changed callback 2943 * @param { 'playbackStateChange' } type 2944 * @param { Array<keyof AVPlaybackState> | 'all' } filter - The properties of {@link AVPlaybackState} that you cared about 2945 * @param { function } callback - The callback used to handle playback state changed event. 2946 * The callback function provides the {@link AVPlaybackState} parameter. 2947 * @throws { BusinessError } 401 - parameter check failed 2948 * @throws { BusinessError } 6600101 - Session service exception. 2949 * @throws { BusinessError } 6600103 - The session controller does not exist. 2950 * @syscap SystemCapability.Multimedia.AVSession.Core 2951 * @since 10 2952 */ 2953 on(type: 'playbackStateChange', filter: Array<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void); 2954 2955 /** 2956 * Unregister playback state changed callback 2957 * @param { 'playbackStateChange' } type 2958 * @param { function } callback - The callback used to handle playback state changed event. 2959 * The callback function provides the {@link AVPlaybackState} parameter. 2960 * @throws { BusinessError } 401 - parameter check failed 2961 * @throws { BusinessError } 6600101 - Session service exception. 2962 * @throws { BusinessError } 6600103 - The session controller does not exist. 2963 * @syscap SystemCapability.Multimedia.AVSession.Core 2964 * @since 10 2965 */ 2966 off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void); 2967 2968 /** 2969 * Register current session destroyed callback 2970 * @param { 'sessionDestroy' } type 2971 * @param { function } callback - The callback used to handle current session destroyed event. 2972 * @throws { BusinessError } 401 - parameter check failed 2973 * @throws { BusinessError } 6600101 - Session service exception. 2974 * @throws { BusinessError } 6600103 - The session controller does not exist. 2975 * @syscap SystemCapability.Multimedia.AVSession.Core 2976 * @since 10 2977 */ 2978 on(type: 'sessionDestroy', callback: () => void); 2979 2980 /** 2981 * Unregister current session destroyed callback 2982 * @param { 'sessionDestroy' } type - 'sessionDestroy' 2983 * @param { function } callback - The callback used to handle current session destroyed event. 2984 * @throws { BusinessError } 401 - parameter check failed 2985 * @throws { BusinessError } 6600101 - Session service exception. 2986 * @throws { BusinessError } 6600103 - The session controller does not exist. 2987 * @syscap SystemCapability.Multimedia.AVSession.Core 2988 * @since 10 2989 */ 2990 off(type: 'sessionDestroy', callback?: () => void); 2991 2992 /** 2993 * Register the active state of this session changed callback 2994 * @param { 'activeStateChange' } type - 'activeStateChange' 2995 * @param { function } callback - The callback used to handle the active state of this session changed event. 2996 * The callback function provides the changed session state. 2997 * @throws { BusinessError } 401 - parameter check failed 2998 * @throws { BusinessError } 6600101 - Session service exception. 2999 * @throws { BusinessError } 6600103 - The session controller does not exist. 3000 * @syscap SystemCapability.Multimedia.AVSession.Core 3001 * @since 10 3002 */ 3003 on(type: 'activeStateChange', callback: (isActive: boolean) => void); 3004 3005 /** 3006 * Unregister the active state of this session changed callback 3007 * @param { 'activeStateChange' } type - 'activeStateChange' 3008 * @param { function } callback - The callback used to handle the active state of this session changed event. 3009 * The callback function provides the changed session state. 3010 * @throws { BusinessError } 401 - parameter check failed 3011 * @throws { BusinessError } 6600101 - Session service exception. 3012 * @throws { BusinessError } 6600103 - The session controller does not exist. 3013 * @syscap SystemCapability.Multimedia.AVSession.Core 3014 * @since 10 3015 */ 3016 off(type: 'activeStateChange', callback?: (isActive: boolean) => void); 3017 3018 /** 3019 * Register the valid commands of the session changed callback 3020 * @param { 'validCommandChange' } type - 'validCommandChange' 3021 * @param { function } callback - The callback used to handle the changes. 3022 * The callback function provides an array of AVControlCommandType. 3023 * @throws { BusinessError } 401 - parameter check failed 3024 * @throws { BusinessError } 6600101 - Session service exception. 3025 * @throws { BusinessError } 6600103 - The session controller does not exist. 3026 * @syscap SystemCapability.Multimedia.AVSession.Core 3027 * @since 10 3028 */ 3029 on(type: 'validCommandChange', callback: (commands: Array<AVControlCommandType>) => void); 3030 3031 /** 3032 * Unregister the valid commands of the session changed callback 3033 * @param { 'validCommandChange' } type - 'validCommandChange' 3034 * @param { function } callback - The callback used to handle the changes. 3035 * The callback function provides an array of AVControlCommandType. 3036 * @throws { BusinessError } 401 - parameter check failed 3037 * @throws { BusinessError } 6600101 - Session service exception. 3038 * @throws { BusinessError } 6600103 - The session controller does not exist. 3039 * @syscap SystemCapability.Multimedia.AVSession.Core 3040 * @since 10 3041 */ 3042 off(type: 'validCommandChange', callback?: (commands: Array<AVControlCommandType>) => void); 3043 3044 /** 3045 * Register session output device change callback 3046 * @param { 'outputDeviceChange' } type - Registration Type 'outputDeviceChange' 3047 * @param { function } callback - Used to handle output device changed. 3048 * The callback provide the new device info {@link OutputDeviceInfo} and related connection state {@link ConnectionState}. 3049 * @throws { BusinessError } 401 - parameter check failed 3050 * @throws { BusinessError } 6600101 - Session service exception 3051 * @throws { BusinessError } 6600103 - The session controller does not exist 3052 * @syscap SystemCapability.Multimedia.AVSession.Core 3053 * @since 10 3054 */ 3055 on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void; 3056 3057 /** 3058 * Unregister session output device change callback 3059 * @param { 'outputDeviceChange' } type - Registration Type 'outputDeviceChange' 3060 * @param { function } callback - Used to handle output device changed. 3061 * The callback provide the new device info {@link OutputDeviceInfo} and related connection state {@link ConnectionState}. 3062 * @throws { BusinessError } 401 - parameter check failed 3063 * @throws { BusinessError } 6600101 - Session service exception 3064 * @throws { BusinessError } 6600103 - The session controller does not exist 3065 * @syscap SystemCapability.Multimedia.AVSession.Core 3066 * @since 10 3067 */ 3068 off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void; 3069 3070 /** 3071 * Register session event callback 3072 * @param { 'sessionEvent' } type - 'sessionEvent' 3073 * @param { function } callback - The callback used to handle session event changed event. 3074 * The callback function provides the event string and key-value pair parameters. 3075 * @throws { BusinessError } 401 - parameter check failed 3076 * @throws { BusinessError } 6600101 - Session service exception. 3077 * @throws { BusinessError } 6600103 - The session controller does not exist. 3078 * @syscap SystemCapability.Multimedia.AVSession.Core 3079 * @since 10 3080 */ 3081 on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key: string]: Object}) => void): void; 3082 3083 /** 3084 * Unregister session event callback 3085 * @param { 'sessionEvent' } type - 'sessionEvent' 3086 * @param { function } callback - Used to cancel a specific listener 3087 * The callback function provides the event string and key-value pair parameters. 3088 * @throws { BusinessError } 401 - parameter check failed 3089 * @throws { BusinessError } 6600101 - Session service exception. 3090 * @throws { BusinessError } 6600103 - The session controller does not exist. 3091 * @syscap SystemCapability.Multimedia.AVSession.Core 3092 * @since 10 3093 */ 3094 off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key: string]: Object}) => void): void; 3095 3096 /** 3097 * Register session playlist change callback 3098 * @param { 'queueItemsChange' } type - Registration Type 'queueItemsChange' 3099 * @param { function } callback - Used to handle playlist changed. 3100 * The callback provides the new array of AVQueueItem {@link AVQueueItem} 3101 * @throws { BusinessError } 401 - parameter check failed 3102 * @throws { BusinessError } 6600101 - Session service exception. 3103 * @throws { BusinessError } 6600103 - The session controller does not exist. 3104 * @syscap SystemCapability.Multimedia.AVSession.Core 3105 * @since 10 3106 */ 3107 on(type: 'queueItemsChange', callback: (items: Array<AVQueueItem>) => void): void; 3108 3109 /** 3110 * Unregister session playlist change callback 3111 * @param { 'queueItemsChange' } type - Registration Type 'queueItemsChange' 3112 * @param { function } callback - Used to handle playlist changed. 3113 * The callback provides the new array of AVQueueItem {@link AVQueueItem} 3114 * @throws { BusinessError } 401 - parameter check failed 3115 * @throws { BusinessError } 6600101 - Session service exception. 3116 * @throws { BusinessError } 6600103 - The session controller does not exist. 3117 * @syscap SystemCapability.Multimedia.AVSession.Core 3118 * @since 10 3119 */ 3120 off(type: 'queueItemsChange', callback?: (items: Array<AVQueueItem>) => void): void; 3121 3122 /** 3123 * Register the name of session playlist change callback 3124 * @param { 'queueTitleChange' } type - Registration Type 'queueTitleChange' 3125 * @param { function } callback - Used to handle name of playlist changed. 3126 * The callback provides the new name. 3127 * @throws { BusinessError } 401 - parameter check failed 3128 * @throws { BusinessError } 6600101 - Session service exception. 3129 * @throws { BusinessError } 6600103 - The session controller does not exist. 3130 * @syscap SystemCapability.Multimedia.AVSession.Core 3131 * @since 10 3132 */ 3133 on(type: 'queueTitleChange', callback: (title: string) => void): void; 3134 3135 /** 3136 * Unregister the name of session playlist change callback 3137 * @param { 'queueTitleChange' } type - Registration Type 'queueTitleChange' 3138 * @param { function } callback - Used to handle name of playlist changed. 3139 * The callback provides the new name. 3140 * @throws { BusinessError } 401 - parameter check failed 3141 * @throws { BusinessError } 6600101 - Session service exception. 3142 * @throws { BusinessError } 6600103 - The session controller does not exist. 3143 * @syscap SystemCapability.Multimedia.AVSession.Core 3144 * @since 10 3145 */ 3146 off(type: 'queueTitleChange', callback?: (title: string) => void): void; 3147 3148 /** 3149 * Register the custom media packets change callback 3150 * @param { 'extrasChange' } type - Registration Type 'extrasChange' 3151 * @param { function } callback - Used to handle custom media packets changed. 3152 * The callback provides the new media packets. 3153 * @throws { BusinessError } 401 - parameter check failed 3154 * @throws { BusinessError } 6600101 - Session service exception. 3155 * @throws { BusinessError } 6600103 - The session controller does not exist. 3156 * @syscap SystemCapability.Multimedia.AVSession.Core 3157 * @since 10 3158 */ 3159 on(type: 'extrasChange', callback: (extras: {[key: string]: Object}) => void): void; 3160 3161 /** 3162 * Unregister the custom media packets change callback 3163 * @param { 'extrasChange' } type - Registration Type 'extrasChange' 3164 * @param { function } callback - Used to handle custom media packets changed. 3165 * The callback provides the new media packets. 3166 * @throws { BusinessError } 401 - parameter check failed 3167 * @throws { BusinessError } 6600101 - Session service exception. 3168 * @throws { BusinessError } 6600103 - The session controller does not exist. 3169 * @syscap SystemCapability.Multimedia.AVSession.Core 3170 * @since 10 3171 */ 3172 off(type: 'extrasChange', callback?: (extras: {[key: string]: Object}) => void): void; 3173 } 3174 3175 /** 3176 * The type of control command 3177 * @syscap SystemCapability.Multimedia.AVSession.Core 3178 * @since 10 3179 */ 3180 type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 3181 'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite'; 3182 3183 /** 3184 * The definition of command to be sent to the session 3185 * @interface AVControlCommand 3186 * @syscap SystemCapability.Multimedia.AVSession.Core 3187 * @since 10 3188 */ 3189 interface AVControlCommand { 3190 /** 3191 * The command value {@link AVControlCommandType} 3192 * @syscap SystemCapability.Multimedia.AVSession.Core 3193 * @since 10 3194 */ 3195 command: AVControlCommandType; 3196 3197 /** 3198 * parameter of the command. Whether this command requires parameters, see {@link AVSessionCommand} 3199 * seek command requires a number parameter 3200 * setSpeed command requires a number parameter 3201 * setLoopMode command requires a {@link LoopMode} parameter. 3202 * toggleFavorite command requires assetId {@link AVMetadata.assetId} parameter 3203 * other commands need no parameter 3204 * @syscap SystemCapability.Multimedia.AVSession.Core 3205 * @since 10 3206 */ 3207 parameter?: LoopMode | string | number; 3208 } 3209 3210 /** 3211 * Enumerates ErrorCode types, returns in BusinessError.code. 3212 * @enum { number } 3213 * @syscap SystemCapability.Multimedia.AVSession.Core 3214 * @since 10 3215 */ 3216 enum AVSessionErrorCode { 3217 /** 3218 * Session service exception. 3219 * @syscap SystemCapability.Multimedia.AVSession.Core 3220 * @since 10 3221 */ 3222 ERR_CODE_SERVICE_EXCEPTION = 6600101, 3223 3224 /** 3225 * The session does not exist 3226 * @syscap SystemCapability.Multimedia.AVSession.Core 3227 * @since 10 3228 */ 3229 ERR_CODE_SESSION_NOT_EXIST = 6600102, 3230 3231 /** 3232 * The session controller does not exist. 3233 * @syscap SystemCapability.Multimedia.AVSession.Core 3234 * @since 10 3235 */ 3236 ERR_CODE_CONTROLLER_NOT_EXIST = 6600103, 3237 3238 /** 3239 * The remote session connection failed. 3240 * @syscap SystemCapability.Multimedia.AVSession.Core 3241 * @since 10 3242 */ 3243 ERR_CODE_REMOTE_CONNECTION_ERR = 6600104, 3244 3245 /** 3246 * Invalid session command. 3247 * @syscap SystemCapability.Multimedia.AVSession.Core 3248 * @since 10 3249 */ 3250 ERR_CODE_COMMAND_INVALID = 6600105, 3251 3252 /** 3253 * The session is not activated. 3254 * @syscap SystemCapability.Multimedia.AVSession.Core 3255 * @since 10 3256 */ 3257 ERR_CODE_SESSION_INACTIVE = 6600106, 3258 3259 /** 3260 * Too many commands or events. 3261 * @syscap SystemCapability.Multimedia.AVSession.Core 3262 * @since 10 3263 */ 3264 ERR_CODE_MESSAGE_OVERLOAD = 6600107, 3265 3266 /** 3267 * Device connecting failed. 3268 * @syscap SystemCapability.Multimedia.AVSession.Core 3269 * @since 10 3270 */ 3271 ERR_CODE_DEVICE_CONNECTION_FAILED = 6600108, 3272 3273 /** 3274 * The remote connection is not established. 3275 * @syscap SystemCapability.Multimedia.AVSession.Core 3276 * @since 10 3277 */ 3278 ERR_CODE_REMOTE_CONNECTION_NOT_EXIST = 6600109, 3279 } 3280} 3281 3282export default avSession; 3283