1/* 2* Copyright (C) 2021 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 { ErrorCallback, AsyncCallback, Callback } from './@ohos.base'; 17import audio from "./@ohos.multimedia.audio"; 18import type { SoundPool as _SoundPool } from './multimedia/soundPool'; 19import type { PlayParameters as _PlayParameters } from './multimedia/soundPool'; 20 21/** 22 * @namespace media 23 * @since 6 24 */ 25declare namespace media { 26 /** 27 * Creates an AVPlayer instance. 28 * @param { AsyncCallback<AVPlayer> } callback - used to return AVPlayer instance if the operation is successful; returns null otherwise. 29 * @throws { BusinessError } 5400101 - No memory. Return by callback. 30 * @syscap SystemCapability.Multimedia.Media.AVPlayer 31 * @since 9 32 */ 33 function createAVPlayer(callback: AsyncCallback<AVPlayer>): void; 34 35 /** 36 * Creates an AVPlayer instance. 37 * @returns { Promise<AVPlayer> } A Promise instance used to return AVPlayer instance if the operation is successful; returns null otherwise. 38 * @throws { BusinessError } 5400101 - No memory. Return by promise. 39 * @syscap SystemCapability.Multimedia.Media.AVPlayer 40 * @since 9 41 */ 42 function createAVPlayer(): Promise<AVPlayer>; 43 44 /** 45 * Creates an AVRecorder instance. 46 * @param { AsyncCallback<AVRecorder> } callback - used to return AVRecorder instance if the operation is successful; returns null otherwise. 47 * @throws { BusinessError } 5400101 - No memory. Return by callback. 48 * @syscap SystemCapability.Multimedia.Media.AVRecorder 49 * @since 9 50 */ 51 function createAVRecorder(callback: AsyncCallback<AVRecorder>): void; 52 53 /** 54 * Creates an AVRecorder instance. 55 * @returns { Promise<AVRecorder> } A Promise instance used to return AVRecorder instance if the operation is successful; returns null otherwise. 56 * @throws { BusinessError } 5400101 - No memory. Return by promise. 57 * @syscap SystemCapability.Multimedia.Media.AVRecorder 58 * @since 9 59 */ 60 function createAVRecorder(): Promise<AVRecorder>; 61 62 /** 63 * Creates an AudioPlayer instance. 64 * @returns { AudioPlayer } Returns an AudioPlayer instance if the operation is successful; returns null otherwise. 65 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 66 * @since 6 67 * @deprecated since 9 68 * @useinstead ohos.multimedia.media/media#createAVPlayer 69 */ 70 function createAudioPlayer(): AudioPlayer; 71 72 /** 73 * Creates an AudioRecorder instance. 74 * @returns { AudioRecorder } Returns an AudioRecorder instance if the operation is successful; returns null otherwise. 75 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 76 * @since 6 77 * @deprecated since 9 78 * @useinstead ohos.multimedia.media/media#createAVRecorder 79 */ 80 function createAudioRecorder(): AudioRecorder; 81 82 /** 83 * Creates an VideoPlayer instance. 84 * @param { AsyncCallback<VideoPlayer> } callback - used to return AudioPlayer instance if the operation is successful; returns null otherwise. 85 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 86 * @since 8 87 * @deprecated since 9 88 * @useinstead ohos.multimedia.media/media#createAVPlayer 89 */ 90 function createVideoPlayer(callback: AsyncCallback<VideoPlayer>): void; 91 92 /** 93 * Creates an VideoPlayer instance. 94 * @returns { Promise<VideoPlayer> } A Promise instance used to return VideoPlayer instance if the operation is successful; returns null otherwise. 95 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 96 * @since 8 97 * @deprecated since 9 98 * @useinstead ohos.multimedia.media/media#createAVPlayer 99 */ 100 function createVideoPlayer(): Promise<VideoPlayer>; 101 102 /** 103 * The maintenance of this interface has been stopped since version api 9. Please use AVRecorder 104 * Creates an VideoRecorder instance. 105 * @param { AsyncCallback<VideoRecorder> } callback - used to return AudioPlayer instance if the operation is successful; returns null otherwise. 106 * @throws { BusinessError } 5400101 - No memory. Return by callback. 107 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 108 * @systemapi 109 * @since 9 110 */ 111 function createVideoRecorder(callback: AsyncCallback<VideoRecorder>): void; 112 113 /** 114 * The maintenance of this interface has been stopped since version api 9. Please use AVRecorder 115 * Creates an VideoRecorder instance. 116 * @returns { Promise<VideoRecorder> } A Promise instance used to return VideoRecorder instance if the operation is successful; returns null otherwise. 117 * @throws { BusinessError } 5400101 - No memory. Return by promise. 118 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 119 * @systemapi 120 * @since 9 121 */ 122 function createVideoRecorder(): Promise<VideoRecorder>; 123 124 /** 125 * Creates a soundPool instance. 126 * 127 * @param {number} maxStreams The maximum number of simultaneous streams for this soundPool instance 128 * @param {audio.AudioRendererInfo} audioRenderInfo Audio renderer information 129 * @param {AsyncCallback<SoundPool>} callback Callback used to return soundPool instance if the operation is successful; returns null otherwise. 130 * @throws { BusinessError } 5400101 - No memory. Return by callback. 131 * @syscap SystemCapability.Multimedia.Media.SoundPool 132 * @since 10 133 */ 134 function createSoundPool( 135 maxStreams: number, 136 audioRenderInfo: audio.AudioRendererInfo, 137 callback: AsyncCallback<SoundPool> 138 ): void; 139 140 /** 141 * Creates a soundPool instance. 142 * 143 * @param {number} maxStreams The maximum number of simultaneous streams for this soundPool instance 144 * @param {audio.AudioRendererInfo} audioRenderInfo Audio renderer information 145 * @returns {Promise<SoundPool>} A Promise instance used to return SoundPool instance if the operation is successful; returns null otherwise. 146 * @throws { BusinessError } 5400101 - No memory. Return by promise. 147 * @syscap SystemCapability.Multimedia.Media.SoundPool 148 * @since 10 149 */ 150 function createSoundPool(maxStreams: number, audioRenderInfo: audio.AudioRendererInfo): Promise<SoundPool>; 151 152 /** 153 * Manages and plays sound. Before calling an SoundPool method, you must use createSoundPool() 154 * to create an SoundPool instance. 155 * 156 * @syscap SystemCapability.Multimedia.Media.SoundPool 157 * @since 10 158 */ 159 type SoundPool = _SoundPool; 160 161 /** 162 * Describes play parameters. 163 * 164 * @syscap SystemCapability.Multimedia.Media.SoundPool 165 * @since 10 166 */ 167 type PlayParameters = _PlayParameters; 168 169 /** 170 * Enumerates state change reason. 171 * 172 * @enum { number } 173 * @syscap SystemCapability.Multimedia.Media.Core 174 * @since 9 175 */ 176 enum StateChangeReason { 177 /** 178 * State changed by user operation. 179 * @syscap SystemCapability.Multimedia.Media.Core 180 * @since 9 181 */ 182 USER = 1, 183 184 /** 185 * State changed by background action. 186 * @syscap SystemCapability.Multimedia.Media.Core 187 * @since 9 188 */ 189 BACKGROUND = 2, 190 } 191 192 /** 193 * Enumerates ErrorCode types, return in BusinessError::code. 194 * 195 * @enum { number } 196 * @syscap SystemCapability.Multimedia.Media.Core 197 * @since 9 198 */ 199 enum AVErrorCode { 200 /** 201 * Operation success. 202 * @syscap SystemCapability.Multimedia.Media.Core 203 * @since 9 204 */ 205 AVERR_OK = 0, 206 207 /** 208 * Permission denied. 209 * @syscap SystemCapability.Multimedia.Media.Core 210 * @since 9 211 */ 212 AVERR_NO_PERMISSION = 201, 213 214 /** 215 * Invalid parameter. 216 * @syscap SystemCapability.Multimedia.Media.Core 217 * @since 9 218 */ 219 AVERR_INVALID_PARAMETER = 401, 220 221 /** 222 * The api is not supported in the current version. 223 * @syscap SystemCapability.Multimedia.Media.Core 224 * @since 9 225 */ 226 AVERR_UNSUPPORT_CAPABILITY = 801, 227 228 /** 229 * The system memory is insufficient or the number of services reaches the upper limit. 230 * @syscap SystemCapability.Multimedia.Media.Core 231 * @since 9 232 */ 233 AVERR_NO_MEMORY = 5400101, 234 235 /** 236 * Current status does not allow or do not have permission to perform this operation. 237 * @syscap SystemCapability.Multimedia.Media.Core 238 * @since 9 239 */ 240 AVERR_OPERATE_NOT_PERMIT = 5400102, 241 242 /** 243 * Data flow exception information. 244 * @syscap SystemCapability.Multimedia.Media.Core 245 * @since 9 246 */ 247 AVERR_IO = 5400103, 248 249 /** 250 * System or network response timeout. 251 * @syscap SystemCapability.Multimedia.Media.Core 252 * @since 9 253 */ 254 AVERR_TIMEOUT = 5400104, 255 256 /** 257 * Service process died. 258 * @syscap SystemCapability.Multimedia.Media.Core 259 * @since 9 260 */ 261 AVERR_SERVICE_DIED = 5400105, 262 263 /** 264 * Unsupported media format. 265 * @syscap SystemCapability.Multimedia.Media.Core 266 * @since 9 267 */ 268 AVERR_UNSUPPORT_FORMAT = 5400106, 269 } 270 271 /** 272 * Describes AVPlayer states. 273 * @syscap SystemCapability.Multimedia.Media.AVPlayer 274 * @since 9 275 276 */ 277 type AVPlayerState = 'idle' | 'initialized' | 'prepared' | 'playing' | 'paused' | 'completed' | 'stopped' | 'released' | 'error'; 278 279 /** 280 * Manages and plays media. Before calling an AVPlayer method, you must use createAVPlayer() 281 * to create an AVPlayer instance. 282 * 283 * @typedef AVPlayer 284 * @syscap SystemCapability.Multimedia.Media.AVPlayer 285 * @since 9 286 */ 287 interface AVPlayer { 288 /** 289 * Prepare audio/video playback, it will request resource for playing. 290 * @param { AsyncCallback<void> } callback - instance used to return when prepare completed. 291 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 292 * @throws { BusinessError } 5400106 - Unsupport format. Return by callback. 293 * @syscap SystemCapability.Multimedia.Media.AVPlayer 294 * @since 9 295 */ 296 prepare(callback: AsyncCallback<void>): void; 297 298 /** 299 * Prepare audio/video playback, it will request resource for playing. 300 * @returns { Promise<void> } A Promise instance used to return when prepare completed. 301 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 302 * @throws { BusinessError } 5400106 - Unsupport format. Return by promise. 303 * @syscap SystemCapability.Multimedia.Media.AVPlayer 304 * @since 9 305 */ 306 prepare(): Promise<void>; 307 308 /** 309 * Play audio/video playback. 310 * @param { AsyncCallback<void> } callback - instance used to return when play completed. 311 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 312 * @syscap SystemCapability.Multimedia.Media.AVPlayer 313 * @since 9 314 */ 315 play(callback: AsyncCallback<void>): void; 316 317 /** 318 * Play audio/video playback. 319 * @returns { Promise<void> } A Promise instance used to return when play completed. 320 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 321 * @syscap SystemCapability.Multimedia.Media.AVPlayer 322 * @since 9 323 */ 324 play(): Promise<void>; 325 326 /** 327 * Pause audio/video playback. 328 * @param { AsyncCallback<void> } callback - instance used to return when pause completed. 329 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 330 * @syscap SystemCapability.Multimedia.Media.AVPlayer 331 * @since 9 332 */ 333 pause(callback: AsyncCallback<void>): void; 334 335 /** 336 * Pause audio/video playback. 337 * @returns { Promise<void> } A Promise instance used to return when pause completed. 338 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 339 * @syscap SystemCapability.Multimedia.Media.AVPlayer 340 * @since 9 341 */ 342 pause(): Promise<void>; 343 344 /** 345 * Stop audio/video playback. 346 * @param { AsyncCallback<void> } callback - instance used to return when stop completed. 347 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 348 * @syscap SystemCapability.Multimedia.Media.AVPlayer 349 * @since 9 350 */ 351 stop(callback: AsyncCallback<void>): void; 352 353 /** 354 * Stop audio/video playback. 355 * @returns { Promise<void> } A Promise instance used to return when stop completed. 356 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 357 * @syscap SystemCapability.Multimedia.Media.AVPlayer 358 * @since 9 359 */ 360 stop(): Promise<void>; 361 362 /** 363 * Reset AVPlayer, it will to idle state and can set src again. 364 * @param { AsyncCallback<void> } callback - instance used to return when reset completed. 365 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 366 * @syscap SystemCapability.Multimedia.Media.AVPlayer 367 * @since 9 368 */ 369 reset(callback: AsyncCallback<void>): void; 370 371 /** 372 * Reset AVPlayer, it will to idle state and can set src again. 373 * @returns { Promise<void> } A Promise instance used to return when reset completed. 374 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 375 * @syscap SystemCapability.Multimedia.Media.AVPlayer 376 * @since 9 377 */ 378 reset(): Promise<void>; 379 380 /** 381 * Releases resources used for AVPlayer. 382 * @param { AsyncCallback<void> } callback - instance used to return when release completed. 383 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 384 * @syscap SystemCapability.Multimedia.Media.AVPlayer 385 * @since 9 386 */ 387 release(callback: AsyncCallback<void>): void; 388 389 /** 390 * Releases resources used for AVPlayer. 391 * @returns { Promise<void> } A Promise instance used to return when release completed. 392 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 393 * @syscap SystemCapability.Multimedia.Media.AVPlayer 394 * @since 9 395 */ 396 release(): Promise<void>; 397 398 /** 399 * Jumps to the specified playback position. 400 * @param { number } timeMs - Playback position to jump, should be in [0, duration]. 401 * @param { SeekMode } mode - See @SeekMode . 402 * @syscap SystemCapability.Multimedia.Media.AVPlayer 403 * @since 9 404 */ 405 seek(timeMs: number, mode?: SeekMode): void; 406 407 /** 408 * Sets the volume. 409 * @param { number } volume - Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%). 410 * @syscap SystemCapability.Multimedia.Media.AVPlayer 411 * @since 9 412 */ 413 setVolume(volume: number): void; 414 415 /** 416 * Get all track infos in MediaDescription, should be called after data loaded callback. 417 * @param { AsyncCallback<Array<MediaDescription>> } callback - Async callback return track info in MediaDescription. 418 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 419 * @syscap SystemCapability.Multimedia.Media.AVPlayer 420 * @since 9 421 */ 422 getTrackDescription(callback: AsyncCallback<Array<MediaDescription>>): void; 423 424 /** 425 * Get all track infos in MediaDescription, should be called after data loaded callback. 426 * @returns { Promise<Array<MediaDescription>> } A Promise instance used to return the track info in MediaDescription. 427 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 428 * @syscap SystemCapability.Multimedia.Media.AVPlayer 429 * @since 9 430 */ 431 getTrackDescription(): Promise<Array<MediaDescription>>; 432 433 /** 434 * Media URI. Mainstream media formats are supported. 435 * Network:http://xxx 436 * @syscap SystemCapability.Multimedia.Media.AVPlayer 437 * @since 9 438 */ 439 url?: string; 440 441 /** 442 * Media file descriptor. Mainstream media formats are supported. 443 * @syscap SystemCapability.Multimedia.Media.AVPlayer 444 * @since 9 445 */ 446 fdSrc?: AVFileDescriptor; 447 448 /** 449 * DataSource descriptor. Supports mainstream media formats. 450 * @syscap SystemCapability.Multimedia.Media.AVPlayer 451 * @since 10 452 */ 453 dataSrc?: AVDataSrcDescriptor; 454 455 /** 456 * Whether to loop media playback. 457 * @syscap SystemCapability.Multimedia.Media.AVPlayer 458 * @since 9 459 */ 460 loop: boolean; 461 462 /** 463 * Describes audio interrupt mode, refer to {@link #audio.InterruptMode}. If it is not 464 * set, the default mode will be used. Set it before calling the {@link #play()} in the 465 * first time in order for the interrupt mode to become effective thereafter. 466 * @syscap SystemCapability.Multimedia.Media.AVPlayer 467 * @since 9 468 */ 469 audioInterruptMode?: audio.InterruptMode; 470 471 /** 472 * Describes audio renderer info, refer to {@link #audio.AudioRendererInfo}. Set it before 473 * calling the {@link #prepare()} in the first time in order for the audio renderer info to 474 * become effective thereafter. 475 * @syscap SystemCapability.Multimedia.Media.AVPlayer 476 * @since 10 477 */ 478 audioRendererInfo?: audio.AudioRendererInfo; 479 480 /** 481 * Obtains the current audio effect mode, refer to {@link #audio.AudioEffectMode}. 482 * @syscap SystemCapability.Multimedia.Media.AVPlayer 483 * @since 10 484 */ 485 audioEffectMode ?: audio.AudioEffectMode; 486 487 /** 488 * Current playback position. 489 * @syscap SystemCapability.Multimedia.Media.AVPlayer 490 * @since 9 491 */ 492 readonly currentTime: number; 493 494 /** 495 * Playback duration, When the data source does not support seek, it returns - 1, such as a live broadcast scenario. 496 * @syscap SystemCapability.Multimedia.Media.AVPlayer 497 * @since 9 498 */ 499 readonly duration: number; 500 501 /** 502 * Playback state. 503 * @syscap SystemCapability.Multimedia.Media.AVPlayer 504 * @since 9 505 */ 506 readonly state: AVPlayerState; 507 508 /** 509 * Video player will use this id get a surface instance. 510 * @syscap SystemCapability.Multimedia.Media.AVPlayer 511 * @since 9 512 */ 513 surfaceId?: string; 514 515 /** 516 * Video width, valid after prepared. 517 * @syscap SystemCapability.Multimedia.Media.AVPlayer 518 * @since 9 519 */ 520 readonly width: number; 521 522 /** 523 * Video height, valid after prepared. 524 * @syscap SystemCapability.Multimedia.Media.AVPlayer 525 * @since 9 526 */ 527 readonly height: number; 528 529 /** 530 * Video scale type. By default, the {@link #VIDEO_SCALE_TYPE_FIT_CROP} will be used, for more 531 * information, refer to {@link #VideoScaleType} . 532 * @syscap SystemCapability.Multimedia.Media.AVPlayer 533 * @since 9 534 */ 535 videoScaleType?: VideoScaleType; 536 537 /** 538 * Set payback speed. 539 * @param { PlaybackSpeed } speed - playback speed, see @PlaybackSpeed . 540 * @syscap SystemCapability.Multimedia.Media.AVPlayer 541 * @since 9 542 */ 543 setSpeed(speed: PlaybackSpeed): void; 544 545 /** 546 * select a specified bitrate to playback, only valid for HLS protocol network stream. By default, the 547 * player will select the appropriate bitrate according to the network connection speed. The 548 * available bitrate list reported by {@link #on('availableBitrates')}. Set it to select 549 * a specified bitrate. If the specified bitrate is not in the list of available bitrate, the player 550 * will select the minimal and closest one from the available bitrate list. 551 * @param { number } bitrate - the playback bitrate must be expressed in bits per second. 552 * @syscap SystemCapability.Multimedia.Media.AVPlayer 553 * @since 9 554 */ 555 setBitrate(bitrate: number): void; 556 557 /** 558 * Register or unregister listens for media playback events. 559 * @param { 'stateChange' } type - Type of the playback event to listen for. 560 * @param { function } callback - Callback used to listen for the playback stateChange event. 561 * @syscap SystemCapability.Multimedia.Media.AVPlayer 562 * @since 9 563 */ 564 on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReason) => void): void; 565 off(type: 'stateChange'): void; 566 /** 567 * Register or unregister listens for media playback events. 568 * @param { 'volumeChange' } type - Type of the playback event to listen for. 569 * @param { Callback<number> } callback - Callback used to listen for the playback volume event. 570 * @syscap SystemCapability.Multimedia.Media.AVPlayer 571 * @since 9 572 */ 573 on(type: 'volumeChange', callback: Callback<number>): void; 574 off(type: 'volumeChange'): void; 575 /** 576 * Register or unregister listens for media playback events. 577 * @param { 'endOfStream' } type - Type of the playback event to listen for. 578 * @param { Callback<void> } callback - Callback used to listen for the playback end of stream. 579 * @syscap SystemCapability.Multimedia.Media.AVPlayer 580 * @since 9 581 */ 582 on(type: 'endOfStream', callback: Callback<void>): void; 583 off(type: 'endOfStream'): void; 584 /** 585 * Register or unregister listens for media playback events. 586 * @param { 'seekDone' } type - Type of the playback event to listen for. 587 * @param { Callback<number> } callback - Callback used to listen for the playback seekDone event. 588 * @syscap SystemCapability.Multimedia.Media.AVPlayer 589 * @since 9 590 */ 591 on(type: 'seekDone', callback: Callback<number>): void; 592 off(type: 'seekDone'): void; 593 /** 594 * Register or unregister listens for media playback events. 595 * @param { 'speedDone' } type - Type of the playback event to listen for. 596 * @param { Callback<number> } callback - Callback used to listen for the playback speedDone event. 597 * @syscap SystemCapability.Multimedia.Media.AVPlayer 598 * @since 9 599 */ 600 on(type: 'speedDone', callback: Callback<number>): void; 601 off(type: 'speedDone'): void; 602 /** 603 * Register or unregister listens for media playback events. 604 * @param { 'bitrateDone' } type - Type of the playback event to listen for. 605 * @param { Callback<number> } callback - Callback used to listen for the playback setBitrateDone event. 606 * @syscap SystemCapability.Multimedia.Media.AVPlayer 607 * @since 9 608 */ 609 on(type: 'bitrateDone', callback: Callback<number>): void; 610 off(type: 'bitrateDone'): void; 611 /** 612 * Register or unregister listens for media playback events. 613 * @param { 'timeUpdate' } type - Type of the playback event to listen for. 614 * @param { Callback<number> } callback - Callback used to listen for the playback timeUpdate event. 615 * @syscap SystemCapability.Multimedia.Media.AVPlayer 616 * @since 9 617 */ 618 on(type: 'timeUpdate', callback: Callback<number>): void; 619 off(type: 'timeUpdate'): void; 620 /** 621 * Register or unregister listens for media playback events. 622 * @param { 'durationUpdate' } type - Type of the playback event to listen for. 623 * @param { Callback<number> } callback - Callback used to listen for the playback durationUpdate event. 624 * @syscap SystemCapability.Multimedia.Media.AVPlayer 625 * @since 9 626 */ 627 on(type: 'durationUpdate', callback: Callback<number>): void; 628 off(type: 'durationUpdate'): void; 629 /** 630 * Register or unregister listens for video playback buffering events. 631 * @param { 'bufferingUpdate' } type - Type of the playback buffering update event to listen for. 632 * @param { function } callback - Callback used to listen for the buffering update event, 633 * return BufferingInfoType and the value. 634 * @syscap SystemCapability.Multimedia.Media.AVPlayer 635 * @since 9 636 */ 637 on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void; 638 off(type: 'bufferingUpdate'): void; 639 /** 640 * Register or unregister listens for start render video frame events. 641 * @param { 'startRenderFrame' } type - Type of the playback event to listen for. 642 * @param { Callback<void> } callback - Callback used to listen for the playback event return . 643 * @syscap SystemCapability.Multimedia.Media.AVPlayer 644 * @since 9 645 */ 646 on(type: 'startRenderFrame', callback: Callback<void>): void; 647 off(type: 'startRenderFrame'): void; 648 /** 649 * Register or unregister listens for video size change event. 650 * @param { 'videoSizeChange' } type - Type of the playback event to listen for. 651 * @param { function } callback - Callback used to listen for the playback event return video size. 652 * @syscap SystemCapability.Multimedia.Media.AVPlayer 653 * @since 9 654 */ 655 on(type: 'videoSizeChange', callback: (width: number, height: number) => void): void; 656 off(type: 'videoSizeChange'): void; 657 /** 658 * Register or unregister listens for audio interrupt event, refer to {@link #audio.InterruptEvent} 659 * @param { 'audioInterrupt' } type - Type of the playback event to listen for. 660 * @param { function } callback - Callback used to listen for the playback event return audio interrupt info. 661 * @syscap SystemCapability.Multimedia.Media.AVPlayer 662 * @since 9 663 */ 664 on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void; 665 off(type: 'audioInterrupt'): void; 666 /** 667 * Register or unregister listens for available bitrate list collect completed events for HLS protocol stream playback. 668 * This event will be reported after the {@link #prepare} called. 669 * @param { 'availableBitrates' } type - Type of the playback event to listen for. 670 * @param { function } callback - Callback used to listen for the playback event return available bitrate list. 671 * @syscap SystemCapability.Multimedia.Media.AVPlayer 672 * @since 9 673 */ 674 on(type: 'availableBitrates', callback: (bitrates: Array<number>) => void): void; 675 off(type: 'availableBitrates'): void; 676 /** 677 * Register or unregister listens for playback error events. 678 * @param { 'error' } type - Type of the playback error event to listen for. 679 * @param { ErrorCallback } callback - Callback used to listen for the playback error event. 680 * @throws { BusinessError } 201 - Permission denied. 681 * @throws { BusinessError } 401 - The parameter check failed. 682 * @throws { BusinessError } 801 - Capability not supported. 683 * @throws { BusinessError } 5400101 - No memory. 684 * @throws { BusinessError } 5400102 - Operation not allowed. 685 * @throws { BusinessError } 5400103 - I/O error. 686 * @throws { BusinessError } 5400104 - Time out. 687 * @throws { BusinessError } 5400105 - Service died. 688 * @throws { BusinessError } 5400106 - Unsupport format. 689 * @syscap SystemCapability.Multimedia.Media.AVPlayer 690 * @since 9 691 */ 692 on(type: 'error', callback: ErrorCallback): void; 693 off(type: 'error'): void; 694 } 695 696 /** 697 * Enumerates ErrorCode types, return in BusinessError::code 698 * 699 * @enum { number } 700 * @syscap SystemCapability.Multimedia.Media.Core 701 * @since 8 702 */ 703 enum MediaErrorCode { 704 /** 705 * operation success. 706 * @syscap SystemCapability.Multimedia.Media.Core 707 * @since 8 708 */ 709 MSERR_OK = 0, 710 711 /** 712 * malloc or new memory failed. maybe system have no memory. 713 * @syscap SystemCapability.Multimedia.Media.Core 714 * @since 8 715 */ 716 MSERR_NO_MEMORY = 1, 717 718 /** 719 * no permission for the operation. 720 * @syscap SystemCapability.Multimedia.Media.Core 721 * @since 8 722 */ 723 MSERR_OPERATION_NOT_PERMIT = 2, 724 725 /** 726 * invalid argument. 727 * @syscap SystemCapability.Multimedia.Media.Core 728 * @since 8 729 */ 730 MSERR_INVALID_VAL = 3, 731 732 /** 733 * an I/O error occurred. 734 * @syscap SystemCapability.Multimedia.Media.Core 735 * @since 8 736 */ 737 MSERR_IO = 4, 738 739 /** 740 * operation time out. 741 * @syscap SystemCapability.Multimedia.Media.Core 742 * @since 8 743 */ 744 MSERR_TIMEOUT = 5, 745 746 /** 747 * unknown error. 748 * @syscap SystemCapability.Multimedia.Media.Core 749 * @since 8 750 */ 751 MSERR_UNKNOWN = 6, 752 753 /** 754 * media service died. 755 * @syscap SystemCapability.Multimedia.Media.Core 756 * @since 8 757 */ 758 MSERR_SERVICE_DIED = 7, 759 760 /** 761 * operation is not permit in current state. 762 * @syscap SystemCapability.Multimedia.Media.Core 763 * @since 8 764 */ 765 MSERR_INVALID_STATE = 8, 766 767 /** 768 * operation is not supported in current version. 769 * @syscap SystemCapability.Multimedia.Media.Core 770 * @since 8 771 */ 772 MSERR_UNSUPPORTED = 9, 773 } 774 775 /** 776 * Enumerates buffering info type, for network playback. 777 * 778 * @enum { number } 779 * @syscap SystemCapability.Multimedia.Media.Core 780 * @since 8 781 */ 782 enum BufferingInfoType { 783 /** 784 * begin to buffering 785 * @syscap SystemCapability.Multimedia.Media.Core 786 * @since 8 787 */ 788 BUFFERING_START = 1, 789 790 /** 791 * end to buffering 792 * @syscap SystemCapability.Multimedia.Media.Core 793 * @since 8 794 */ 795 BUFFERING_END = 2, 796 797 /** 798 * buffering percent 799 * @syscap SystemCapability.Multimedia.Media.Core 800 * @since 8 801 */ 802 BUFFERING_PERCENT = 3, 803 804 /** 805 * cached duration in milliseconds 806 * @syscap SystemCapability.Multimedia.Media.Core 807 * @since 8 808 */ 809 CACHED_DURATION = 4, 810 } 811 812 /** 813 * Media file descriptor. The caller needs to ensure that the fd is valid and 814 * the offset and length are correct. 815 * 816 * @typedef AVFileDescriptor 817 * @syscap SystemCapability.Multimedia.Media.Core 818 * @since 9 819 */ 820 interface AVFileDescriptor { 821 /** 822 * The file descriptor of audio or video source from file system. The caller 823 * is responsible to close the file descriptor. 824 * @syscap SystemCapability.Multimedia.Media.Core 825 * @since 9 826 */ 827 fd: number 828 829 /** 830 * The offset into the file where the data to be read, in bytes. By default, 831 * the offset is zero. 832 * @syscap SystemCapability.Multimedia.Media.Core 833 * @since 9 834 */ 835 offset?: number 836 837 /** 838 * The length in bytes of the data to be read. By default, the length is the 839 * rest of bytes in the file from the offset. 840 * @syscap SystemCapability.Multimedia.Media.Core 841 * @since 9 842 */ 843 length?: number 844 } 845 846 /** 847 * DataSource descriptor. The caller needs to ensure that the fileSize and 848 * callback is valid. 849 * 850 * @typedef AVDataSrcDescriptor 851 * @syscap SystemCapability.Multimedia.Media.AVPlayer 852 * @since 10 853 */ 854 interface AVDataSrcDescriptor { 855 /** 856 * Size of the file, -1 means the file size is unknown, in this case, 857 * seek and setSpeed can't be executed, loop can't be set, and can't replay. 858 * @syscap SystemCapability.Multimedia.Media.AVPlayer 859 * @since 10 860 */ 861 fileSize: number; 862 /** 863 * Callback function implemented by users, which is used to fill data. 864 * buffer - The buffer need to fill. 865 * length - The stream length player want to get. 866 * pos - The stream position player want get start, and is an optional parameter. 867 * When fileSize set to -1, this parameter is not used. 868 * Returns length of the data to be filled. 869 * @syscap SystemCapability.Multimedia.Media.AVPlayer 870 * @since 10 871 */ 872 callback: (buffer: ArrayBuffer, length: number, pos?: number) => number; 873 } 874 875 /** 876 * Describes audio playback states. 877 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 878 * @since 6 879 * @deprecated since 9 880 * @useinstead ohos.multimedia.media/media.AVPlayerState 881 */ 882 type AudioState = 'idle' | 'playing' | 'paused' | 'stopped' | 'error'; 883 884 /** 885 * Manages and plays audio. Before calling an AudioPlayer method, you must use createAudioPlayer() 886 * to create an AudioPlayer instance. 887 * 888 * @typedef AudioPlayer 889 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 890 * @since 6 891 * @deprecated since 9 892 * @useinstead ohos.multimedia.media/media.AVPlayer 893 */ 894 interface AudioPlayer { 895 /** 896 * Starts audio playback. 897 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 898 * @since 6 899 * @deprecated since 9 900 * @useinstead ohos.multimedia.media/media.AVPlayer#play 901 */ 902 play(): void; 903 904 /** 905 * Pauses audio playback. 906 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 907 * @since 6 908 * @deprecated since 9 909 * @useinstead ohos.multimedia.media/media.AVPlayer#pause 910 */ 911 pause(): void; 912 913 /** 914 * Stops audio playback. 915 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 916 * @since 6 917 * @deprecated since 9 918 * @useinstead ohos.multimedia.media/media.AVPlayer#stop 919 */ 920 stop(): void; 921 922 /** 923 * Resets audio playback. 924 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 925 * @since 7 926 * @deprecated since 9 927 * @useinstead ohos.multimedia.media/media.AVPlayer#reset 928 */ 929 reset(): void; 930 931 /** 932 * Jumps to the specified playback position. 933 * @param { number } timeMs - Playback position to jump 934 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 935 * @since 6 936 * @deprecated since 9 937 * @useinstead ohos.multimedia.media/media.AVPlayer#seek 938 */ 939 seek(timeMs: number): void; 940 941 /** 942 * Sets the volume. 943 * @param { number } vol - Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%). 944 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 945 * @since 6 946 * @deprecated since 9 947 * @useinstead ohos.multimedia.media/media.AVPlayer#setVolume 948 */ 949 setVolume(vol: number): void; 950 951 /** 952 * Releases resources used for audio playback. 953 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 954 * @since 6 955 * @deprecated since 9 956 * @useinstead ohos.multimedia.media/media.AVPlayer#release 957 */ 958 release(): void; 959 960 /** 961 * Get all track infos in MediaDescription, should be called after data loaded callback. 962 * @param { AsyncCallback<Array<MediaDescription>> } callback - async callback return track info in MediaDescription. 963 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 964 * @since 8 965 * @deprecated since 9 966 * @useinstead ohos.multimedia.media/media.AVPlayer#getTrackDescription 967 */ 968 getTrackDescription(callback: AsyncCallback<Array<MediaDescription>>): void; 969 970 /** 971 * Get all track infos in MediaDescription, should be called after data loaded callback. 972 * @returns { Promise<Array<MediaDescription>> } A Promise instance used to return the track info in MediaDescription. 973 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 974 * @since 8 975 * @deprecated since 9 976 * @useinstead ohos.multimedia.media/media.AVPlayer#getTrackDescription 977 */ 978 getTrackDescription(): Promise<Array<MediaDescription>>; 979 980 /** 981 * Listens for audio playback buffering events. 982 * @param { 'bufferingUpdate' } type - Type of the playback buffering update event to listen for. 983 * @param { function } callback - Callback used to listen for the buffering update event, 984 * return BufferingInfoType and the value. 985 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 986 * @since 8 987 * @deprecated since 9 988 * @useinstead ohos.multimedia.media/media.AVPlayer#event:bufferingUpdate 989 */ 990 on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void; 991 992 /** 993 * Audio media URI. Mainstream audio formats are supported. 994 * local:fd://XXX, file://XXX. network:http://xxx 995 * @permission ohos.permission.READ_MEDIA or ohos.permission.INTERNET 996 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 997 * @since 6 998 * @deprecated since 9 999 * @useinstead ohos.multimedia.media/media.AVPlayer#url 1000 */ 1001 src: string; 1002 1003 /** 1004 * Audio file descriptor. Mainstream audio formats are supported. 1005 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1006 * @since 9 1007 * @deprecated since 9 1008 * @useinstead ohos.multimedia.media/media.AVPlayer#fdSrc 1009 */ 1010 fdSrc: AVFileDescriptor; 1011 1012 /** 1013 * Whether to loop audio playback. The value true means to loop playback. 1014 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1015 * @since 6 1016 * @deprecated since 9 1017 * @useinstead ohos.multimedia.media/media.AVPlayer#loop 1018 */ 1019 loop: boolean; 1020 1021 /** 1022 * Describes audio interrupt mode, refer to {@link #audio.InterruptMode}. If it is not 1023 * set, the default mode will be used. Set it before calling the {@link #play()} in the 1024 * first time in order for the interrupt mode to become effective thereafter. 1025 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1026 * @since 9 1027 * @deprecated since 9 1028 * @useinstead ohos.multimedia.media/media.AVPlayer#audioInterruptMode 1029 */ 1030 audioInterruptMode?: audio.InterruptMode; 1031 1032 /** 1033 * Current playback position. 1034 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1035 * @since 6 1036 * @deprecated since 9 1037 * @useinstead ohos.multimedia.media/media.AVPlayer#currentTime 1038 */ 1039 readonly currentTime: number; 1040 1041 /** 1042 * Playback duration, When the data source does not support seek, it returns - 1, such as a live broadcast scenario. 1043 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1044 * @since 6 1045 * @deprecated since 9 1046 * @useinstead ohos.multimedia.media/media.AVPlayer#duration 1047 */ 1048 readonly duration: number; 1049 1050 /** 1051 * Playback state. 1052 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1053 * @since 6 1054 * @deprecated since 9 1055 * @useinstead ohos.multimedia.media/media.AVPlayer#state 1056 */ 1057 readonly state: AudioState; 1058 1059 /** 1060 * Listens for audio playback events. 1061 * @param { 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange' } type - Type of the playback event to listen for. 1062 * @param { function } callback - Callback used to listen for the playback event. 1063 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1064 * @since 6 1065 * @deprecated since 9 1066 * @useinstead ohos.multimedia.media/media.AVPlayer#event:stateChange 1067 */ 1068 on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void; 1069 1070 /** 1071 * Listens for audio playback events. 1072 * @param { 'timeUpdate' } type - Type of the playback event to listen for. 1073 * @param { Callback<number> } callback - Callback used to listen for the playback event. 1074 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1075 * @since 6 1076 * @deprecated since 9 1077 * @useinstead ohos.multimedia.media/media.AVPlayer#event:timeUpdate 1078 */ 1079 on(type: 'timeUpdate', callback: Callback<number>): void; 1080 1081 /** 1082 * Listens for audio interrupt event, refer to {@link #audio.InterruptEvent} 1083 * @param { 'audioInterrupt' } type - Type of the playback event to listen for. 1084 * @param { function } callback - Callback used to listen for the playback event return audio interrupt info. 1085 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1086 * @since 9 1087 * @deprecated since 9 1088 * @useinstead ohos.multimedia.media/media.AVPlayer#event:audioInterrupt 1089 */ 1090 on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void; 1091 1092 /** 1093 * Listens for playback error events. 1094 * @param { 'error' } type - Type of the playback error event to listen for. 1095 * @param { ErrorCallback } callback - Callback used to listen for the playback error event. 1096 * @syscap SystemCapability.Multimedia.Media.AudioPlayer 1097 * @since 6 1098 * @deprecated since 9 1099 * @useinstead ohos.multimedia.media/media.AVPlayer#event:error 1100 */ 1101 on(type: 'error', callback: ErrorCallback): void; 1102 } 1103 1104 /** 1105 * Describes media recorder states. 1106 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1107 * @since 9 1108 */ 1109 type AVRecorderState = 'idle' | 'prepared' | 'started' | 'paused' | 'stopped' | 'released' | 'error'; 1110 1111 /** 1112 * Manages and record audio/video. Before calling an AVRecorder method, you must use createAVRecorder() 1113 * to create an AVRecorder instance. 1114 * 1115 * @typedef AVRecorder 1116 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1117 * @since 9 1118 */ 1119 interface AVRecorder { 1120 /** 1121 * Prepares for recording. 1122 * @permission ohos.permission.MICROPHONE 1123 * @param { AVRecorderConfig } config - Recording parameters. 1124 * @param { AsyncCallback<void> } callback - A callback instance used to return when prepare completed. 1125 * @throws { BusinessError } 201 - Permission denied. Return by callback. 1126 * @throws { BusinessError } 401 - Parameter error. Return by callback. 1127 * @throws { BusinessError } 5400102 - Operate not permit. Return by callback. 1128 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1129 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1130 * @since 9 1131 */ 1132 prepare(config: AVRecorderConfig, callback: AsyncCallback<void>): void; 1133 1134 /** 1135 * Prepares for recording. 1136 * @permission ohos.permission.MICROPHONE 1137 * @param { AVRecorderConfig } config - Recording parameters. 1138 * @returns { Promise<void> } A Promise instance used to return when prepare completed. 1139 * @throws { BusinessError } 201 - Permission denied. Return by promise. 1140 * @throws { BusinessError } 401 - Parameter error. Return by promise. 1141 * @throws { BusinessError } 5400102 - Operate not permit. Return by promise. 1142 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1143 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1144 * @since 9 1145 */ 1146 prepare(config: AVRecorderConfig): Promise<void>; 1147 1148 /** 1149 * Get input surface.it must be called between prepare completed and start. 1150 * @param { AsyncCallback<string> } callback - Callback used to return the input surface id in string. 1151 * @throws { BusinessError } 5400102 - Operate not permit. Return by callback. 1152 * @throws { BusinessError } 5400103 - IO error. Return by callback. 1153 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1154 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1155 * @since 9 1156 */ 1157 getInputSurface(callback: AsyncCallback<string>): void; 1158 1159 /** 1160 * Get input surface. it must be called between prepare completed and start. 1161 * @returns { Promise<string> } A Promise instance used to return the input surface id in string. 1162 * @throws { BusinessError } 5400102 - Operate not permit. Return by promise. 1163 * @throws { BusinessError } 5400103 - IO error. Return by promise. 1164 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1165 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1166 * @since 9 1167 */ 1168 getInputSurface(): Promise<string>; 1169 1170 /** 1171 * Start AVRecorder, it will to started state. 1172 * @param { AsyncCallback<void> } callback - A callback instance used to return when start completed. 1173 * @throws { BusinessError } 5400102 - Operate not permit. Return by callback. 1174 * @throws { BusinessError } 5400103 - IO error. Return by callback. 1175 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1176 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1177 * @since 9 1178 */ 1179 start(callback: AsyncCallback<void>): void; 1180 1181 /** 1182 * Start AVRecorder, it will to started state. 1183 * @returns { Promise<void> } A Promise instance used to return when start completed. 1184 * @throws { BusinessError } 5400102 - Operate not permit. Return by promise. 1185 * @throws { BusinessError } 5400103 - IO error. Return by promise. 1186 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1187 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1188 * @since 9 1189 */ 1190 start(): Promise<void>; 1191 1192 /** 1193 * Start AVRecorder, it will to paused state. 1194 * @param { AsyncCallback<void> } callback - A callback instance used to return when pause completed. 1195 * @throws { BusinessError } 5400102 - Operate not permit. Return by callback. 1196 * @throws { BusinessError } 5400103 - IO error. Return by callback. 1197 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1198 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1199 * @since 9 1200 */ 1201 pause(callback: AsyncCallback<void>): void; 1202 1203 /** 1204 * Start AVRecorder, it will to paused state. 1205 * @returns { Promise<void> } A Promise instance used to return when pause completed. 1206 * @throws { BusinessError } 5400102 - Operate not permit. Return by promise. 1207 * @throws { BusinessError } 5400103 - IO error. Return by promise. 1208 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1209 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1210 * @since 9 1211 */ 1212 pause(): Promise<void>; 1213 1214 /** 1215 * Resume AVRecorder, it will to started state. 1216 * @param { AsyncCallback<void> } callback - A callback instance used to return when resume completed. 1217 * @throws { BusinessError } 5400102 - Operate not permit. Return by callback. 1218 * @throws { BusinessError } 5400103 - IO error. Return by callback. 1219 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1220 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1221 * @since 9 1222 */ 1223 resume(callback: AsyncCallback<void>): void; 1224 1225 /** 1226 * Resume AVRecorder, it will to started state. 1227 * @returns { Promise<void> } A Promise instance used to return when resume completed. 1228 * @throws { BusinessError } 5400102 - Operate not permit. Return by promise. 1229 * @throws { BusinessError } 5400103 - IO error. Return by promise. 1230 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1231 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1232 * @since 9 1233 */ 1234 resume(): Promise<void>; 1235 1236 /** 1237 * Stop AVRecorder, it will to stopped state. 1238 * @param { AsyncCallback<void> } callback - A callback instance used to return when stop completed. 1239 * @throws { BusinessError } 5400102 - Operate not permit. Return by callback. 1240 * @throws { BusinessError } 5400103 - IO error. Return by callback. 1241 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1242 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1243 * @since 9 1244 */ 1245 stop(callback: AsyncCallback<void>): void; 1246 1247 /** 1248 * Stop AVRecorder, it will to stopped state. 1249 * @returns { Promise<void> } A Promise instance used to return when stop completed. 1250 * @throws { BusinessError } 5400102 - Operate not permit. Return by promise. 1251 * @throws { BusinessError } 5400103 - IO error. Return by promise. 1252 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1253 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1254 * @since 9 1255 */ 1256 stop(): Promise<void>; 1257 1258 /** 1259 * Reset AVRecorder, it will to idle state. 1260 * @param { AsyncCallback<void> } callback - A callback instance used to return when reset completed. 1261 * @throws { BusinessError } 5400103 - IO error. Return by callback. 1262 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1263 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1264 * @since 9 1265 */ 1266 reset(callback: AsyncCallback<void>): void; 1267 1268 /** 1269 * Reset AVRecorder, it will to idle state. 1270 * @returns { Promise<void> } A Promise instance used to return when reset completed. 1271 * @throws { BusinessError } 5400103 - IO error. Return by promise. 1272 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1273 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1274 * @since 9 1275 */ 1276 reset(): Promise<void>; 1277 1278 /** 1279 * Releases resources used for AVRecorder, it will to released state. 1280 * @param { AsyncCallback<void> } callback - A callback instance used to return when release completed. 1281 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1282 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1283 * @since 9 1284 */ 1285 release(callback: AsyncCallback<void>): void; 1286 1287 /** 1288 * Releases resources used for AVRecorder, it will to released state. 1289 * @returns { Promise<void> } A Promise instance used to return when release completed. 1290 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1291 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1292 * @since 9 1293 */ 1294 release(): Promise<void>; 1295 1296 /** 1297 * Recorder state. 1298 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1299 * @since 9 1300 */ 1301 readonly state: AVRecorderState; 1302 1303 /** 1304 * Listens for recording stateChange events. 1305 * @param { 'stateChange' } type - Type of the recording event to listen for. 1306 * @param { function } callback - Callback used to listen for the recorder stateChange event. 1307 * @throws { BusinessError } 5400103 - IO error. Return by callback. 1308 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1309 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1310 * @since 9 1311 */ 1312 on(type: 'stateChange', callback: (state: AVRecorderState, reason: StateChangeReason) => void): void; 1313 1314 /** 1315 * Listens for recording error events. 1316 * @param { 'error' } type - Type of the recording error event to listen for. 1317 * @param { ErrorCallback } callback - Callback used to listen for the recorder error event. 1318 * @throws { BusinessError } 201 - Permission denied. 1319 * @throws { BusinessError } 401 - The parameter check failed. 1320 * @throws { BusinessError } 801 - Capability not supported. 1321 * @throws { BusinessError } 5400101 - No memory. 1322 * @throws { BusinessError } 5400102 - Operation not allowed. 1323 * @throws { BusinessError } 5400103 - I/O error. 1324 * @throws { BusinessError } 5400104 - Time out. 1325 * @throws { BusinessError } 5400105 - Service died. 1326 * @throws { BusinessError } 5400106 - Unsupport format. 1327 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1328 * @since 9 1329 */ 1330 on(type: 'error', callback: ErrorCallback): void; 1331 1332 /** 1333 * Cancel Listens for recording stateChange events. 1334 * @param { 'stateChange' } type - Type of the recording stateChange event to listen for. 1335 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1336 * @since 9 1337 */ 1338 off(type: 'stateChange'): void; 1339 1340 /** 1341 * Cancel Listens for recording error events. 1342 * @param { 'error' } type - Type of the recording error event to listen for. 1343 * @syscap SystemCapability.Multimedia.Media.AVRecorder 1344 * @since 9 1345 */ 1346 off(type: 'error'): void; 1347 } 1348 1349 /** 1350 * Enumerates audio encoding formats, it will be deprecated after API8, use @CodecMimeType to replace. 1351 * 1352 * @enum { number } 1353 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1354 * @since 6 1355 * @deprecated since 8 1356 * @useinstead ohos.multimedia.media/media.CodecMimeType 1357 */ 1358 enum AudioEncoder { 1359 /** 1360 * Default audio encoding format, which is AMR-NB. 1361 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1362 * @since 6 1363 * @deprecated since 8 1364 */ 1365 DEFAULT = 0, 1366 1367 /** 1368 * Indicates the AMR-NB audio encoding format. 1369 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1370 * @since 6 1371 * @deprecated since 8 1372 */ 1373 AMR_NB = 1, 1374 1375 /** 1376 * Indicates the AMR-WB audio encoding format. 1377 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1378 * @since 6 1379 * @deprecated since 8 1380 */ 1381 AMR_WB = 2, 1382 1383 /** 1384 * Advanced Audio Coding Low Complexity (AAC-LC). 1385 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1386 * @since 6 1387 * @deprecated since 8 1388 */ 1389 AAC_LC = 3, 1390 1391 /** 1392 * High-Efficiency Advanced Audio Coding (HE-AAC). 1393 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1394 * @since 6 1395 * @deprecated since 8 1396 */ 1397 HE_AAC = 4 1398 } 1399 1400 /** 1401 * Enumerates audio output formats, it will be deprecated after API8, use @ContainerFormatType to replace. 1402 * 1403 * @enum { number } 1404 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1405 * @since 6 1406 * @deprecated since 8 1407 * @useinstead ohos.multimedia.media/media.ContainerFormatType 1408 */ 1409 enum AudioOutputFormat { 1410 /** 1411 * Default audio output format, which is Moving Pictures Expert Group 4 (MPEG-4). 1412 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1413 * @since 6 1414 * @deprecated since 8 1415 */ 1416 DEFAULT = 0, 1417 1418 /** 1419 * Indicates the Moving Picture Experts Group-4 (MPEG4) media format. 1420 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1421 * @since 6 1422 * @deprecated since 8 1423 */ 1424 MPEG_4 = 2, 1425 1426 /** 1427 * Indicates the Adaptive Multi-Rate Narrowband (AMR-NB) media format. 1428 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1429 * @since 6 1430 * @deprecated since 8 1431 */ 1432 AMR_NB = 3, 1433 1434 /** 1435 * Indicates the Adaptive Multi-Rate Wideband (AMR-WB) media format. 1436 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1437 * @since 6 1438 * @deprecated since 8 1439 */ 1440 AMR_WB = 4, 1441 1442 /** 1443 * Audio Data Transport Stream (ADTS), a transmission stream format of Advanced Audio Coding (AAC) audio. 1444 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1445 * @since 6 1446 * @deprecated since 8 1447 */ 1448 AAC_ADTS = 6 1449 } 1450 1451 /** 1452 * Provides the geographical location definitions for media resources. 1453 * 1454 * @typedef Location 1455 * @syscap SystemCapability.Multimedia.Media.Core 1456 * @since 6 1457 */ 1458 interface Location { 1459 /** 1460 * Latitude. 1461 * @syscap SystemCapability.Multimedia.Media.Core 1462 * @since 6 1463 */ 1464 latitude: number; 1465 1466 /** 1467 * Longitude. 1468 * @syscap SystemCapability.Multimedia.Media.Core 1469 * @since 6 1470 */ 1471 longitude: number; 1472 } 1473 1474 /** 1475 * Provides the audio recorder configuration definitions. 1476 * 1477 * @typedef AudioRecorderConfig 1478 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1479 * @since 6 1480 * @deprecated since 9 1481 * @useinstead ohos.multimedia.media/media.AVRecorderConfig 1482 */ 1483 interface AudioRecorderConfig { 1484 /** 1485 * Audio encoding format. The default value is DEFAULT, it will be deprecated after API8. 1486 * use "audioEncoderMime" instead. 1487 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1488 * @since 6 1489 * @deprecated since 8 1490 * @useinstead ohos.multimedia.media/media.AudioRecorderConfig.audioEncoderMime 1491 */ 1492 audioEncoder?: AudioEncoder; 1493 1494 /** 1495 * Audio encoding bit rate. 1496 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1497 * @since 6 1498 * @deprecated since 9 1499 */ 1500 audioEncodeBitRate?: number; 1501 1502 /** 1503 * Audio sampling rate. 1504 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1505 * @since 6 1506 * @deprecated since 9 1507 */ 1508 audioSampleRate?: number; 1509 1510 /** 1511 * Number of audio channels. 1512 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1513 * @since 6 1514 * @deprecated since 9 1515 */ 1516 numberOfChannels?: number; 1517 1518 /** 1519 * Audio output format. The default value is DEFAULT, it will be deprecated after API8. 1520 * it will be replaced with "fileFormat". 1521 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1522 * @since 6 1523 * @deprecated since 8 1524 * @useinstead ohos.multimedia.media/media.AudioRecorderConfig.fileFormat 1525 */ 1526 format?: AudioOutputFormat; 1527 1528 /** 1529 * Audio output uri.support two kind of uri now. 1530 * format like: scheme + "://" + "context". 1531 * file: file://path 1532 * fd: fd://fd 1533 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1534 * @since 6 1535 * @deprecated since 9 1536 */ 1537 uri: string; 1538 1539 /** 1540 * Geographical location information. 1541 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1542 * @since 6 1543 * @deprecated since 9 1544 */ 1545 location?: Location; 1546 1547 /** 1548 * audio encoding format MIME. it used to replace audioEncoder. 1549 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1550 * @since 8 1551 * @deprecated since 9 1552 */ 1553 audioEncoderMime?: CodecMimeType; 1554 /** 1555 * output file format. see @ContainerFormatType , it used to replace "format". 1556 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1557 * @since 8 1558 * @deprecated since 9 1559 */ 1560 fileFormat?: ContainerFormatType; 1561 } 1562 1563 /** 1564 * Manages and record audio. Before calling an AudioRecorder method, you must use createAudioRecorder() 1565 * to create an AudioRecorder instance. 1566 * 1567 * @typedef AudioRecorder 1568 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1569 * @since 6 1570 * @deprecated since 9 1571 * @useinstead ohos.multimedia.media/media.AVRecorder 1572 */ 1573 interface AudioRecorder { 1574 /** 1575 * Prepares for recording. 1576 * @permission ohos.permission.MICROPHONE 1577 * @param { AudioRecorderConfig } config - Recording parameters. 1578 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1579 * @since 6 1580 * @deprecated since 9 1581 * @useinstead ohos.multimedia.media/media.AVRecorder#prepare 1582 */ 1583 prepare(config: AudioRecorderConfig): void; 1584 1585 /** 1586 * Starts audio recording. 1587 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1588 * @since 6 1589 * @deprecated since 9 1590 * @useinstead ohos.multimedia.media/media.AVRecorder#start 1591 */ 1592 start(): void; 1593 1594 /** 1595 * Pauses audio recording. 1596 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1597 * @since 6 1598 * @deprecated since 9 1599 * @useinstead ohos.multimedia.media/media.AVRecorder#pause 1600 */ 1601 pause(): void; 1602 1603 /** 1604 * Resumes audio recording. 1605 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1606 * @since 6 1607 * @deprecated since 9 1608 * @useinstead ohos.multimedia.media/media.AVRecorder#resume 1609 */ 1610 resume(): void; 1611 1612 /** 1613 * Stops audio recording. 1614 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1615 * @since 6 1616 * @deprecated since 9 1617 * @useinstead ohos.multimedia.media/media.AVRecorder#stop 1618 */ 1619 stop(): void; 1620 1621 /** 1622 * Releases resources used for audio recording. 1623 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1624 * @since 6 1625 * @deprecated since 9 1626 * @useinstead ohos.multimedia.media/media.AVRecorder#release 1627 */ 1628 release(): void; 1629 1630 /** 1631 * Resets audio recording. 1632 * Before resetting audio recording, you must call stop() to stop recording. After audio recording is reset, 1633 * you must call prepare() to set the recording configurations for another recording. 1634 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1635 * @since 6 1636 * @deprecated since 9 1637 * @useinstead ohos.multimedia.media/media.AVRecorder#reset 1638 */ 1639 reset(): void; 1640 1641 /** 1642 * Listens for audio recording events. 1643 * @param { 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset' } type - Type of the audio recording event to listen for. 1644 * @param { function } callback - Callback used to listen for the audio recording event. 1645 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1646 * @since 6 1647 * @deprecated since 9 1648 * @useinstead ohos.multimedia.media/media.AVRecorder#on 1649 */ 1650 on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void; 1651 1652 /** 1653 * Listens for audio recording error events. 1654 * @param { 'error' } type - Type of the audio recording error event to listen for. 1655 * @param { ErrorCallback } callback - Callback used to listen for the audio recording error event. 1656 * @syscap SystemCapability.Multimedia.Media.AudioRecorder 1657 * @since 6 1658 * @deprecated since 9 1659 * @useinstead ohos.multimedia.media/media.AVRecorder#on 1660 */ 1661 on(type: 'error', callback: ErrorCallback): void; 1662 } 1663 1664 /** 1665 * The maintenance of this interface has been stopped since version api 9. Please use AVRecorderState. 1666 * Describes video recorder states. 1667 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1668 * @systemapi 1669 * @since 9 1670 */ 1671 type VideoRecordState = 'idle' | 'prepared' | 'playing' | 'paused' | 'stopped' | 'error'; 1672 1673 /** 1674 * The maintenance of this interface has been stopped since version api 9. Please use AVRecorder. 1675 * Manages and record video. Before calling an VideoRecorder method, you must use createVideoRecorder() 1676 * to create an VideoRecorder instance. 1677 * 1678 * @typedef VideoRecorder 1679 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1680 * @systemapi 1681 * @since 9 1682 */ 1683 interface VideoRecorder { 1684 /** 1685 * Prepares for recording. 1686 * @permission ohos.permission.MICROPHONE 1687 * @param { VideoRecorderConfig } config - Recording parameters. 1688 * @param { AsyncCallback<void> } callback - A callback instance used to return when prepare completed. 1689 * @throws { BusinessError } 201 - Permission denied. Return by callback. 1690 * @throws { BusinessError } 401 - Parameter error. Return by callback. 1691 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 1692 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1693 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1694 * @systemapi 1695 * @since 9 1696 */ 1697 prepare(config: VideoRecorderConfig, callback: AsyncCallback<void>): void; 1698 /** 1699 * Prepares for recording. 1700 * @permission ohos.permission.MICROPHONE 1701 * @param { VideoRecorderConfig } config - Recording parameters. 1702 * @returns { Promise<void> } A Promise instance used to return when prepare completed. 1703 * @throws { BusinessError } 201 - Permission denied. Return by promise. 1704 * @throws { BusinessError } 401 - Parameter error. Return by promise. 1705 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 1706 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1707 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1708 * @systemapi 1709 * @since 9 1710 */ 1711 prepare(config: VideoRecorderConfig): Promise<void>; 1712 /** 1713 * get input surface.it must be called between prepare completed and start. 1714 * @param { AsyncCallback<string> } callback - Callback used to return the input surface id in string. 1715 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 1716 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 1717 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1718 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1719 * @systemapi 1720 * @since 9 1721 */ 1722 getInputSurface(callback: AsyncCallback<string>): void; 1723 /** 1724 * get input surface. it must be called between prepare completed and start. 1725 * @returns { Promise<string> } A Promise instance used to return the input surface id in string. 1726 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 1727 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 1728 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1729 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1730 * @systemapi 1731 * @since 9 1732 */ 1733 getInputSurface(): Promise<string>; 1734 /** 1735 * Starts video recording. 1736 * @param { AsyncCallback<void> } callback - A callback instance used to return when start completed. 1737 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 1738 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 1739 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1740 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1741 * @systemapi 1742 * @since 9 1743 */ 1744 start(callback: AsyncCallback<void>): void; 1745 /** 1746 * Starts video recording. 1747 * @returns { Promise<void> } A Promise instance used to return when start completed. 1748 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 1749 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 1750 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1751 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1752 * @systemapi 1753 * @since 9 1754 */ 1755 start(): Promise<void>; 1756 /** 1757 * Pauses video recording. 1758 * @param { AsyncCallback<void> } callback - A callback instance used to return when pause completed. 1759 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 1760 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 1761 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1762 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1763 * @systemapi 1764 * @since 9 1765 */ 1766 pause(callback: AsyncCallback<void>): void; 1767 /** 1768 * Pauses video recording. 1769 * @returns { Promise<void> } A Promise instance used to return when pause completed. 1770 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 1771 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 1772 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1773 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1774 * @systemapi 1775 * @since 9 1776 */ 1777 pause(): Promise<void>; 1778 /** 1779 * Resumes video recording. 1780 * @param { AsyncCallback<void> } callback - A callback instance used to return when resume completed. 1781 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 1782 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 1783 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1784 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1785 * @systemapi 1786 * @since 9 1787 */ 1788 resume(callback: AsyncCallback<void>): void; 1789 /** 1790 * Resumes video recording. 1791 * @returns { Promise<void> } A Promise instance used to return when resume completed. 1792 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 1793 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 1794 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1795 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1796 * @systemapi 1797 * @since 9 1798 */ 1799 resume(): Promise<void>; 1800 /** 1801 * Stops video recording. 1802 * @param { AsyncCallback<void> } callback A callback instance used to return when stop completed. 1803 * @throws { BusinessError } 5400102 - Operation not allowed. Return by callback. 1804 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 1805 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1806 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1807 * @systemapi 1808 * @since 9 1809 */ 1810 stop(callback: AsyncCallback<void>): void; 1811 /** 1812 * Stops video recording. 1813 * @returns { Promise<void> } A Promise instance used to return when stop completed. 1814 * @throws { BusinessError } 5400102 - Operation not allowed. Return by promise. 1815 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 1816 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1817 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1818 * @systemapi 1819 * @since 9 1820 */ 1821 stop(): Promise<void>; 1822 /** 1823 * Releases resources used for video recording. 1824 * @param { AsyncCallback<void> } callback - A callback instance used to return when release completed. 1825 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1826 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1827 * @systemapi 1828 * @since 9 1829 */ 1830 release(callback: AsyncCallback<void>): void; 1831 /** 1832 * Releases resources used for video recording. 1833 * @returns { Promise<void> } A Promise instance used to return when release completed. 1834 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1835 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1836 * @systemapi 1837 * @since 9 1838 */ 1839 release(): Promise<void>; 1840 /** 1841 * Resets video recording. 1842 * Before resetting video recording, you must call stop() to stop recording. After video recording is reset, 1843 * you must call prepare() to set the recording configurations for another recording. 1844 * @param { AsyncCallback<void> } callback - A callback instance used to return when reset completed. 1845 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 1846 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1847 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1848 * @systemapi 1849 * @since 9 1850 */ 1851 reset(callback: AsyncCallback<void>): void; 1852 /** 1853 * Resets video recording. 1854 * Before resetting video recording, you must call stop() to stop recording. After video recording is reset, 1855 * you must call prepare() to set the recording configurations for another recording. 1856 * @returns { Promise<void> } A Promise instance used to return when reset completed. 1857 * @throws { BusinessError } 5400103 - I/O error. Return by promise. 1858 * @throws { BusinessError } 5400105 - Service died. Return by promise. 1859 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1860 * @systemapi 1861 * @since 9 1862 */ 1863 reset(): Promise<void>; 1864 /** 1865 * Listens for video recording error events. 1866 * @param { 'error' } type - Type of the video recording error event to listen for. 1867 * @param { ErrorCallback } callback - Callback used to listen for the video recording error event. 1868 * @throws { BusinessError } 5400103 - I/O error. Return by callback. 1869 * @throws { BusinessError } 5400105 - Service died. Return by callback. 1870 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1871 * @systemapi 1872 * @since 9 1873 */ 1874 on(type: 'error', callback: ErrorCallback): void; 1875 1876 /** 1877 * video recorder state. 1878 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 1879 * @systemapi 1880 * @since 9 1881 */ 1882 readonly state: VideoRecordState; 1883 } 1884 1885 /** 1886 * Describes video playback states. 1887 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1888 * @since 8 1889 * @deprecated since 9 1890 * @useinstead ohos.multimedia.media/media.AVPlayerState 1891 */ 1892 type VideoPlayState = 'idle' | 'prepared' | 'playing' | 'paused' | 'stopped' | 'error'; 1893 1894 /** 1895 * Enumerates playback speed. 1896 * 1897 * @enum { number } 1898 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1899 * @since 8 1900 */ 1901 enum PlaybackSpeed { 1902 /** 1903 * playback at 0.75x normal speed 1904 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1905 * @since 8 1906 */ 1907 SPEED_FORWARD_0_75_X = 0, 1908 /** 1909 * playback at normal speed 1910 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1911 * @since 8 1912 */ 1913 SPEED_FORWARD_1_00_X = 1, 1914 /** 1915 * playback at 1.25x normal speed 1916 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1917 * @since 8 1918 */ 1919 SPEED_FORWARD_1_25_X = 2, 1920 /** 1921 * playback at 1.75x normal speed 1922 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1923 * @since 8 1924 */ 1925 SPEED_FORWARD_1_75_X = 3, 1926 /** 1927 * playback at 2.0x normal speed 1928 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1929 * @since 8 1930 */ 1931 SPEED_FORWARD_2_00_X = 4, 1932 } 1933 1934 /** 1935 * Manages and plays video. Before calling an video method, you must use createVideoPlayer() to create an VideoPlayer 1936 * instance. 1937 * 1938 * @typedef VideoPlayer 1939 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1940 * @since 8 1941 * @deprecated since 9 1942 * @useinstead ohos.multimedia.media/media.AVPlayer 1943 */ 1944 interface VideoPlayer { 1945 /** 1946 * Set display surface. 1947 * @param {string} surfaceId - surface id, video player will use this id get a surface instance. 1948 * @param { AsyncCallback<void> } callback - A callback instance used to return when release output buffer completed. 1949 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1950 * @since 8 1951 * @deprecated since 9 1952 * @useinstead ohos.multimedia.media/media.AVPlayer#surfaceId 1953 */ 1954 setDisplaySurface(surfaceId: string, callback: AsyncCallback<void>): void; 1955 /** 1956 * Set display surface. 1957 * @param {string} surfaceId - surface id, video player will use this id get a surface instance. 1958 * @returns { Promise<void> } A Promise instance used to return when release output buffer completed. 1959 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1960 * @since 8 1961 * @deprecated since 9 1962 * @useinstead ohos.multimedia.media/media.AVPlayer#surfaceId 1963 */ 1964 setDisplaySurface(surfaceId: string): Promise<void>; 1965 /** 1966 * Prepare video playback, it will request resource for playing. 1967 * @param { AsyncCallback<void> } callback - A callback instance used to return when prepare completed. 1968 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1969 * @since 8 1970 * @deprecated since 9 1971 * @useinstead ohos.multimedia.media/media.AVPlayer#prepare 1972 */ 1973 prepare(callback: AsyncCallback<void>): void; 1974 /** 1975 * Prepare video playback, it will request resource for playing. 1976 * @returns { Promise<void> } A Promise instance used to return when prepare completed. 1977 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1978 * @since 8 1979 * @deprecated since 9 1980 * @useinstead ohos.multimedia.media/media.AVPlayer#prepare 1981 */ 1982 prepare(): Promise<void>; 1983 /** 1984 * Starts video playback. 1985 * @param { AsyncCallback<void> } callback - A callback instance used to return when start completed. 1986 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1987 * @since 8 1988 * @deprecated since 9 1989 * @useinstead ohos.multimedia.media/media.AVPlayer#play 1990 */ 1991 play(callback: AsyncCallback<void>): void; 1992 /** 1993 * Starts video playback. 1994 * @returns { Promise<void> } A Promise instance used to return when start completed. 1995 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 1996 * @since 8 1997 * @deprecated since 9 1998 * @useinstead ohos.multimedia.media/media.AVPlayer#play 1999 */ 2000 play(): Promise<void>; 2001 /** 2002 * Pauses video playback. 2003 * @param { AsyncCallback<void> } callback - A callback instance used to return when pause completed. 2004 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2005 * @since 8 2006 * @deprecated since 9 2007 * @useinstead ohos.multimedia.media/media.AVPlayer#pause 2008 */ 2009 pause(callback: AsyncCallback<void>): void; 2010 /** 2011 * Pauses video playback. 2012 * @returns { Promise<void> } A Promise instance used to return when pause completed. 2013 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2014 * @since 8 2015 * @deprecated since 9 2016 * @useinstead ohos.multimedia.media/media.AVPlayer#pause 2017 */ 2018 pause(): Promise<void>; 2019 /** 2020 * Stops video playback. 2021 * @param { AsyncCallback<void> } callback - A callback instance used to return when stop completed. 2022 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2023 * @since 8 2024 * @deprecated since 9 2025 * @useinstead ohos.multimedia.media/media.AVPlayer#stop 2026 */ 2027 stop(callback: AsyncCallback<void>): void; 2028 /** 2029 * Stops video playback. 2030 * @returns { Promise<void> } A Promise instance used to return when stop completed. 2031 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2032 * @since 8 2033 * @deprecated since 9 2034 * @useinstead ohos.multimedia.media/media.AVPlayer#stop 2035 */ 2036 stop(): Promise<void>; 2037 /** 2038 * Resets video playback, it will release the resource. 2039 * @param { AsyncCallback<void> } callback - A callback instance used to return when reset completed. 2040 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2041 * @since 8 2042 * @deprecated since 9 2043 * @useinstead ohos.multimedia.media/media.AVPlayer#reset 2044 */ 2045 reset(callback: AsyncCallback<void>): void; 2046 /** 2047 * Resets video playback, it will release the resource. 2048 * @returns { Promise<void> } A Promise instance used to return when reset completed. 2049 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2050 * @since 8 2051 * @deprecated since 9 2052 * @useinstead ohos.multimedia.media/media.AVPlayer#reset 2053 */ 2054 reset(): Promise<void>; 2055 /** 2056 * Jumps to the specified playback position by default SeekMode(SEEK_PREV_SYNC), 2057 * the performance may be not the best. 2058 * @param { number } timeMs - Playback position to jump 2059 * @param { AsyncCallback<number> } callback - A callback instance used to return when seek completed 2060 * and return the seeking position result. 2061 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2062 * @since 8 2063 * @deprecated since 9 2064 * @useinstead ohos.multimedia.media/media.AVPlayer#seek 2065 */ 2066 seek(timeMs: number, callback: AsyncCallback<number>): void; 2067 /** 2068 * Jumps to the specified playback position. 2069 * @param { number } timeMs - Playback position to jump 2070 * @param { SeekMode } mode - seek mode, see @SeekMode . 2071 * @param { AsyncCallback<number> } callback - A callback instance used to return when seek completed 2072 * and return the seeking position result. 2073 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2074 * @since 8 2075 * @deprecated since 9 2076 * @useinstead ohos.multimedia.media/media.AVPlayer#seek 2077 */ 2078 seek(timeMs: number, mode: SeekMode, callback: AsyncCallback<number>): void; 2079 /** 2080 * Jumps to the specified playback position. 2081 * @param { number } timeMs - Playback position to jump 2082 * @param { SeekMode } mode - seek mode, see @SeekMode . 2083 * @returns { Promise<number> } A Promise instance used to return when seek completed 2084 * and return the seeking position result. 2085 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2086 * @since 8 2087 * @deprecated since 9 2088 * @useinstead ohos.multimedia.media/media.AVPlayer#seek 2089 */ 2090 seek(timeMs: number, mode?: SeekMode): Promise<number>; 2091 /** 2092 * Sets the volume. 2093 * @param { number } vol - Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%). 2094 * @param { AsyncCallback<void> } callback - A callback instance used to return when set volume completed. 2095 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2096 * @since 8 2097 * @deprecated since 9 2098 * @useinstead ohos.multimedia.media/media.AVPlayer#setVolume 2099 */ 2100 setVolume(vol: number, callback: AsyncCallback<void>): void; 2101 /** 2102 * Sets the volume. 2103 * @param { number } vol - Relative volume. The value ranges from 0.00 to 1.00. The value 1 indicates the maximum volume (100%). 2104 * @returns { Promise<void> } A Promise instance used to return when set volume completed. 2105 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2106 * @since 8 2107 * @deprecated since 9 2108 * @useinstead ohos.multimedia.media/media.AVPlayer#setVolume 2109 */ 2110 setVolume(vol: number): Promise<void>; 2111 /** 2112 * Releases resources used for video playback. 2113 * @param { AsyncCallback<void> } callback - A callback instance used to return when release completed. 2114 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2115 * @since 8 2116 * @deprecated since 9 2117 * @useinstead ohos.multimedia.media/media.AVPlayer#release 2118 */ 2119 release(callback: AsyncCallback<void>): void; 2120 /** 2121 * Releases resources used for video playback. 2122 * @returns { Promise<void> } A Promise instance used to return when release completed. 2123 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2124 * @since 8 2125 * @deprecated since 9 2126 * @useinstead ohos.multimedia.media/media.AVPlayer#release 2127 */ 2128 release(): Promise<void>; 2129 /** 2130 * Get all track infos in MediaDescription, should be called after data loaded callback. 2131 * @param { AsyncCallback<Array<MediaDescription>> } callback - async callback return track info in MediaDescription. 2132 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2133 * @since 8 2134 * @deprecated since 9 2135 * @useinstead ohos.multimedia.media/media.AVPlayer#getTrackDescription 2136 */ 2137 getTrackDescription(callback: AsyncCallback<Array<MediaDescription>>): void; 2138 2139 /** 2140 * Get all track infos in MediaDescription, should be called after data loaded callback. 2141 * @returns { Promise<Array<MediaDescription>> } A Promise instance used to return the track info in MediaDescription. 2142 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2143 * @since 8 2144 * @deprecated since 9 2145 * @useinstead ohos.multimedia.media/media.AVPlayer#getTrackDescription 2146 */ 2147 getTrackDescription(): Promise<Array<MediaDescription>>; 2148 2149 /** 2150 * media url. Mainstream video formats are supported. 2151 * local:fd://XXX, file://XXX. network:http://xxx 2152 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2153 * @since 8 2154 * @deprecated since 9 2155 * @useinstead ohos.multimedia.media/media.AVPlayer#url 2156 */ 2157 url: string; 2158 2159 /** 2160 * Video file descriptor. Mainstream video formats are supported. 2161 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2162 * @since 9 2163 * @deprecated since 9 2164 * @useinstead ohos.multimedia.media/media.AVPlayer#fdSrc 2165 */ 2166 fdSrc: AVFileDescriptor; 2167 2168 /** 2169 * Whether to loop video playback. The value true means to loop playback. 2170 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2171 * @since 8 2172 * @deprecated since 9 2173 * @useinstead ohos.multimedia.media/media.AVPlayer#loop 2174 */ 2175 loop: boolean; 2176 2177 /** 2178 * Current playback position. 2179 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2180 * @since 8 2181 * @deprecated since 9 2182 * @useinstead ohos.multimedia.media/media.AVPlayer#currentTime 2183 */ 2184 readonly currentTime: number; 2185 2186 /** 2187 * Playback duration, if -1 means cannot seek. 2188 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2189 * @since 8 2190 * @deprecated since 9 2191 * @useinstead ohos.multimedia.media/media.AVPlayer#duration 2192 */ 2193 readonly duration: number; 2194 2195 /** 2196 * Playback state. 2197 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2198 * @since 8 2199 * @deprecated since 9 2200 * @useinstead ohos.multimedia.media/media.AVPlayer#state 2201 */ 2202 readonly state: VideoPlayState; 2203 2204 /** 2205 * video width, valid after prepared. 2206 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2207 * @since 8 2208 * @deprecated since 9 2209 * @useinstead ohos.multimedia.media/media.AVPlayer#width 2210 */ 2211 readonly width: number; 2212 2213 /** 2214 * video height, valid after prepared. 2215 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2216 * @since 8 2217 * @deprecated since 9 2218 * @useinstead ohos.multimedia.media/media.AVPlayer#height 2219 */ 2220 readonly height: number; 2221 2222 /** 2223 * Describes audio interrupt mode, refer to {@link #audio.InterruptMode}. If it is not 2224 * set, the default mode will be used. Set it before calling the {@link #play()} in the 2225 * first time in order for the interrupt mode to become effective thereafter. 2226 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2227 * @since 9 2228 * @deprecated since 9 2229 * @useinstead ohos.multimedia.media/media.AVPlayer#audioInterruptMode 2230 */ 2231 audioInterruptMode?: audio.InterruptMode; 2232 2233 /** 2234 * video scale type. By default, the {@link #VIDEO_SCALE_TYPE_FIT_CROP} will be used, for more 2235 * information, refer to {@link #VideoScaleType} 2236 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2237 * @since 9 2238 * @deprecated since 9 2239 * @useinstead ohos.multimedia.media/media.AVPlayer#videoScaleType 2240 */ 2241 videoScaleType?: VideoScaleType; 2242 2243 /** 2244 * set payback speed. 2245 * @param { number } speed - playback speed, see @PlaybackSpeed . 2246 * @param { AsyncCallback<number> } callback Callback used to return actually speed. 2247 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2248 * @since 8 2249 * @deprecated since 9 2250 * @useinstead ohos.multimedia.media/media.AVPlayer#setSpeed 2251 */ 2252 setSpeed(speed: number, callback: AsyncCallback<number>): void; 2253 /** 2254 * set output surface. 2255 * @param { number } speed - playback speed, see @PlaybackSpeed . 2256 * @returns { Promise<number> } A Promise instance used to return actually speed. 2257 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2258 * @since 8 2259 * @deprecated since 9 2260 * @useinstead ohos.multimedia.media/media.AVPlayer#setSpeed 2261 */ 2262 setSpeed(speed: number): Promise<number>; 2263 2264 /** 2265 * Listens for video playback completed events. 2266 * @param { 'playbackCompleted' } type - Type of the playback event to listen for. 2267 * @param { Callback<void> } callback - Callback used to listen for the playback event return. 2268 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2269 * @since 8 2270 * @deprecated since 9 2271 * @useinstead ohos.multimedia.media/media.AVPlayer#event:stateChange 2272 */ 2273 on(type: 'playbackCompleted', callback: Callback<void>): void; 2274 2275 /** 2276 * Listens for video playback buffering events. 2277 * @param { 'bufferingUpdate' } type - Type of the playback buffering update event to listen for. 2278 * @param { function } callback - Callback used to listen for the buffering update event, 2279 * return BufferingInfoType and the value. 2280 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2281 * @since 8 2282 * @deprecated since 9 2283 * @useinstead ohos.multimedia.media/media.AVPlayer#event:bufferingUpdate 2284 */ 2285 on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void; 2286 2287 /** 2288 * Listens for start render video frame events. 2289 * @param { 'startRenderFrame' } type - Type of the playback event to listen for. 2290 * @param { Callback<void> } callback - Callback used to listen for the playback event return. 2291 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2292 * @since 8 2293 * @deprecated since 9 2294 * @useinstead ohos.multimedia.media/media.AVPlayer#event:startRenderFrame 2295 */ 2296 on(type: 'startRenderFrame', callback: Callback<void>): void; 2297 2298 /** 2299 * Listens for video size changed event. 2300 * @param { 'videoSizeChanged' } type - Type of the playback event to listen for. 2301 * @param { function } callback - Callback used to listen for the playback event return video size. 2302 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2303 * @since 8 2304 * @deprecated since 9 2305 * @useinstead ohos.multimedia.media/media.AVPlayer#event:videoSizeChange 2306 */ 2307 on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void; 2308 2309 /** 2310 * Listens for audio interrupt event, refer to {@link #audio.InterruptEvent} 2311 * @param { 'audioInterrupt' } type - Type of the playback event to listen for. 2312 * @param { function } callback - Callback used to listen for the playback event return audio interrupt info. 2313 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2314 * @since 9 2315 * @deprecated since 9 2316 * @useinstead ohos.multimedia.media/media.AVPlayer#event:audioInterrupt 2317 */ 2318 on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void; 2319 2320 /** 2321 * Listens for playback error events. 2322 * @param { 'error' } type - Type of the playback error event to listen for. 2323 * @param { ErrorCallback } callback - Callback used to listen for the playback error event. 2324 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2325 * @since 8 2326 * @deprecated since 9 2327 * @useinstead ohos.multimedia.media/media.AVPlayer#event:error 2328 */ 2329 on(type: 'error', callback: ErrorCallback): void; 2330 } 2331 2332 /** 2333 * Enumerates video scale type. 2334 * 2335 * @enum { number } 2336 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2337 * @since 9 2338 */ 2339 enum VideoScaleType { 2340 /** 2341 * The content is stretched to the fit the display surface rendering area. When 2342 * the aspect ratio of the content is not same as the display surface, the aspect 2343 * of the content is not maintained. This is the default scale type. 2344 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2345 * @since 9 2346 */ 2347 VIDEO_SCALE_TYPE_FIT = 0, 2348 2349 /** 2350 * The content is stretched to the fit the display surface rendering area. When 2351 * the aspect ratio of the content is not the same as the display surface, content's 2352 * aspect ratio is maintained and the content is cropped to fit the display surface. 2353 * @syscap SystemCapability.Multimedia.Media.VideoPlayer 2354 * @since 9 2355 */ 2356 VIDEO_SCALE_TYPE_FIT_CROP = 1, 2357 } 2358 2359 /** 2360 * Enumerates container format type(The abbreviation for 'container format type' is CFT). 2361 * 2362 * @enum { number } 2363 * @syscap SystemCapability.Multimedia.Media.Core 2364 * @since 8 2365 */ 2366 enum ContainerFormatType { 2367 /** 2368 * A video container format type mp4. 2369 * @syscap SystemCapability.Multimedia.Media.Core 2370 * @since 8 2371 */ 2372 CFT_MPEG_4 = 'mp4', 2373 2374 /** 2375 * A audio container format type m4a. 2376 * @syscap SystemCapability.Multimedia.Media.Core 2377 * @since 8 2378 */ 2379 CFT_MPEG_4A = 'm4a', 2380 } 2381 2382 /** 2383 * Enumerates media data type. 2384 * 2385 * @enum { number } 2386 * @syscap SystemCapability.Multimedia.Media.Core 2387 * @since 8 2388 */ 2389 enum MediaType { 2390 /** 2391 * track is audio. 2392 * @syscap SystemCapability.Multimedia.Media.Core 2393 * @since 8 2394 */ 2395 MEDIA_TYPE_AUD = 0, 2396 /** 2397 * track is video. 2398 * @syscap SystemCapability.Multimedia.Media.Core 2399 * @since 8 2400 */ 2401 MEDIA_TYPE_VID = 1, 2402 } 2403 2404 /** 2405 * Enumerates media description key. 2406 * 2407 * @enum { number } 2408 * @syscap SystemCapability.Multimedia.Media.Core 2409 * @since 8 2410 */ 2411 enum MediaDescriptionKey { 2412 /** 2413 * key for track index, value type is number. 2414 * @syscap SystemCapability.Multimedia.Media.Core 2415 * @since 8 2416 */ 2417 MD_KEY_TRACK_INDEX = 'track_index', 2418 2419 /** 2420 * key for track type, value type is number, see @MediaType. 2421 * @syscap SystemCapability.Multimedia.Media.Core 2422 * @since 8 2423 */ 2424 MD_KEY_TRACK_TYPE = 'track_type', 2425 2426 /** 2427 * key for codec mime type, value type is string. 2428 * @syscap SystemCapability.Multimedia.Media.Core 2429 * @since 8 2430 */ 2431 MD_KEY_CODEC_MIME = 'codec_mime', 2432 2433 /** 2434 * key for duration, value type is number. 2435 * @syscap SystemCapability.Multimedia.Media.Core 2436 * @since 8 2437 */ 2438 MD_KEY_DURATION = 'duration', 2439 2440 /** 2441 * key for bitrate, value type is number. 2442 * @syscap SystemCapability.Multimedia.Media.Core 2443 * @since 8 2444 */ 2445 MD_KEY_BITRATE = 'bitrate', 2446 2447 /** 2448 * key for video width, value type is number. 2449 * @syscap SystemCapability.Multimedia.Media.Core 2450 * @since 8 2451 */ 2452 MD_KEY_WIDTH = 'width', 2453 2454 /** 2455 * key for video height, value type is number. 2456 * @syscap SystemCapability.Multimedia.Media.Core 2457 * @since 8 2458 */ 2459 MD_KEY_HEIGHT = 'height', 2460 2461 /** 2462 * key for video frame rate, value type is number. 2463 * @syscap SystemCapability.Multimedia.Media.Core 2464 * @since 8 2465 */ 2466 MD_KEY_FRAME_RATE = 'frame_rate', 2467 2468 /** 2469 * key for audio channel count, value type is number 2470 * @syscap SystemCapability.Multimedia.Media.Core 2471 * @since 8 2472 */ 2473 MD_KEY_AUD_CHANNEL_COUNT = 'channel_count', 2474 2475 /** 2476 * key for audio sample rate, value type is number 2477 * @syscap SystemCapability.Multimedia.Media.Core 2478 * @since 8 2479 */ 2480 MD_KEY_AUD_SAMPLE_RATE = 'sample_rate', 2481 } 2482 2483 /** 2484 * Provides the video recorder profile definitions. 2485 * 2486 * @typedef VideoRecorderProfile 2487 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2488 * @systemapi 2489 * @since 9 2490 */ 2491 interface VideoRecorderProfile { 2492 /** 2493 * Indicates the audio bit rate. 2494 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2495 * @systemapi 2496 * @since 9 2497 */ 2498 readonly audioBitrate: number; 2499 2500 /** 2501 * Indicates the number of audio channels. 2502 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2503 * @systemapi 2504 * @since 9 2505 */ 2506 readonly audioChannels: number; 2507 2508 /** 2509 * Indicates the audio encoding format. 2510 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2511 * @systemapi 2512 * @since 9 2513 */ 2514 readonly audioCodec: CodecMimeType; 2515 2516 /** 2517 * Indicates the audio sampling rate. 2518 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2519 * @systemapi 2520 * @since 9 2521 */ 2522 readonly audioSampleRate: number; 2523 2524 /** 2525 * Indicates the output file format. 2526 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2527 * @systemapi 2528 * @since 9 2529 */ 2530 readonly fileFormat: ContainerFormatType; 2531 2532 /** 2533 * Indicates the video bit rate. 2534 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2535 * @systemapi 2536 * @since 9 2537 */ 2538 readonly videoBitrate: number; 2539 2540 /** 2541 * Indicates the video encoding format. 2542 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2543 * @systemapi 2544 * @since 9 2545 */ 2546 readonly videoCodec: CodecMimeType; 2547 2548 /** 2549 * Indicates the video width. 2550 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2551 * @systemapi 2552 * @since 9 2553 */ 2554 readonly videoFrameWidth: number; 2555 2556 /** 2557 * Indicates the video height. 2558 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2559 * @systemapi 2560 * @since 9 2561 */ 2562 readonly videoFrameHeight: number; 2563 2564 /** 2565 * Indicates the video frame rate. 2566 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2567 * @systemapi 2568 * @since 9 2569 */ 2570 readonly videoFrameRate: number; 2571 } 2572 2573 /** 2574 * Enumerates audio source type for recorder. 2575 * 2576 * @enum { number } 2577 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2578 * @since 9 2579 */ 2580 enum AudioSourceType { 2581 /** 2582 * Default audio source type. 2583 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2584 * @since 9 2585 */ 2586 AUDIO_SOURCE_TYPE_DEFAULT = 0, 2587 /** 2588 * Source type mic. 2589 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2590 * @since 9 2591 */ 2592 AUDIO_SOURCE_TYPE_MIC = 1, 2593 } 2594 2595 /** 2596 * Enumerates video source type for recorder. 2597 * 2598 * @enum { number } 2599 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2600 * @since 9 2601 */ 2602 enum VideoSourceType { 2603 /** 2604 * Surface raw data. 2605 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2606 * @since 9 2607 */ 2608 VIDEO_SOURCE_TYPE_SURFACE_YUV = 0, 2609 /** 2610 * Surface ES data. 2611 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2612 * @since 9 2613 */ 2614 VIDEO_SOURCE_TYPE_SURFACE_ES = 1, 2615 } 2616 2617 /** 2618 * Provides the video recorder configuration definitions. 2619 * 2620 * @typedef VideoRecorderConfig 2621 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2622 * @systemapi 2623 * @since 9 2624 */ 2625 interface VideoRecorderConfig { 2626 /** 2627 * audio source type, details see @AudioSourceType . 2628 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2629 * @systemapi 2630 * @since 9 2631 */ 2632 audioSourceType?: AudioSourceType; 2633 /** 2634 * video source type, details see @VideoSourceType . 2635 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2636 * @systemapi 2637 * @since 9 2638 */ 2639 videoSourceType: VideoSourceType; 2640 /** 2641 * video recorder profile, can get by "getVideoRecorderProfile", details see @VideoRecorderProfile .= 2642 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2643 * @systemapi 2644 * @since 9 2645 */ 2646 profile: VideoRecorderProfile; 2647 /** 2648 * video output uri.support two kind of uri now. 2649 * format like: scheme + "://" + "context". 2650 * fd: fd://fd 2651 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2652 * @systemapi 2653 * @since 9 2654 */ 2655 url: string; 2656 /** 2657 * Sets the video rotation angle in output file, and for the file to playback. mp4 support. 2658 * the range of rotation angle should be {0, 90, 180, 270}, default is 0. 2659 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2660 * @systemapi 2661 * @since 9 2662 */ 2663 rotation?: number; 2664 /** 2665 * geographical location information. 2666 * @syscap SystemCapability.Multimedia.Media.VideoRecorder 2667 * @systemapi 2668 * @since 9 2669 */ 2670 location?: Location; 2671 } 2672 2673 /** 2674 * Provides the media recorder profile definitions. 2675 * 2676 * @typedef AVRecorderProfile 2677 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2678 * @since 9 2679 */ 2680 interface AVRecorderProfile { 2681 /** 2682 * Indicates the audio bitrate. 2683 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2684 * @since 9 2685 */ 2686 audioBitrate?: number; 2687 2688 /** 2689 * Indicates the number of audio channels. 2690 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2691 * @since 9 2692 */ 2693 audioChannels?: number; 2694 2695 /** 2696 * Indicates the audio encoding format. 2697 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2698 * @since 9 2699 */ 2700 audioCodec?: CodecMimeType; 2701 2702 /** 2703 * Indicates the audio sampling rate. 2704 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2705 * @since 9 2706 */ 2707 audioSampleRate?: number; 2708 2709 /** 2710 * Indicates the output file format. 2711 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2712 * @since 9 2713 */ 2714 fileFormat: ContainerFormatType; 2715 2716 /** 2717 * Indicates the video bitrate. 2718 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2719 * @since 9 2720 */ 2721 videoBitrate?: number; 2722 2723 /** 2724 * Indicates the video encoding format. 2725 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2726 * @since 9 2727 */ 2728 videoCodec?: CodecMimeType; 2729 2730 /** 2731 * Indicates the video width. 2732 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2733 * @since 9 2734 */ 2735 videoFrameWidth?: number; 2736 2737 /** 2738 * Indicates the video height. 2739 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2740 * @since 9 2741 */ 2742 videoFrameHeight?: number; 2743 2744 /** 2745 * Indicates the video frame rate. 2746 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2747 * @since 9 2748 */ 2749 videoFrameRate?: number; 2750 } 2751 2752 /** 2753 * Provides the media recorder configuration definitions. 2754 * 2755 * @typedef AVRecorderConfig 2756 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2757 * @since 9 2758 */ 2759 interface AVRecorderConfig { 2760 /** 2761 * Audio source type, details see @AudioSourceType . 2762 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2763 * @since 9 2764 */ 2765 audioSourceType?: AudioSourceType; 2766 /** 2767 * Video source type, details see @VideoSourceType . 2768 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2769 * @since 9 2770 */ 2771 videoSourceType?: VideoSourceType; 2772 /** 2773 * Video recorder profile, details see @AVRecorderProfile . 2774 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2775 * @since 9 2776 */ 2777 profile: AVRecorderProfile; 2778 /** 2779 * File output uri, support a kind of uri now. 2780 * format like: "fd://" + "context". 2781 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2782 * @since 9 2783 */ 2784 url: string; 2785 /** 2786 * Sets the video rotation angle in output file, and for the file to playback, mp4 support 2787 * the range of rotation angle should be {0, 90, 180, 270}, default is 0. 2788 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2789 * @since 9 2790 */ 2791 rotation?: number; 2792 /** 2793 * Geographical location information. 2794 * @syscap SystemCapability.Multimedia.Media.AVRecorder 2795 * @since 9 2796 */ 2797 location?: Location; 2798 } 2799 2800 /** 2801 * Provides the container definition for media description key-value pairs. 2802 * 2803 * @typedef MediaDescription 2804 * @syscap SystemCapability.Multimedia.Media.Core 2805 * @since 8 2806 */ 2807 interface MediaDescription { 2808 /** 2809 * key:value pair, key see @MediaDescriptionKey . 2810 * @syscap SystemCapability.Multimedia.Media.Core 2811 * @since 8 2812 */ 2813 [key: string]: Object; 2814 } 2815 2816 /** 2817 * Enumerates seek mode. 2818 * 2819 * @enum { number } 2820 * @syscap SystemCapability.Multimedia.Media.Core 2821 * @since 8 2822 */ 2823 enum SeekMode { 2824 /** 2825 * seek to the next sync frame of the given timestamp 2826 * @syscap SystemCapability.Multimedia.Media.Core 2827 * @since 8 2828 */ 2829 SEEK_NEXT_SYNC = 0, 2830 /** 2831 * seek to the previous sync frame of the given timestamp 2832 * @syscap SystemCapability.Multimedia.Media.Core 2833 * @since 8 2834 */ 2835 SEEK_PREV_SYNC = 1, 2836 } 2837 2838 /** 2839 * Enumerates Codec MIME types. 2840 * 2841 * @enum { string } 2842 * @syscap SystemCapability.Multimedia.Media.Core 2843 * @since 8 2844 */ 2845 enum CodecMimeType { 2846 /** 2847 * H.263 codec MIME type. 2848 * @syscap SystemCapability.Multimedia.Media.Core 2849 * @since 8 2850 */ 2851 VIDEO_H263 = 'video/h263', 2852 /** 2853 * H.264 codec MIME type. 2854 * @syscap SystemCapability.Multimedia.Media.Core 2855 * @since 8 2856 */ 2857 VIDEO_AVC = 'video/avc', 2858 /** 2859 * MPEG2 codec MIME type. 2860 * @syscap SystemCapability.Multimedia.Media.Core 2861 * @since 8 2862 */ 2863 VIDEO_MPEG2 = 'video/mpeg2', 2864 /** 2865 * MPEG4 codec MIME type 2866 * @syscap SystemCapability.Multimedia.Media.Core 2867 * @since 8 2868 */ 2869 VIDEO_MPEG4 = 'video/mp4v-es', 2870 2871 /** 2872 * VP8 codec MIME type 2873 * @syscap SystemCapability.Multimedia.Media.Core 2874 * @since 8 2875 */ 2876 VIDEO_VP8 = 'video/x-vnd.on2.vp8', 2877 2878 /** 2879 * AAC codec MIME type. 2880 * @syscap SystemCapability.Multimedia.Media.Core 2881 * @since 8 2882 */ 2883 AUDIO_AAC = 'audio/mp4a-latm', 2884 2885 /** 2886 * vorbis codec MIME type. 2887 * @syscap SystemCapability.Multimedia.Media.Core 2888 * @since 8 2889 */ 2890 AUDIO_VORBIS = 'audio/vorbis', 2891 2892 /** 2893 * flac codec MIME type. 2894 * @syscap SystemCapability.Multimedia.Media.Core 2895 * @since 8 2896 */ 2897 AUDIO_FLAC = 'audio/flac', 2898 } 2899} 2900export default media; 2901