1# AVPlayer 2 3 4## Overview 5 6The AVPlayer module provides APIs related to media playback. 7 8**System capability**: SystemCapability.Multimedia.Media.AVPlayer 9 10**Since**: 11 11 12 13## Summary 14 15 16### Files 17 18| Name| Description| 19| -------- | -------- | 20| [avplayer.h](avplayer_8h.md) | Declares the AVPlayer APIs. You can use the native AVPlayer APIs to play a media asset.| 21| [avplayer_base.h](avplayer__base_8h.md) | Declares the structs and enums of the AVPlayer.| 22 23 24### Structs 25 26| Name| Description| 27| -------- | -------- | 28| [AVPlayerCallback](_a_v_player_callback.md) | Defines all the callback function pointers of an **OH_AVPlayer** instance.| 29 30 31### Types 32 33| Name| Description| 34| -------- | -------- | 35| [AVPlayerState](#avplayerstate) | Defines an enum that enumerates the AVPlayer states.| 36| [AVPlayerSeekMode](#avplayerseekmode) | Defines an enum that enumerates the seek modes of the AVPlayer.| 37| [AVPlaybackSpeed](#avplaybackspeed) | Defines an enum that enumerates the playback speeds of the AVPlayer.| 38| [AVPlayerOnInfoType](#avplayeroninfotype) | Defines an enum that enumerates the types of messages received by the AVPlayer.| 39| (\*[OH_AVPlayerOnInfo](#oh_avplayeroninfo)) (OH_AVPlayer \*player, [AVPlayerOnInfoType](#avplayeroninfotype) type, int32_t extra) | Defines the callback when the AVPlayer receives a message.| 40| (\*[OH_AVPlayerOnError](#oh_avplayeronerror)) (OH_AVPlayer \*player, int32_t errorCode, const char \*errorMsg) | Defines the callback when an error occurs in the AVPlayer. This type is available in API version 9 or later.| 41| [AVPlayerCallback](#avplayercallback) | Defines all the callback function pointers of an **OH_AVPlayer** instance.| 42 43 44### Enums 45 46| Name| Description| 47| -------- | -------- | 48| [AVPlayerState](#avplayerstate) {<br>AV_IDLE = 0, AV_INITIALIZED = 1, AV_PREPARED = 2, AV_PLAYING = 3,<br>AV_PAUSED = 4, AV_STOPPED = 5, AV_COMPLETED = 6, AV_RELEASED = 7,<br>AV_ERROR = 8<br>} | Enumerates the AVPlayer states.| 49| [AVPlayerSeekMode](#avplayerseekmode) { AV_SEEK_NEXT_SYNC = 0, AV_SEEK_PREVIOUS_SYNC } | Enumerates the seek modes of the AVPlayer.| 50| [AVPlaybackSpeed](#avplaybackspeed) {<br>AV_SPEED_FORWARD_0_75_X, AV_SPEED_FORWARD_1_00_X, AV_SPEED_FORWARD_1_25_X, AV_SPEED_FORWARD_1_75_X,<br>AV_SPEED_FORWARD_2_00_X<br>} | Enumerates the playback speeds of the AVPlayer.| 51| [AVPlayerOnInfoType](#avplayeroninfotype) {<br>AV_INFO_TYPE_SEEKDONE = 0, AV_INFO_TYPE_SPEEDDONE = 1, AV_INFO_TYPE_BITRATEDONE = 2, AV_INFO_TYPE_EOS = 3,<br>AV_INFO_TYPE_STATE_CHANGE = 4, AV_INFO_TYPE_POSITION_UPDATE = 5, AV_INFO_TYPE_MESSAGE = 6, AV_INFO_TYPE_VOLUME_CHANGE = 7,<br>AV_INFO_TYPE_RESOLUTION_CHANGE = 8, AV_INFO_TYPE_BUFFERING_UPDATE = 9, AV_INFO_TYPE_BITRATE_COLLECT = 10, AV_INFO_TYPE_INTERRUPT_EVENT = 11,<br>AV_INFO_TYPE_DURATION_UPDATE = 12, AV_INFO_TYPE_IS_LIVE_STREAM = 13, AV_INFO_TYPE_TRACKCHANGE = 14, AV_INFO_TYPE_TRACK_INFO_UPDATE = 15,<br>AV_INFO_TYPE_SUBTITLE_UPDATE = 16<br>} | Enumerates the types of messages received by the AVPlayer.| 52 53 54### Functions 55 56| Name| Description| 57| -------- | -------- | 58| \*[OH_AVPlayer_Create](#oh_avplayer_create) (void) | Creates an **OH_AVPlayer** instance.| 59| [OH_AVPlayer_SetURLSource](#oh_avplayer_seturlsource) (OH_AVPlayer \*player, const char \*url) | Sets the HTTP URL of a media source to be played by an AVPlayer. | 60| [OH_AVPlayer_SetFDSource](#oh_avplayer_setfdsource) (OH_AVPlayer \*player, int32_t fd, int64_t offset, int64_t size) | Sets the file descriptor of a media source to be played by an AVPlayer.| 61| [OH_AVPlayer_Prepare](#oh_avplayer_prepare) (OH_AVPlayer \*player) | Prepares the playback environment and buffers media data.| 62| [OH_AVPlayer_Play](#oh_avplayer_play) (OH_AVPlayer \*player) | Starts playback.| 63| [OH_AVPlayer_Pause](#oh_avplayer_pause) (OH_AVPlayer \*player) | Pauses playback.| 64| [OH_AVPlayer_Stop](#oh_avplayer_stop) (OH_AVPlayer \*player) | Stops playback.| 65| [OH_AVPlayer_Reset](#oh_avplayer_reset) (OH_AVPlayer \*player) | Restores the AVPlayer to the initial state.| 66| [OH_AVPlayer_Release](#oh_avplayer_release) (OH_AVPlayer \*player) | Asynchronously releases an **OH_AVPlayer** instance.| 67| [OH_AVPlayer_ReleaseSync](#oh_avplayer_releasesync) (OH_AVPlayer \*player) | Synchronously releases an **OH_AVPlayer** instance.| 68| [OH_AVPlayer_SetVolume](#oh_avplayer_setvolume) (OH_AVPlayer \*player, float leftVolume, float rightVolume) | Sets the volume for an AVPlayer.| 69| [OH_AVPlayer_Seek](#oh_avplayer_seek) (OH_AVPlayer \*player, int32_t mSeconds, [AVPlayerSeekMode](#avplayerseekmode) mode) | Seeks to a playback position.| 70| [OH_AVPlayer_GetCurrentTime](#oh_avplayer_getcurrenttime) (OH_AVPlayer \*player, int32_t \*currentTime) | Obtains the playback position, in milliseconds.| 71| [OH_AVPlayer_GetVideoWidth](#oh_avplayer_getvideowidth) (OH_AVPlayer \*player, int32_t \*videoWidth) | Obtains the video width.| 72| [OH_AVPlayer_GetVideoHeight](#oh_avplayer_getvideoheight) (OH_AVPlayer \*player, int32_t \*videoHeight) | Obtains the video height.| 73| [OH_AVPlayer_SetPlaybackSpeed](#oh_avplayer_setplaybackspeed) (OH_AVPlayer \*player, [AVPlaybackSpeed](#avplaybackspeed) speed) | Sets the playback speed for an AVPlayer.| 74| [OH_AVPlayer_GetPlaybackSpeed](#oh_avplayer_getplaybackspeed) (OH_AVPlayer \*player, [AVPlaybackSpeed](#avplaybackspeed) \*speed) | Obtains the playback speed of an AVPlayer.| 75| [OH_AVPlayer_SelectBitRate](#oh_avplayer_selectbitrate) (OH_AVPlayer \*player, uint32_t bitRate) | Sets the bit rate used by an HLS player.| 76| [OH_AVPlayer_SetVideoSurface](#oh_avplayer_setvideosurface) (OH_AVPlayer \*player, OHNativeWindow \*window) | Sets a playback window.| 77| [OH_AVPlayer_GetDuration](#oh_avplayer_getduration) (OH_AVPlayer \*player, int32_t \*duration) | Obtains the total duration of a media file, in milliseconds.| 78| [OH_AVPlayer_GetState](#oh_avplayer_getstate) (OH_AVPlayer \*player, [AVPlayerState](#avplayerstate) \*state) | Obtains the AVPlayer state.| 79| [OH_AVPlayer_IsPlaying](#oh_avplayer_isplaying) (OH_AVPlayer \*player) | Checks whether an AVPlayer is playing.| 80| [OH_AVPlayer_IsLooping](#oh_avplayer_islooping) (OH_AVPlayer \*player) | Checks whether an AVPlayer is looping.| 81| [OH_AVPlayer_SetLooping](#oh_avplayer_setlooping) (OH_AVPlayer \*player, bool loop) | Enables loop playback.| 82| [OH_AVPlayer_SetPlayerCallback](#oh_avplayer_setplayercallback) (OH_AVPlayer \*player, [AVPlayerCallback](_a_v_player_callback.md) callback) | Sets a callback for an AVPlayer.| 83| [OH_AVPlayer_SelectTrack](#oh_avplayer_selecttrack) (OH_AVPlayer \*player, int32_t index) | Selects an audio or subtitle track.| 84| [OH_AVPlayer_DeselectTrack](#oh_avplayer_deselecttrack) (OH_AVPlayer \*player, int32_t index) | Deselects an audio or subtitle track.| 85| [OH_AVPlayer_GetCurrentTrack](#oh_avplayer_getcurrenttrack) (OH_AVPlayer \*player, int32_t trackType, int32_t \*index) | Obtains the currently valid track.| 86 87 88### Variables 89 90| Name| Description| 91| -------- | -------- | 92| [AVPlayerCallback::onInfo](#oninfo) | Defines the AVPlayer process information. For details, see [OH_AVPlayerOnInfo](oh_avplayeroninfo).| 93| [AVPlayerCallback::onError](#onerror) | Defines the AVPlayer error information. For details, see [OH_AVPlayerOnError](_oh_avplayeronerror).| 94 95 96## Type Description 97 98 99### AVPlaybackSpeed 100 101``` 102typedef enum AVPlaybackSpeedAVPlaybackSpeed 103``` 104 105**Description** 106 107Defines an enum that enumerates the playback speeds of the AVPlayer. 108 109**System capability**: SystemCapability.Multimedia.Media.AVPlayer 110 111**Since**: 11 112 113 114### AVPlayerCallback 115 116``` 117typedef struct AVPlayerCallbackAVPlayerCallback 118``` 119 120**Description** 121 122Defines all the callback function pointers of an **OH_AVPlayer** instance. To ensure the normal running of **OH_AVPlayer**, you must register the instance of this struct with the **OH_AVPlayer** instance and process the information reported by the callback functions. 123 124**System capability**: SystemCapability.Multimedia.Media.AVPlayer 125 126**Since**: 11 127 128 129### AVPlayerOnInfoType 130 131``` 132typedef enum AVPlayerOnInfoTypeAVPlayerOnInfoType 133``` 134 135**Description** 136 137Defines an enum that enumerates the types of messages received by the AVPlayer. 138 139**System capability**: SystemCapability.Multimedia.Media.AVPlayer 140 141**Since**: 11 142 143 144### AVPlayerSeekMode 145 146``` 147typedef enum AVPlayerSeekModeAVPlayerSeekMode 148``` 149 150**Description** 151 152Defines an enum that enumerates the seek modes of the AVPlayer. 153 154**System capability**: SystemCapability.Multimedia.Media.AVPlayer 155 156**Since**: 11 157 158 159### AVPlayerState 160 161``` 162typedef enum AVPlayerStateAVPlayerState 163``` 164 165**Description** 166 167Defines an enum that enumerates the AVPlayer states. 168 169**System capability**: SystemCapability.Multimedia.Media.AVPlayer 170 171**Since**: 11 172 173 174### OH_AVPlayerOnError 175 176``` 177typedef void(* OH_AVPlayerOnError) (OH_AVPlayer *player, int32_t errorCode, const char *errorMsg) 178``` 179 180**Description** 181 182Defines the callback when an error occurs in the AVPlayer. This type is available in API version 9 or later. 183 184**System capability**: SystemCapability.Multimedia.Media.AVPlayer 185 186**Since**: 11 187 188**Parameters** 189 190| Name| Description| 191| -------- | -------- | 192| player | Pointer to an **OH_AVPlayer** instance.| 193| errorCode | Error code.| 194| errorMsg | Pointer to an error message.| 195 196 197### OH_AVPlayerOnInfo 198 199``` 200typedef void(* OH_AVPlayerOnInfo) (OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra) 201``` 202 203**Description** 204 205Defines the callback when the AVPlayer receives a message. 206 207**System capability**: SystemCapability.Multimedia.Media.AVPlayer 208 209**Since**: 11 210 211**Parameters** 212 213| Name| Description| 214| -------- | -------- | 215| player | Pointer to an **OH_AVPlayer** instance.| 216| type | Message type. For details, see [AVPlayerOnInfoType](#avplayeroninfotype).| 217| extra | Other information, such as the start time and position of the media file to play.| 218 219 220## Enum Description 221 222 223### AVPlaybackSpeed 224 225``` 226enum AVPlaybackSpeed 227``` 228 229**Description** 230 231Enumerates the playback speeds of the AVPlayer. 232 233**System capability**: SystemCapability.Multimedia.Media.AVPlayer 234 235**Since**: 11 236 237| Value| Description| 238| -------- | -------- | 239| AV_SPEED_FORWARD_0_75_X | Plays the video at 0.75 times the normal speed.| 240| AV_SPEED_FORWARD_1_00_X | Plays the video at the normal speed.| 241| AV_SPEED_FORWARD_1_25_X | Plays the video at 1.25 times the normal speed.| 242| AV_SPEED_FORWARD_1_75_X | Plays the video at 1.75 times the normal speed.| 243| AV_SPEED_FORWARD_2_00_X | Plays the video at 2.0 times the normal speed.| 244 245 246### AVPlayerOnInfoType 247 248``` 249enum AVPlayerOnInfoType 250``` 251 252**Description** 253 254Enumerates the types of messages received by the AVPlayer. 255 256**System capability**: SystemCapability.Multimedia.Media.AVPlayer 257 258**Since**: 11 259 260| Value| Description| 261| -------- | -------- | 262| AV_INFO_TYPE_SEEKDONE | Message returned when seeking to a playback position is complete.| 263| AV_INFO_TYPE_SPEEDDONE | Message returned when the playback speed setting is complete.| 264| AV_INFO_TYPE_BITRATEDONE | Message returned when the bit rate setting is complete.| 265| AV_INFO_TYPE_EOS | Message returned when the playback is complete.| 266| AV_INFO_TYPE_STATE_CHANGE | Message returned when the AVPlayer state changes.| 267| AV_INFO_TYPE_POSITION_UPDATE | Message returned when the playback position changes.| 268| AV_INFO_TYPE_MESSAGE | Message returned when the playback message is received.| 269| AV_INFO_TYPE_VOLUME_CHANGE | Message returned when the playback volume changes.| 270| AV_INFO_TYPE_RESOLUTION_CHANGE | Message returned when the video size is obtained for the first time or the video size is updated.| 271| AV_INFO_TYPE_BUFFERING_UPDATE | Message returned when multi-queue buffering changes.| 272| AV_INFO_TYPE_BITRATE_COLLECT | Message returned when the bit rate conflicts.| 273| AV_INFO_TYPE_INTERRUPT_EVENT | Message returned when the audio focus changes.| 274| AV_INFO_TYPE_DURATION_UPDATE | Message returned when the playback duration changes.| 275| AV_INFO_TYPE_IS_LIVE_STREAM | Message returned when live streams are played.| 276| AV_INFO_TYPE_TRACKCHANGE | Message returned when the track changes.| 277| AV_INFO_TYPE_TRACK_INFO_UPDATE | Message returned when the subtitle track information changes.| 278| AV_INFO_TYPE_SUBTITLE_UPDATE | Message returned when the subtitle information changes.| 279 280 281### AVPlayerSeekMode 282 283``` 284enum AVPlayerSeekMode 285``` 286 287**Description** 288 289Enumerates the seek modes of the AVPlayer. 290 291**System capability**: SystemCapability.Multimedia.Media.AVPlayer 292 293**Since**: 11 294 295| Value| Description| 296| -------- | -------- | 297| AV_SEEK_NEXT_SYNC | Seeks to the next key frame at the specified position.| 298| AV_SEEK_PREVIOUS_SYNC | Seeks to the previous key frame at the specified position.| 299 300 301### AVPlayerState 302 303``` 304enum AVPlayerState 305``` 306 307**Description** 308 309Enumerates the AVPlayer states. 310 311**System capability**: SystemCapability.Multimedia.Media.AVPlayer 312 313**Since**: 11 314 315| Value| Description| 316| -------- | -------- | 317| AV_IDLE | The AVPlayer is idle.| 318| AV_INITIALIZED | The AVPlayer is initialized.| 319| AV_PREPARED | The AVPlayer is ready for playback.| 320| AV_PLAYING | The AVPlayer is playing.| 321| AV_PAUSED | The AVPlayer is paused.| 322| AV_STOPPED | The AVPlayer is stopped.| 323| AV_COMPLETED | The AVPlayer finishes playing.| 324| AV_RELEASED | The AVPlayer is released.| 325| AV_ERROR | An error occurs.| 326 327 328## Function Description 329 330 331### OH_AVPlayer_Create() 332 333``` 334OH_AVPlayer* OH_AVPlayer_Create (void ) 335``` 336 337**Description** 338 339Creates an **OH_AVPlayer** instance. 340 341**System capability**: SystemCapability.Multimedia.Media.AVPlayer 342 343**Since**: 11 344 345**Returns** 346 347Returns the pointer to an **OH_AVPlayer** instance. 348 349 350### OH_AVPlayer_DeselectTrack() 351 352``` 353OH_AVErrCode OH_AVPlayer_DeselectTrack (OH_AVPlayer * player, int32_t index ) 354``` 355 356**Description** 357 358Deselects an audio or subtitle track. 359 360**System capability**: SystemCapability.Multimedia.Media.AVPlayer 361 362**Since**: 11 363 364**Parameters** 365 366| Name| Description| 367| -------- | -------- | 368| player | Pointer to an **OH_AVPlayer** instance.| 369| index | Index of the track.| 370 371**Returns** 372 373Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in **native_averrors.h** otherwise. 374 375 376### OH_AVPlayer_GetCurrentTime() 377 378``` 379OH_AVErrCode OH_AVPlayer_GetCurrentTime (OH_AVPlayer * player, int32_t * currentTime ) 380``` 381 382**Description** 383 384Obtains the playback position, in milliseconds. 385 386**System capability**: SystemCapability.Multimedia.Media.AVPlayer 387 388**Since**: 11 389 390**Parameters** 391 392| Name| Description| 393| -------- | -------- | 394| player | Pointer to an **OH_AVPlayer** instance.| 395| currentTime | Pointer to the playback position.| 396 397**Returns** 398 399Returns **AV_ERR_OK** if the playback position is obtained; returns an error code defined in **native_averrors.h** otherwise. 400 401 402### OH_AVPlayer_GetCurrentTrack() 403 404``` 405OH_AVErrCode OH_AVPlayer_GetCurrentTrack (OH_AVPlayer * player, int32_t trackType, int32_t * index ) 406``` 407 408**Description** 409 410Obtains the currently valid track. 411 412You can set the track to the prepared, playing, paused, or completed state. 413 414**System capability**: SystemCapability.Multimedia.Media.AVPlayer 415 416**Since**: 11 417 418**Parameters** 419 420| Name| Description| 421| -------- | -------- | 422| player | Pointer to an **OH_AVPlayer** instance.| 423| trackType | Track type.| 424| index | Pointer to the index of the track.| 425 426**Returns** 427 428Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in **native_averrors.h** otherwise. 429 430 431### OH_AVPlayer_GetDuration() 432 433``` 434OH_AVErrCode OH_AVPlayer_GetDuration (OH_AVPlayer * player, int32_t * duration ) 435``` 436 437**Description** 438 439Obtains the total duration of a media file, in milliseconds. 440 441**System capability**: SystemCapability.Multimedia.Media.AVPlayer 442 443**Since**: 11 444 445**Parameters** 446 447| Name| Description| 448| -------- | -------- | 449| player | Pointer to an **OH_AVPlayer** instance.| 450| duration | Pointer to the total duration.| 451 452**Returns** 453 454Returns **AV_ERR_OK** if the total duration is obtained; returns an error code defined in **native_averrors.h** otherwise. 455 456 457### OH_AVPlayer_GetPlaybackSpeed() 458 459``` 460OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed (OH_AVPlayer * player, AVPlaybackSpeed * speed ) 461``` 462 463**Description** 464 465Obtains the playback speed of an AVPlayer. 466 467**System capability**: SystemCapability.Multimedia.Media.AVPlayer 468 469**Since**: 11 470 471**Parameters** 472 473| Name| Description| 474| -------- | -------- | 475| player | Pointer to an **OH_AVPlayer** instance.| 476| speed | Pointer to the playback speed. For details, see [AVPlaybackSpeed](#avplaybackspeed).| 477 478**Returns** 479 480Returns **AV_ERR_OK** if the playback speed is obtained; returns an error code defined in **native_averrors.h** otherwise. 481 482 483### OH_AVPlayer_GetState() 484 485``` 486OH_AVErrCode OH_AVPlayer_GetState (OH_AVPlayer * player, AVPlayerState * state ) 487``` 488 489**Description** 490 491Obtains the AVPlayer state. 492 493**System capability**: SystemCapability.Multimedia.Media.AVPlayer 494 495**Since**: 11 496 497**Parameters** 498 499| Name| Description| 500| -------- | -------- | 501| player | Pointer to an **OH_AVPlayer** instance.| 502| state | Pointer to the state.| 503 504**Returns** 505 506Returns **AV_ERR_OK** if the state is obtained; returns an error code defined in **native_averrors.h** otherwise. 507 508 509### OH_AVPlayer_GetVideoHeight() 510 511``` 512OH_AVErrCode OH_AVPlayer_GetVideoHeight (OH_AVPlayer * player, int32_t * videoHeight ) 513``` 514 515**Description** 516 517Obtains the video height. 518 519**System capability**: SystemCapability.Multimedia.Media.AVPlayer 520 521**Since**: 11 522 523**Parameters** 524 525| Name| Description| 526| -------- | -------- | 527| player | Pointer to an **OH_AVPlayer** instance.| 528| videoHeights | Pointer to the video height.| 529 530**Returns** 531 532Returns **AV_ERR_OK** if the video height is obtained; returns an error code defined in **native_averrors.h** otherwise. 533 534 535### OH_AVPlayer_GetVideoWidth() 536 537``` 538OH_AVErrCode OH_AVPlayer_GetVideoWidth (OH_AVPlayer * player, int32_t * videoWidth ) 539``` 540 541**Description** 542 543Obtains the video width. 544 545**System capability**: SystemCapability.Multimedia.Media.AVPlayer 546 547**Since**: 11 548 549**Parameters** 550 551| Name| Description| 552| -------- | -------- | 553| player | Pointer to an **OH_AVPlayer** instance.| 554| videoWidth | Pointer to the video width.| 555 556**Returns** 557 558Returns **AV_ERR_OK** if the video width is obtained; returns an error code defined in **native_averrors.h** otherwise. 559 560 561### OH_AVPlayer_IsLooping() 562 563``` 564bool OH_AVPlayer_IsLooping (OH_AVPlayer * player) 565``` 566 567**Description** 568 569Checks whether an AVPlayer is looping. 570 571**System capability**: SystemCapability.Multimedia.Media.AVPlayer 572 573**Since**: 11 574 575**Parameters** 576 577| Name| Description| 578| -------- | -------- | 579| player | Pointer to an **OH_AVPlayer** instance.| 580 581**Returns** 582 583Returns **true** if the AVPlayer is looping; returns **false** otherwise. 584 585 586### OH_AVPlayer_IsPlaying() 587 588``` 589bool OH_AVPlayer_IsPlaying (OH_AVPlayer * player) 590``` 591 592**Description** 593 594Checks whether an AVPlayer is playing. 595 596**System capability**: SystemCapability.Multimedia.Media.AVPlayer 597 598**Since**: 11 599 600**Parameters** 601 602| Name| Description| 603| -------- | -------- | 604| player | Pointer to an **OH_AVPlayer** instance.| 605 606**Returns** 607 608Returns **true** if the AVPlayer is playing; returns **false** otherwise. 609 610 611### OH_AVPlayer_Pause() 612 613``` 614OH_AVErrCode OH_AVPlayer_Pause (OH_AVPlayer * player) 615``` 616 617**Description** 618 619Pauses playback. 620 621**System capability**: SystemCapability.Multimedia.Media.AVPlayer 622 623**Since**: 11 624 625**Parameters** 626 627| Name| Description| 628| -------- | -------- | 629| player | Pointer to an **OH_AVPlayer** instance.| 630 631**Returns** 632 633Returns **AV_ERR_OK** if the playback is paused; returns an error code defined in **native_averrors.h** otherwise. 634 635 636### OH_AVPlayer_Play() 637 638``` 639OH_AVErrCode OH_AVPlayer_Play (OH_AVPlayer * player) 640``` 641 642**Description** 643 644Starts playback. 645 646This function must be called after **Prepare**. In other words, you can call this function when the AVPlayer is in the prepared state. 647 648**System capability**: SystemCapability.Multimedia.Media.AVPlayer 649 650**Since**: 11 651 652**Parameters** 653 654| Name| Description| 655| -------- | -------- | 656| player | Pointer to an **OH_AVPlayer** instance.| 657 658**Returns** 659 660Returns **AV_ERR_OK** if the playback starts; returns an error code defined in **native_averrors.h** otherwise. 661 662 663### OH_AVPlayer_Prepare() 664 665``` 666OH_AVErrCode OH_AVPlayer_Prepare (OH_AVPlayer * player) 667``` 668 669**Description** 670 671Prepares the playback environment and buffers media data. 672 673This function must be called after **SetSource**. 674 675**System capability**: SystemCapability.Multimedia.Media.AVPlayer 676 677**Since**: 11 678 679**Parameters** 680 681| Name| Description| 682| -------- | -------- | 683| player | Pointer to an **OH_AVPlayer** instance.| 684 685**Returns** 686 687Returns **AV_ERR_OK** if the playback environment is prepared; returns an error code defined in **native_averrors.h** otherwise. 688 689 690### OH_AVPlayer_Release() 691 692``` 693OH_AVErrCode OH_AVPlayer_Release (OH_AVPlayer * player) 694``` 695 696**Description** 697 698Asynchronously releases an **OH_AVPlayer** instance. 699 700The asynchronous function ensures the performance, but cannot ensure that the surface buffer of the playback window is released. You must ensure the lifecycle of the playback window. 701 702**System capability**: SystemCapability.Multimedia.Media.AVPlayer 703 704**Since**: 11 705 706**Parameters** 707 708| Name| Description| 709| -------- | -------- | 710| player | Pointer to an **OH_AVPlayer** instance.| 711 712**Returns** 713 714Returns **AV_ERR_OK** if the AVPlayer is released; returns an error code defined in **native_averrors.h** otherwise. 715 716 717### OH_AVPlayer_ReleaseSync() 718 719``` 720OH_AVErrCode OH_AVPlayer_ReleaseSync (OH_AVPlayer * player) 721``` 722 723**Description** 724 725Synchronously releases an **OH_AVPlayer** instance. 726 727The synchronous function ensures that the surface buffer of the playback window is released, with a long time (when the engine is not idle). Therefore, you need to design an asynchronous mechanism. 728 729**System capability**: SystemCapability.Multimedia.Media.AVPlayer 730 731**Since**: 11 732 733**Parameters** 734 735| Name| Description| 736| -------- | -------- | 737| player | Pointer to an **OH_AVPlayer** instance.| 738 739**Returns** 740 741Returns **AV_ERR_OK** if the AVPlayer is released; returns an error code defined in **native_averrors.h** otherwise. 742 743 744### OH_AVPlayer_Reset() 745 746``` 747OH_AVErrCode OH_AVPlayer_Reset (OH_AVPlayer * player) 748``` 749 750**Description** 751 752Restores the AVPlayer to the initial state. 753 754After the function is called, you can call **SetSource** to set the media source to play, and then call **Prepare** and **Play** in sequence. 755 756**System capability**: SystemCapability.Multimedia.Media.AVPlayer 757 758**Since**: 11 759 760**Parameters** 761 762| Name| Description| 763| -------- | -------- | 764| player | Pointer to an **OH_AVPlayer** instance.| 765 766**Returns** 767 768Returns **AV_ERR_OK** if the AVPlayer is reset; returns an error code defined in **native_averrors.h** otherwise. 769 770 771### OH_AVPlayer_Seek() 772 773``` 774OH_AVErrCode OH_AVPlayer_Seek (OH_AVPlayer * player, int32_t mSeconds, AVPlayerSeekMode mode ) 775``` 776 777**Description** 778 779Seeks to a playback position. 780 781This function can be used when the AVPlayer is in the playing or paused state. 782 783**System capability**: SystemCapability.Multimedia.Media.AVPlayer 784 785**Parameters** 786 787| Name| Description| 788| -------- | -------- | 789| player | Pointer to an **OH_AVPlayer** instance.| 790| mSeconds | Position to seek to, in ms.| 791| mode | Seek mode. For details, see [AVPlayerSeekMode](#avplayerseekmode).| 792 793 794### OH_AVPlayer_SelectBitRate() 795 796``` 797OH_AVErrCode OH_AVPlayer_SelectBitRate (OH_AVPlayer * player, uint32_t bitRate ) 798``` 799 800**Description** 801 802Sets the bit rate used by an HLS player, 803 804in bit/s. This function is valid only for HLS network streams. By default, the player selects a proper bit rate and speed based on the network connection. You can set a bit rate available in the valid bit rates reported in **INFO_TYPE_BITRATE_COLLECT**. The player selects a bit rate that is lower than or closest to the specified bit rate for playback. When ready, you can query the selected bit rate. 805 806**System capability**: SystemCapability.Multimedia.Media.AVPlayer 807 808**Since**: 11 809 810**Parameters** 811 812| Name| Description| 813| -------- | -------- | 814| player | Pointer to an **OH_AVPlayer** instance.| 815| bitRate | Bit rate, in kbit/s.| 816 817**Returns** 818 819Returns **AV_ERR_OK** if the setting is successful; returns an error code defined in **native_averrors.h** otherwise. 820 821 822### OH_AVPlayer_SelectTrack() 823 824``` 825OH_AVErrCode OH_AVPlayer_SelectTrack (OH_AVPlayer * player, int32_t index ) 826``` 827 828**Description** 829 830Selects an audio or subtitle track. 831 832By default, the first audio stream with data is played, and the subtitle track is not played. After the setting takes effect, the original track becomes invalid. Set the subtitle track to the prepared, playing, paused, or completed state, and set the audio track to the prepared state. 833 834**System capability**: SystemCapability.Multimedia.Media.AVPlayer 835 836**Since**: 11 837 838**Parameters** 839 840| Name| Description| 841| -------- | -------- | 842| player | Pointer to an **OH_AVPlayer** instance.| 843| index | Index of the track.| 844 845**Returns** 846 847Returns **AV_ERR_OK** if a track is selected; returns an error code defined in **native_averrors.h** otherwise. 848 849 850### OH_AVPlayer_SetFDSource() 851 852``` 853OH_AVErrCode OH_AVPlayer_SetFDSource (OH_AVPlayer * player, int32_t fd, int64_t offset, int64_t size ) 854``` 855 856**Description** 857 858Sets the file descriptor of a media source to be played by an AVPlayer. 859 860**System capability**: SystemCapability.Multimedia.Media.AVPlayer 861 862**Since**: 11 863 864**Parameters** 865 866| Name| Description| 867| -------- | -------- | 868| player | Pointer to an **OH_AVPlayer** instance.| 869| fd | File descriptor of the media source.| 870| offset | Offset of the media source in the file descriptor.| 871| size | Size of the media source.| 872 873**Returns** 874 875Returns **AV_ERR_OK** if the setting is successful; returns an error code defined in **native_averrors.h** otherwise. 876 877 878### OH_AVPlayer_SetLooping() 879 880``` 881OH_AVErrCode OH_AVPlayer_SetLooping (OH_AVPlayer * player, bool loop ) 882``` 883 884**Description** 885 886Enables loop playback. 887 888**System capability**: SystemCapability.Multimedia.Media.AVPlayer 889 890**Since**: 11 891 892**Parameters** 893 894| Name| Description| 895| -------- | -------- | 896| player | Pointer to an **OH_AVPlayer** instance.| 897| loop | Whether to enable loop playback.| 898 899**Returns** 900 901Returns **AV_ERR_OK** if the setting is successful; returns an error code defined in **native_averrors.h** otherwise. 902 903 904### OH_AVPlayer_SetPlaybackSpeed() 905 906``` 907OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed (OH_AVPlayer * player, AVPlaybackSpeed speed ) 908``` 909 910**Description** 911 912Sets the playback speed for an AVPlayer. 913 914**System capability**: SystemCapability.Multimedia.Media.AVPlayer 915 916**Parameters** 917 918| Name| Description| 919| -------- | -------- | 920| player | Pointer to an **OH_AVPlayer** instance.| 921| speed | Playback speed. For details, see [AVPlaybackSpeed](#avplaybackspeed).| 922 923 924### OH_AVPlayer_SetPlayerCallback() 925 926``` 927OH_AVErrCode OH_AVPlayer_SetPlayerCallback (OH_AVPlayer * player, AVPlayerCallback callback ) 928``` 929 930**Description** 931 932Sets a callback for an AVPlayer. 933 934**System capability**: SystemCapability.Multimedia.Media.AVPlayer 935 936**Since**: 11 937 938**Parameters** 939 940| Name| Description| 941| -------- | -------- | 942| player | Pointer to an **OH_AVPlayer** instance.| 943| callback | Callback.| 944 945**Returns** 946 947Returns **AV_ERR_OK** if the setting is successful; returns an error code defined in **native_averrors.h** otherwise. 948 949 950### OH_AVPlayer_SetURLSource() 951 952``` 953OH_AVErrCode OH_AVPlayer_SetURLSource (OH_AVPlayer * player, const char * url ) 954``` 955 956**Description** 957 958Sets the HTTP URL of a media source to be played by an AVPlayer. 959 960**System capability**: SystemCapability.Multimedia.Media.AVPlayer 961 962**Since**: 11 963 964**Parameters** 965 966| Name| Description| 967| -------- | -------- | 968| player | Pointer to an **OH_AVPlayer** instance.| 969| url | URL of the media source.| 970 971**Returns** 972 973Returns **AV_ERR_OK** if the setting is successful; returns an error code defined in **native_averrors.h** otherwise. 974 975 976### OH_AVPlayer_SetVideoSurface() 977 978``` 979OH_AVErrCode OH_AVPlayer_SetVideoSurface (OH_AVPlayer * player, OHNativeWindow * window ) 980``` 981 982**Description** 983 984Sets a playback window. 985 986**System capability**: SystemCapability.Multimedia.Media.AVPlayer 987 988**Parameters** 989 990| Name| Description| 991| -------- | -------- | 992| player | Pointer to an **OH_AVPlayer** instance.| 993| window | Pointer to an **OHNativeWindow** instance.| 994 995 996### OH_AVPlayer_SetVolume() 997 998``` 999OH_AVErrCode OH_AVPlayer_SetVolume (OH_AVPlayer * player, float leftVolume, float rightVolume ) 1000``` 1001 1002**Description** 1003 1004Sets the volume for an AVPlayer. 1005 1006This function can be used when the AVPlayer is in the playing or paused state. The value **0** means that the AVPlayer is muted, and **1** means that the original volume is used. 1007 1008**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1009 1010**Since**: 11 1011 1012**Parameters** 1013 1014| Name| Description| 1015| -------- | -------- | 1016| player | Pointer to an **OH_AVPlayer** instance.| 1017| leftVolume | Target volume of the left channel.| 1018| rightVolume | Target volume of the right channel.| 1019 1020**Returns** 1021 1022Returns **AV_ERR_OK** if the setting is successful; returns an error code defined in **native_averrors.h** otherwise. 1023 1024 1025### OH_AVPlayer_Stop() 1026 1027``` 1028OH_AVErrCode OH_AVPlayer_Stop (OH_AVPlayer * player) 1029``` 1030 1031**Description** 1032 1033Stops playback. 1034 1035**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1036 1037**Since**: 11 1038 1039**Parameters** 1040 1041| Name| Description| 1042| -------- | -------- | 1043| player | Pointer to an **OH_AVPlayer** instance.| 1044 1045**Returns** 1046 1047Returns **AV_ERR_OK** if the AVPlayer is stopped; returns an error code defined in **native_averrors.h** otherwise. 1048 1049 1050## Variable Description 1051 1052 1053### onError 1054 1055``` 1056OH_AVPlayerOnError AVPlayerCallback::onError 1057``` 1058 1059**Description** 1060 1061Defines the AVPlayer error information. For details, see [OH_AVPlayerOnError](_oh_avplayeronerror). 1062 1063 1064### onInfo 1065 1066``` 1067OH_AVPlayerOnInfo AVPlayerCallback::onInfo 1068``` 1069 1070**Description** 1071 1072Defines the AVPlayer process information. For details, see [OH_AVPlayerOnInfo](oh_avplayeroninfo). 1073