1# Deprecated Interface (VideoPlayer, deprecated) 2<!--Kit: Media Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @xushubo; @chennotfound--> 5<!--Designer: @dongyu_dy--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9> **NOTE** 10> 11> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer](arkts-apis-media-AVPlayer.md) instead. 12 13VideoPlayer is a class for video playback management. It provides APIs to manage and play videos. Before calling any API in VideoPlayer, you must use [createVideoPlayer()](arkts-apis-media-f.md#mediacreatevideoplayerdeprecated) to create a VideoPlayer instance. 14 15## Modules to Import 16 17```ts 18import { media } from '@kit.MediaKit'; 19``` 20 21## Properties 22 23**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 24 25| Name | Type | Read-Only| Optional| Description | 26| ------------------------------- | ------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | 27| url<sup>8+</sup> | string | No | No | Video URL. The video formats MP4, MPEG-TS, and MKV are supported.<br>**Example of supported URLs**:<br>1. FD: fd://xx<br><br>2. HTTP: http\://xx<br>3. HTTPS: https\://xx<br>4. HLS: http\://xx or https\://xx<br>5. File type: file\://xx<br>**NOTE**<br>WebM is no longer supported since API version 11.| 28| fdSrc<sup>9+</sup> | [AVFileDescriptor](arkts-apis-media-i.md#avfiledescriptor9) | No | No | Description of a video file. This property is required when video assets of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music assets consists of the following:<br>Video 1 (address offset: 0, byte length: 100)<br>Video 2 (address offset: 101; byte length: 50)<br>Video 3 (address offset: 151, byte length: 150)<br>1. To play video 1: AVFileDescriptor { fd = resource handle; offset = 0; length = 100; }<br>2. To play video 2: AVFileDescriptor { fd = resource handle; offset = 101; length = 50; }<br>3. To play video 3: AVFileDescriptor { fd = resource handle; offset = 151; length = 150; }<br>To play an independent video file, use **src=fd://xx**.<br>| 29| loop<sup>8+</sup> | boolean | No | No | Whether to loop video playback. **true** to loop, **false** otherwise. | 30| videoScaleType<sup>9+</sup> | [VideoScaleType](arkts-apis-media-e.md#videoscaletype9) | No | Yes | Video scale type. The default value is **VIDEO_SCALE_TYPE_FIT**. | 31| audioInterruptMode<sup>9+</sup> | [audio.InterruptMode](../apis-audio-kit/arkts-apis-audio-e.md#interruptmode9) | No | Yes | Audio interruption mode. | 32| currentTime<sup>8+</sup> | number | Yes | No | Current video playback position, in ms. | 33| duration<sup>8+</sup> | number | Yes | No | Video duration, in ms. The value **-1** indicates the live mode. | 34| state<sup>8+</sup> | [VideoPlayState](arkts-apis-media-t.md#videoplaystatedeprecated) | Yes | No | Video playback state. | 35| width<sup>8+</sup> | number | Yes | No | Video width, in px. | 36| height<sup>8+</sup> | number | Yes | No | Video height, in px. | 37 38## setDisplaySurface<sup>(deprecated)</sup> 39 40setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void 41 42Sets a surface ID. This API uses an asynchronous callback to return the result. 43 44*Note: **SetDisplaySurface** must be called between the URL setting and the calling of **prepare**. A surface must be set for video streams without audio. Otherwise, the calling of **prepare** fails. 45 46> **NOTE** 47> 48> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.surfaceId](arkts-apis-media-AVPlayer.md#properties) instead. 49 50**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 51 52**Parameters** 53 54| Name | Type | Mandatory| Description | 55| --------- | -------------------- | ---- | ------------------------- | 56| surfaceId | string | Yes | Surface ID, which is obtained from the **XComponent**. For details about how to obtain it, see [XComponent](../../reference/apis-arkui/arkui-ts/ts-basic-components-xcomponent.md). | 57| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 58 59**Example** 60 61```ts 62import { BusinessError } from '@kit.BasicServicesKit'; 63 64let surfaceId: string = ''; 65videoPlayer.setDisplaySurface(surfaceId, (err: BusinessError) => { 66 if (err) { 67 console.error('Failed to set DisplaySurface!'); 68 } else { 69 console.info('Succeeded in setting DisplaySurface!'); 70 } 71}); 72``` 73 74## setDisplaySurface<sup>(deprecated)</sup> 75 76setDisplaySurface(surfaceId: string): Promise\<void> 77 78Sets a surface ID. This API uses a promise to return the result. 79 80*Note: **SetDisplaySurface** must be called between the URL setting and the calling of **prepare**. A surface must be set for video streams without audio. Otherwise, the calling of **prepare** fails. 81 82> **NOTE** 83> 84> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.surfaceId](arkts-apis-media-AVPlayer.md#properties) instead. 85 86**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 87 88**Parameters** 89 90| Name | Type | Mandatory| Description | 91| --------- | ------ | ---- | --------- | 92| surfaceId | string | Yes | Surface ID, which is obtained from the **XComponent**. For details about how to obtain it, see [XComponent](../../reference/apis-arkui/arkui-ts/ts-basic-components-xcomponent.md).| 93 94**Return value** 95 96| Type | Description | 97| -------------- | ------------------------------ | 98| Promise\<void> | Promise that returns no value.| 99 100**Example** 101 102```ts 103import { BusinessError } from '@kit.BasicServicesKit'; 104 105let surfaceId: string = ''; 106videoPlayer.setDisplaySurface(surfaceId).then(() => { 107 console.info('Succeeded in setting DisplaySurface'); 108}).catch((error: BusinessError) => { 109 console.error(`video catchCallback, error:${error}`); 110}); 111``` 112 113## prepare<sup>(deprecated)</sup> 114 115prepare(callback: AsyncCallback\<void>): void 116 117Prepares for video playback. This API uses an asynchronous callback to return the result. 118 119> **NOTE** 120> 121> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.prepare](arkts-apis-media-AVPlayer.md#prepare9) instead. 122 123**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 124 125**Parameters** 126 127| Name | Type | Mandatory| Description | 128| -------- | -------------------- | ---- | ------------------------ | 129| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 130 131**Example** 132 133```ts 134import { BusinessError } from '@kit.BasicServicesKit'; 135 136videoPlayer.prepare((err: BusinessError) => { 137 if (err) { 138 console.error('Failed to prepare!'); 139 } else { 140 console.info('Succeeded in preparing!'); 141 } 142}); 143``` 144 145## prepare<sup>(deprecated)</sup> 146 147prepare(): Promise\<void> 148 149Prepares for video playback. This API uses a promise to return the result. 150 151> **NOTE** 152> 153> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.prepare](arkts-apis-media-AVPlayer.md#prepare9-1) instead. 154 155**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 156 157**Return value** 158 159| Type | Description | 160| -------------- | ----------------------------- | 161| Promise\<void> | Promise that returns no value.| 162 163**Example** 164 165```ts 166import { BusinessError } from '@kit.BasicServicesKit'; 167 168videoPlayer.prepare().then(() => { 169 console.info('Succeeded in preparing'); 170}).catch((error: BusinessError) => { 171 console.error(`video catchCallback, error:${error}`); 172}); 173``` 174 175## play<sup>(deprecated)</sup> 176 177play(callback: AsyncCallback\<void>): void 178 179Starts video playback. This API uses an asynchronous callback to return the result. 180 181> **NOTE** 182> 183> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.play](arkts-apis-media-AVPlayer.md#play9) instead. 184 185**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 186 187**Parameters** 188 189| Name | Type | Mandatory| Description | 190| -------- | -------------------- | ---- | ------------------------ | 191| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 192 193**Example** 194 195```ts 196import { BusinessError } from '@kit.BasicServicesKit'; 197 198videoPlayer.play((err: BusinessError) => { 199 if (err) { 200 console.error('Failed to play!'); 201 } else { 202 console.info('Succeeded in playing!'); 203 } 204}); 205``` 206 207## play<sup>(deprecated)</sup> 208 209play(): Promise\<void> 210 211Starts video playback. This API uses a promise to return the result. 212 213> **NOTE** 214> 215> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.play](arkts-apis-media-AVPlayer.md#play9-1) instead. 216 217**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 218 219**Return value** 220 221| Type | Description | 222| -------------- | ----------------------------- | 223| Promise\<void> | Promise that returns no value.| 224 225**Example** 226 227```ts 228import { BusinessError } from '@kit.BasicServicesKit'; 229 230videoPlayer.play().then(() => { 231 console.info('Succeeded in playing'); 232}).catch((error: BusinessError) => { 233 console.error(`video catchCallback, error:${error}`); 234}); 235``` 236 237## pause<sup>(deprecated)</sup> 238 239pause(callback: AsyncCallback\<void>): void 240 241Pauses video playback. This API uses an asynchronous callback to return the result. 242 243> **NOTE** 244> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.pause](arkts-apis-media-AVPlayer.md#pause9) instead. 245 246**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 247 248**Parameters** 249 250| Name | Type | Mandatory| Description | 251| -------- | -------------------- | ---- | ------------------------ | 252| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 253 254**Example** 255 256```ts 257import { BusinessError } from '@kit.BasicServicesKit'; 258 259videoPlayer.pause((err: BusinessError) => { 260 if (err) { 261 console.error('Failed to pause!'); 262 } else { 263 console.info('Succeeded in pausing!'); 264 } 265}); 266``` 267 268## pause<sup>(deprecated)</sup> 269 270pause(): Promise\<void> 271 272Pauses video playback. This API uses a promise to return the result. 273 274> **NOTE** 275> 276> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.pause](arkts-apis-media-AVPlayer.md#pause9-1) instead. 277 278**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 279 280**Return value** 281 282| Type | Description | 283| -------------- | ----------------------------- | 284| Promise\<void> | Promise that returns no value.| 285 286**Example** 287 288```ts 289import { BusinessError } from '@kit.BasicServicesKit'; 290 291videoPlayer.pause().then(() => { 292 console.info('Succeeded in pausing'); 293}).catch((error: BusinessError) => { 294 console.error(`video catchCallback, error:${error}`); 295}); 296``` 297 298## stop<sup>(deprecated)</sup> 299 300stop(callback: AsyncCallback\<void>): void 301 302Stops video playback. This API uses an asynchronous callback to return the result. 303 304> **NOTE** 305> 306> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.stop](arkts-apis-media-AVPlayer.md#stop9) instead. 307 308**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 309 310**Parameters** 311 312| Name | Type | Mandatory| Description | 313| -------- | -------------------- | ---- | ------------------------ | 314| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 315 316**Example** 317 318```ts 319import { BusinessError } from '@kit.BasicServicesKit'; 320 321videoPlayer.stop((err: BusinessError) => { 322 if (err) { 323 console.error('Failed to stop!'); 324 } else { 325 console.info('Succeeded in stopping!'); 326 } 327}); 328``` 329 330## stop<sup>(deprecated)</sup> 331 332stop(): Promise\<void> 333 334Stops video playback. This API uses a promise to return the result. 335 336> **NOTE** 337> 338> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.stop](arkts-apis-media-AVPlayer.md#stop9-1) instead. 339 340**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 341 342**Return value** 343 344| Type | Description | 345| -------------- | ----------------------------- | 346| Promise\<void> | Promise that returns no value.| 347 348**Example** 349 350```ts 351import { BusinessError } from '@kit.BasicServicesKit'; 352 353videoPlayer.stop().then(() => { 354 console.info('Succeeded in stopping'); 355}).catch((error: BusinessError) => { 356 console.error(`video catchCallback, error:${error}`); 357}); 358``` 359 360## reset<sup>(deprecated)</sup> 361 362reset(callback: AsyncCallback\<void>): void 363 364Resets video playback. This API uses an asynchronous callback to return the result. 365 366> **NOTE** 367> 368> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.reset](arkts-apis-media-AVPlayer.md#reset9) instead. 369 370**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 371 372**Parameters** 373 374| Name | Type | Mandatory| Description | 375| -------- | -------------------- | ---- | ------------------------ | 376| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 377 378**Example** 379 380```ts 381import { BusinessError } from '@kit.BasicServicesKit'; 382 383videoPlayer.reset((err: BusinessError) => { 384 if (err) { 385 console.error('Failed to reset!'); 386 } else { 387 console.info('Succeeded in resetting!'); 388 } 389}); 390``` 391 392## reset<sup>(deprecated)</sup> 393 394reset(): Promise\<void> 395 396Resets video playback. This API uses a promise to return the result. 397 398> **NOTE** 399> 400> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.reset](arkts-apis-media-AVPlayer.md#reset9-1) instead. 401 402**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 403 404**Return value** 405 406| Type | Description | 407| -------------- | ----------------------------- | 408| Promise\<void> | Promise that returns no value.| 409 410**Example** 411 412```ts 413import { BusinessError } from '@kit.BasicServicesKit'; 414 415videoPlayer.reset().then(() => { 416 console.info('Succeeded in resetting'); 417}).catch((error: BusinessError) => { 418 console.error(`video catchCallback, error:${error}`); 419}); 420``` 421 422## seek<sup>(deprecated)</sup> 423 424seek(timeMs: number, callback: AsyncCallback\<number>): void 425 426Seeks to the specified playback position. The previous key frame at the specified position is played. This API uses an asynchronous callback to return the result. 427 428> **NOTE** 429> 430> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.seek](arkts-apis-media-AVPlayer.md#seek9) instead. 431 432**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 433 434**Parameters** 435 436| Name | Type | Mandatory| Description | 437| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 438| timeMs | number | Yes | Position to seek to, in ms. The value range is [0, duration].| 439| callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the new playback position; otherwise, **err** is an error object. | 440 441**Example** 442 443```ts 444import { BusinessError } from '@kit.BasicServicesKit'; 445 446let videoPlayer: media.VideoPlayer; 447media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => { 448 if (video != null) { 449 videoPlayer = video; 450 console.info('Succeeded in creating VideoPlayer'); 451 } else { 452 console.error(`Failed to create VideoPlayer, error:${error}`); 453 } 454}); 455 456let seekTime: number = 5000; 457videoPlayer.seek(seekTime, (err: BusinessError, result: number) => { 458 if (err) { 459 console.error('Failed to do seek!'); 460 } else { 461 console.info('Succeeded in doing seek!'); 462 } 463}); 464``` 465 466## seek<sup>(deprecated)</sup> 467 468seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void 469 470Seeks to the specified playback position. This API uses an asynchronous callback to return the result. 471 472> **NOTE** 473> 474> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.seek](arkts-apis-media-AVPlayer.md#seek9) instead. 475 476**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 477 478**Parameters** 479 480| Name | Type | Mandatory| Description | 481| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 482| timeMs | number | Yes | Position to seek to, in ms. The value range is [0, duration].| 483| mode | [SeekMode](arkts-apis-media-e.md#seekmode8) | Yes | Seek mode. | 484| callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the new playback position; otherwise, **err** is an error object. | 485 486**Example** 487 488```ts 489import { BusinessError } from '@kit.BasicServicesKit'; 490 491let videoPlayer: media.VideoPlayer | null = null; 492media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => { 493 if (video != null) { 494 videoPlayer = video; 495 console.info('Succeeded in creating VideoPlayer'); 496 } else { 497 console.error(`Failed to create VideoPlayer, error:${error}`); 498 } 499}); 500let seekTime: number = 5000; 501if (videoPlayer) { 502 (videoPlayer as media.VideoPlayer).seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err: BusinessError, result: number) => { 503 if (err) { 504 console.error('Failed to do seek!'); 505 } else { 506 console.info('Succeeded in doing seek!'); 507 } 508 }); 509} 510``` 511 512## seek<sup>(deprecated)</sup> 513 514seek(timeMs: number, mode?:SeekMode): Promise\<number> 515 516Seeks to the specified playback position. If **mode** is not specified, the previous key frame at the specified position is played. This API uses a promise to return the result. 517 518> **NOTE** 519> 520> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.seek](arkts-apis-media-AVPlayer.md#seek9) instead. 521 522**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 523 524**Parameters** 525 526| Name| Type | Mandatory| Description | 527| ------ | ---------------------- | ---- | ------------------------------------------------------------ | 528| timeMs | number | Yes | Position to seek to, in ms. The value range is [0, duration].| 529| mode | [SeekMode](arkts-apis-media-e.md#seekmode8) | No | Seek mode based on the video I frame. The default value is **SEEK_PREV_SYNC**. | 530 531**Return value** 532 533| Type | Description | 534| ---------------- | ------------------------------------------- | 535| Promise\<number>| Promise used to return the playback position, in ms.| 536 537**Example** 538 539```ts 540import { BusinessError } from '@kit.BasicServicesKit'; 541 542let videoPlayer: media.VideoPlayer | null = null; 543media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => { 544 if (video != null) { 545 videoPlayer = video; 546 console.info('Succeeded in creating VideoPlayer'); 547 } else { 548 console.error(`Failed to create VideoPlayer, error:${error}`); 549 } 550}); 551let seekTime: number = 5000; 552if (videoPlayer) { 553 (videoPlayer as media.VideoPlayer).seek(seekTime).then((seekDoneTime: number) => { // seekDoneTime indicates the position after the seek operation is complete. 554 console.info('Succeeded in doing seek'); 555 }).catch((error: BusinessError) => { 556 console.error(`video catchCallback, error:${error}`); 557 }); 558 559 (videoPlayer as media.VideoPlayer).seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime: number) => { 560 console.info('Succeeded in doing seek'); 561 }).catch((error: BusinessError) => { 562 console.error(`video catchCallback, error:${error}`); 563 }); 564} 565``` 566 567## setVolume<sup>(deprecated)</sup> 568 569setVolume(vol: number, callback: AsyncCallback\<void>): void 570 571Sets the volume. This API uses an asynchronous callback to return the result. 572 573> **NOTE** 574> 575> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setVolume](arkts-apis-media-AVPlayer.md#setvolume9) instead. 576 577**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 578 579**Parameters** 580 581| Name | Type | Mandatory| Description | 582| -------- | -------------------- | ---- | ------------------------------------------------------------ | 583| vol | number | Yes | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).| 584| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 585 586**Example** 587 588```ts 589import { BusinessError } from '@kit.BasicServicesKit'; 590 591let vol: number = 0.5; 592videoPlayer.setVolume(vol, (err: BusinessError) => { 593 if (err) { 594 console.error('Failed to set Volume!'); 595 } else { 596 console.info('Succeeded in setting Volume!'); 597 } 598}); 599``` 600 601## setVolume<sup>(deprecated)</sup> 602 603setVolume(vol: number): Promise\<void> 604 605Sets the volume. This API uses a promise to return the result. 606 607> **NOTE** 608> 609> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setVolume](arkts-apis-media-AVPlayer.md#setvolume9) instead. 610 611**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 612 613**Parameters** 614 615| Name| Type | Mandatory| Description | 616| ------ | ------ | ---- | ------------------------------------------------------------ | 617| vol | number | Yes | Relative volume. The value ranges from 0.00 to 1.00. The value **1.00** indicates the maximum volume (100%).| 618 619**Return value** 620 621| Type | Description | 622| -------------- | ------------------------- | 623| Promise\<void> | Promise that returns no value.| 624 625**Example** 626 627```ts 628import { BusinessError } from '@kit.BasicServicesKit'; 629 630let vol: number = 0.5; 631videoPlayer.setVolume(vol).then(() => { 632 console.info('Succeeded in setting Volume'); 633}).catch((error: BusinessError) => { 634 console.error(`video catchCallback, error:${error}`); 635}); 636``` 637 638## release<sup>(deprecated)</sup> 639 640release(callback: AsyncCallback\<void>): void 641 642Releases the video playback resources. This API uses an asynchronous callback to return the result. 643 644> **NOTE** 645> 646> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.release](arkts-apis-media-AVPlayer.md#release9) instead. 647 648**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 649 650**Parameters** 651 652| Name | Type | Mandatory| Description | 653| -------- | -------------------- | ---- | ------------------------ | 654| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| 655 656**Example** 657 658```ts 659import { BusinessError } from '@kit.BasicServicesKit'; 660 661videoPlayer.release((err: BusinessError) => { 662 if (err) { 663 console.error('Failed to release!'); 664 } else { 665 console.info('Succeeded in releasing!'); 666 } 667}); 668``` 669 670## release<sup>(deprecated)</sup> 671 672release(): Promise\<void> 673 674Releases the video playback resources. This API uses a promise to return the result. 675 676> **NOTE** 677> 678> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.release](arkts-apis-media-AVPlayer.md#release9-1) instead. 679 680**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 681 682**Return value** 683 684| Type | Description | 685| -------------- | ----------------------------- | 686| Promise\<void> | Promise that returns no value.| 687 688**Example** 689 690```ts 691import { BusinessError } from '@kit.BasicServicesKit'; 692 693videoPlayer.release().then(() => { 694 console.info('Succeeded in releasing'); 695}).catch((error: BusinessError) => { 696 console.error(`video catchCallback, error:${error}`); 697}); 698``` 699 700## getTrackDescription<sup>(deprecated)</sup> 701 702getTrackDescription(callback: AsyncCallback\<Array\<MediaDescription>>): void 703 704Obtains the video track information. This API uses an asynchronous callback to return the result. 705 706> **NOTE** 707> 708> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.getTrackDescription](arkts-apis-media-AVPlayer.md#gettrackdescription9) instead. 709 710**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 711 712**Parameters** 713 714| Name | Type | Mandatory| Description | 715| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 716| callback | AsyncCallback\<Array\<[MediaDescription](arkts-apis-media-i.md#mediadescription8)>> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the MediaDescription array obtained; otherwise, **err** is an error object.| 717 718**Example** 719 720```ts 721import { BusinessError } from '@kit.BasicServicesKit'; 722 723videoPlayer.getTrackDescription((error: BusinessError, arrList: Array<media.MediaDescription>) => { 724 if ((arrList) != null) { 725 console.info('Succeeded in getting TrackDescription'); 726 } else { 727 console.error(`Failed to get TrackDescription, error:${error}`); 728 } 729}); 730``` 731 732## getTrackDescription<sup>(deprecated)</sup> 733 734getTrackDescription(): Promise\<Array\<MediaDescription>> 735 736Obtains the video track information. This API uses a promise to return the result. 737 738> **NOTE** 739> 740> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.getTrackDescription](arkts-apis-media-AVPlayer.md#gettrackdescription9-1) instead. 741 742**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 743 744**Return value** 745 746| Type | Description | 747| ------------------------------------------------------ | ----------------------------------------------- | 748| Promise<Array<[MediaDescription](arkts-apis-media-i.md#mediadescription8)>> | Promise used to return the MediaDescription array that holds the video track information.| 749 750**Example** 751 752```ts 753import { BusinessError } from '@kit.BasicServicesKit'; 754 755videoPlayer.getTrackDescription().then((arrList: Array<media.MediaDescription>) => { 756 if (arrList != null) { 757 console.info('Succeeded in getting TrackDescription'); 758 } else { 759 console.error('Failed to get TrackDescription'); 760 } 761}).catch((error: BusinessError) => { 762 console.error(`video catchCallback, error:${error}`); 763}); 764``` 765 766## setSpeed<sup>(deprecated)</sup> 767 768setSpeed(speed: number, callback: AsyncCallback\<number>): void 769 770Sets the playback speed. This API uses an asynchronous callback to return the result. 771 772> **NOTE** 773> 774> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setSpeed](arkts-apis-media-AVPlayer.md#setspeed9) instead. 775 776**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 777 778**Parameters** 779 780| Name | Type | Mandatory| Description | 781| -------- | ---------------------- | ---- | ---------------------------------------------------------- | 782| speed | number | Yes | Video playback speed. For details, see [PlaybackSpeed](arkts-apis-media-e.md#playbackspeed8).| 783| callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the playback speed; otherwise, **err** is an error object. | 784 785**Example** 786 787```ts 788import { BusinessError } from '@kit.BasicServicesKit'; 789 790let videoPlayer: media.VideoPlayer | null = null; 791media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => { 792 if (video != null) { 793 videoPlayer = video; 794 console.info('Succeeded in creating VideoPlayer'); 795 } else { 796 console.error(`Failed to create VideoPlayer, error:${error}`); 797 } 798}); 799let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; 800if (videoPlayer) { 801 (videoPlayer as media.VideoPlayer).setSpeed(speed, (err: BusinessError, result: number) => { 802 if (err) { 803 console.error('Failed to set Speed!'); 804 } else { 805 console.info('Succeeded in setting Speed!'); 806 } 807 }); 808} 809``` 810 811## setSpeed<sup>(deprecated)</sup> 812 813setSpeed(speed: number): Promise\<number> 814 815Sets the playback speed. This API uses a promise to return the result. 816 817> **NOTE** 818> 819> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.setSpeed](arkts-apis-media-AVPlayer.md#setspeed9) instead. 820 821**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 822 823**Parameters** 824 825| Name| Type | Mandatory| Description | 826| ------ | ------ | ---- | ---------------------------------------------------------- | 827| speed | number | Yes | Video playback speed. For details, see [PlaybackSpeed](arkts-apis-media-e.md#playbackspeed8).| 828 829**Return value** 830 831| Type | Description | 832| ---------------- | ------------------------------------------------------------ | 833| Promise\<number>| Promise used to return the playback speed. For details, see [PlaybackSpeed](arkts-apis-media-e.md#playbackspeed8).| 834 835**Example** 836 837```ts 838import { BusinessError } from '@kit.BasicServicesKit'; 839 840let videoPlayer: media.VideoPlayer | null = null; 841media.createVideoPlayer((error: BusinessError, video: media.VideoPlayer) => { 842 if (video != null) { 843 videoPlayer = video; 844 console.info('Succeeded in creating VideoPlayer'); 845 } else { 846 console.error(`Failed to create VideoPlayer, error:${error}`); 847 } 848}); 849let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; 850if (videoPlayer) { 851 (videoPlayer as media.VideoPlayer).setSpeed(speed).then((result: number) => { 852 console.info('Succeeded in setting Speed'); 853 }).catch((error: BusinessError) => { 854 console.error(`Failed to set Speed, error:${error}`);//todo:: error. 855 }); 856} 857``` 858 859## on('playbackCompleted')<sup>(deprecated)</sup> 860 861on(type: 'playbackCompleted', callback: Callback\<void>): void 862 863Subscribes to the video playback completion event. 864 865> **NOTE** 866> 867> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('stateChange')](arkts-apis-media-AVPlayer.md#onstatechange9) instead. 868 869**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 870 871**Parameters** 872 873| Name | Type | Mandatory| Description | 874| -------- | -------- | ---- | ----------------------------------------------------------- | 875| type | string | Yes | Event type, which is **'playbackCompleted'** in this case.| 876| callback | Callback\<void> | Yes | Callback invoked when the event is triggered. | 877 878**Example** 879 880```ts 881videoPlayer.on('playbackCompleted', () => { 882 console.info('playbackCompleted called!'); 883}); 884``` 885 886## on('bufferingUpdate')<sup>(deprecated)</sup> 887 888on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void 889 890Subscribes to the video buffering update event. This API works only under online playback. 891 892> **NOTE** 893> 894> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('bufferingUpdate')](arkts-apis-media-AVPlayer.md#onbufferingupdate9) instead. 895 896**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 897 898**Parameters** 899 900| Name | Type | Mandatory| Description | 901| -------- | -------- | ---- | ------------------------------------------------------------ | 902| type | string | Yes | Event type, which is **'bufferingUpdate'** in this case. | 903| callback | function | Yes | Callback invoked when the event is triggered.<br>The value of [BufferingInfoType](arkts-apis-media-e.md#bufferinginfotype8) is fixed at **0**.| 904 905**Example** 906 907```ts 908videoPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => { 909 console.info('video bufferingInfo type: ' + infoType); 910 console.info('video bufferingInfo value: ' + value); 911}); 912``` 913 914## on('startRenderFrame')<sup>(deprecated)</sup> 915 916on(type: 'startRenderFrame', callback: Callback\<void>): void 917 918Subscribes to the frame rendering start event. 919 920> **NOTE** 921> 922> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('startRenderFrame')](arkts-apis-media-AVPlayer.md#onstartrenderframe9) instead. 923 924**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 925 926**Parameters** 927 928| Name | Type | Mandatory| Description | 929| -------- | --------------- | ---- | ------------------------------------------------------------ | 930| type | string | Yes | Event type, which is **'startRenderFrame'** in this case.| 931| callback | Callback\<void> | Yes | Callback invoked when the event is triggered. | 932 933**Example** 934 935```ts 936videoPlayer.on('startRenderFrame', () => { 937 console.info('startRenderFrame called!'); 938}); 939``` 940 941## on('videoSizeChanged')<sup>(deprecated)</sup> 942 943on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void 944 945Subscribes to the video width and height change event. 946 947> **NOTE** 948> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('videoSizeChange')](arkts-apis-media-AVPlayer.md#onvideosizechange9) instead. 949 950**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 951 952**Parameters** 953 954| Name | Type | Mandatory| Description | 955| -------- | -------- | ---- | ------------------------------------------------------------ | 956| type | string | Yes | Event type, which is **'videoSizeChanged'** in this case.| 957| callback | function | Yes | Callback invoked when the event is triggered. **width** indicates the video width, and **height** indicates the video height. | 958 959**Example** 960 961```ts 962videoPlayer.on('videoSizeChanged', (width: number, height: number) => { 963 console.info('video width is: ' + width); 964 console.info('video height is: ' + height); 965}); 966``` 967## on('audioInterrupt')<sup>(deprecated)</sup> 968 969on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void 970 971Subscribes to the audio interruption event. For details, see [audio.InterruptEvent](../apis-audio-kit/arkts-apis-audio-i.md#interruptevent9). 972 973> **NOTE** 974> 975> This API is supported since API version 9 and deprecated since API version 9. You are advised to use [AVPlayer.on('audioInterrupt')](arkts-apis-media-AVPlayer.md#onaudiointerrupt9) instead. 976 977**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 978 979**Parameters** 980 981| Name | Type | Mandatory| Description | 982| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 983| type | string | Yes | Event type, which is **'audioInterrupt'** in this case.| 984| callback | function | Yes | Callback invoked when the event is triggered. | 985 986**Example** 987 988```ts 989import { audio } from '@kit.AudioKit'; 990 991videoPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => { 992 console.info('audioInterrupt called,and InterruptEvent info is:' + info); 993}); 994``` 995 996## on('error')<sup>(deprecated)</sup> 997 998on(type: 'error', callback: ErrorCallback): void 999 1000Subscribes to video playback error events. After an error event is reported, you must handle the event and exit the playback. 1001 1002> **NOTE** 1003> 1004> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [AVPlayer.on('error')](arkts-apis-media-AVPlayer.md#onerror9) instead. 1005 1006**System capability**: SystemCapability.Multimedia.Media.VideoPlayer 1007 1008**Parameters** 1009 1010| Name | Type | Mandatory| Description | 1011| -------- | ------------- | ---- | ------------------------------------------------------------ | 1012| type | string | Yes | Event type, which is **'error'** in this case.<br>This event is triggered when an error occurs during video playback.| 1013| callback | [ErrorCallback](../apis-basic-services-kit/js-apis-base.md#errorcallback) | Yes | Callback invoked when the event is triggered. | 1014 1015**Example** 1016 1017```ts 1018import { BusinessError } from '@kit.BasicServicesKit'; 1019 1020videoPlayer.on('error', (error: BusinessError) => { // Set the 'error' event callback. 1021 console.error(`video error called, error: ${error}`); 1022}); 1023videoPlayer.url = 'fd://error'; // Set an incorrect URL to trigger the 'error' event. 1024``` 1025