1# avplayer.h 2<!--Kit: Media Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @xushubo; @chennotfound--> 5<!--Designer: @dongyu_dy--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9## Overview 10 11The file declares the AVPlayer APIs. You can use the native AVPlayer APIs to play a media asset. 12 13**File to include**: <multimedia/player_framework/avplayer.h> 14 15**Library**: libavplayer.so 16 17**System capability**: SystemCapability.Multimedia.Media.AVPlayer 18 19**Since**: 11 20 21**Related module**: [AVPlayer](capi-avplayer.md) 22 23## Summary 24 25### Structs 26 27| Name| typedef Keyword| Description| 28| -- | -- | -- | 29| [MediaKeySession](capi-avplayer-mediakeysession.md) | MediaKeySession | Describes the media key session.| 30| [DRM_MediaKeySystemInfo](capi-avplayer-drm-mediakeysysteminfo.md) | DRM_MediaKeySystemInfo | Describes the media key system information.| 31 32### Functions 33 34| Name| typedef Keyword| Description| 35| -- | -- | -- | 36| [typedef void (\*Player_MediaKeySystemInfoCallback)(OH_AVPlayer \*player, DRM_MediaKeySystemInfo* mediaKeySystemInfo)](#player_mediakeysysteminfocallback) | Player_MediaKeySystemInfoCallback | Called when media key system information of the AVPlayer is updated.| 37| [OH_AVPlayer *OH_AVPlayer_Create(void)](#oh_avplayer_create) | - | Creates an OH_AVPlayer instance.<br>You are advised to create a maximum of 16 AVPlayer instances for an application in both audio and video playback scenarios.<!--Del--><br>The actual number of instances that can be created may be different. It depends on the specifications of the device chip in use. For example, in the case of RK3568, you are advised to create a maximum of 6 AVPlayer instances for an application in audio and video playback scenarios.<!--DelEnd--> | 38| [OH_AVErrCode OH_AVPlayer_SetURLSource(OH_AVPlayer *player, const char *url)](#oh_avplayer_seturlsource) | - | Sets the HTTP URL of a media source to be played by an AVPlayer. | 39| [OH_AVErrCode OH_AVPlayer_SetFDSource(OH_AVPlayer *player, int32_t fd, int64_t offset, int64_t size)](#oh_avplayer_setfdsource) | - | Sets the file descriptor of a media source to be played by an AVPlayer.| 40| [OH_AVErrCode OH_AVPlayer_Prepare(OH_AVPlayer *player)](#oh_avplayer_prepare) | - | Prepares the playback environment and buffers media data.<br>This function must be called after **SetSource**.| 41| [OH_AVErrCode OH_AVPlayer_Play(OH_AVPlayer *player)](#oh_avplayer_play) | - | Starts playback.<br>This function must be called after [OH_AVPlayer_Prepare](capi-avplayer-h.md#oh_avplayer_prepare).<br>In other words, you can call this function when the AVPlayer is in the prepared state.| 42| [OH_AVErrCode OH_AVPlayer_Pause(OH_AVPlayer *player)](#oh_avplayer_pause) | - | Pauses playback.| 43| [OH_AVErrCode OH_AVPlayer_Stop(OH_AVPlayer *player)](#oh_avplayer_stop) | - | Stops playback.| 44| [OH_AVErrCode OH_AVPlayer_Reset(OH_AVPlayer *player)](#oh_avplayer_reset) | - | Restores the AVPlayer to the initial state.<br>After the function is called, you can call **SetSource** to set the media source to play, and then call [OH_AVPlayer_Prepare](capi-avplayer-h.md#oh_avplayer_prepare) and [OH_AVPlayer_Play](capi-avplayer-h.md#oh_avplayer_play) in sequence.| 45| [OH_AVErrCode OH_AVPlayer_Release(OH_AVPlayer *player)](#oh_avplayer_release) | - | Asynchronously releases an OH_AVPlayer instance. The asynchronous function improves performance, but cannot ensure that the surface buffer of the playback window is released. You must ensure the lifecycle of the playback window.| 46| [OH_AVErrCode OH_AVPlayer_ReleaseSync(OH_AVPlayer *player)](#oh_avplayer_releasesync) | - | Synchronously releases an OH_AVPlayer instance.<br>The synchronous function ensures that the display buffer of the playback window is released, with a long time. Therefore, you need to design an asynchronous mechanism.| 47| [OH_AVErrCode OH_AVPlayer_SetVolume(OH_AVPlayer *player, float leftVolume, float rightVolume)](#oh_avplayer_setvolume) | - | Sets the volume for an AVPlayer.<br>This 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.| 48| [OH_AVErrCode OH_AVPlayer_Seek(OH_AVPlayer *player, int32_t mSeconds, AVPlayerSeekMode mode)](#oh_avplayer_seek) | - | Seeks to a playback position.<br>This function can be used when the AVPlayer is in the playing or paused state.| 49| [OH_AVErrCode OH_AVPlayer_GetCurrentTime(OH_AVPlayer *player, int32_t *currentTime)](#oh_avplayer_getcurrenttime) | - | Obtains the playback position, in milliseconds.| 50| [OH_AVErrCode OH_AVPlayer_GetVideoWidth(OH_AVPlayer *player, int32_t *videoWidth)](#oh_avplayer_getvideowidth) | - | Obtains the video width.| 51| [OH_AVErrCode OH_AVPlayer_GetVideoHeight(OH_AVPlayer *player, int32_t *videoHeight)](#oh_avplayer_getvideoheight) | - | Obtains the video height.| 52| [OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed speed)](#oh_avplayer_setplaybackspeed) | - | Sets the playback speed of an AVPlayer.| 53| [OH_AVErrCode OH_AVPlayer_SetPlaybackRate(OH_AVPlayer *player, float rate)](#oh_avplayer_setplaybackrate) | - | Sets the playback rate of an AVPlayer within the valid range.<br>The supported states are prepared, playing, paused, and completed.| 54| [OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed *speed)](#oh_avplayer_getplaybackspeed) | - | Obtains the playback speed of an AVPlayer.| 55| [OH_AVErrCode OH_AVPlayer_SetAudioRendererInfo(OH_AVPlayer *player, OH_AudioStream_Usage streamUsage)](#oh_avplayer_setaudiorendererinfo) | - | Sets the audio stream type for an AVPlayer.| 56| [OH_AVErrCode OH_AVPlayer_SetVolumeMode(OH_AVPlayer *player, OH_AudioStream_VolumeMode volumeMode)](#oh_avplayer_setvolumemode) | - | Sets the audio volume mode for an AVPlayer.| 57| [OH_AVErrCode OH_AVPlayer_SetAudioInterruptMode(OH_AVPlayer *player, OH_AudioInterrupt_Mode interruptMode)](#oh_avplayer_setaudiointerruptmode) | - | Sets the audio interruption mode for an AVPlayer.| 58| [OH_AVErrCode OH_AVPlayer_SetAudioEffectMode(OH_AVPlayer *player, OH_AudioStream_AudioEffectMode effectMode)](#oh_avplayer_setaudioeffectmode) | - | Sets the audio effect mode for an AVPlayer.| 59| [OH_AVErrCode OH_AVPlayer_SelectBitRate(OH_AVPlayer *player, uint32_t bitRate)](#oh_avplayer_selectbitrate) | - | Sets the bit rate used by an HLS player. This function is valid only for HLS network streams.<br>By default, the AVPlayer selects a proper bit rate and speed based on the network connection.<br>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 and closest to the specified bit rate. When ready, you can query the selected bit rate.| 60| [OH_AVErrCode OH_AVPlayer_SetVideoSurface(OH_AVPlayer *player, OHNativeWindow *window)](#oh_avplayer_setvideosurface) | - | Sets a playback window.<br>This function must be called after **SetSource** and before **Prepare**.| 61| [OH_AVErrCode OH_AVPlayer_GetDuration(OH_AVPlayer *player, int32_t *duration)](#oh_avplayer_getduration) | - | Obtains the total duration of a media file, in milliseconds.| 62| [OH_AVErrCode OH_AVPlayer_GetState(OH_AVPlayer *player, AVPlayerState *state)](#oh_avplayer_getstate) | - | Obtains the AVPlayer state.| 63| [bool OH_AVPlayer_IsPlaying(OH_AVPlayer *player)](#oh_avplayer_isplaying) | - | Checks whether an AVPlayer is playing.| 64| [bool OH_AVPlayer_IsLooping(OH_AVPlayer *player)](#oh_avplayer_islooping) | - | Checks whether an AVPlayer is looping.| 65| [OH_AVErrCode OH_AVPlayer_SetLooping(OH_AVPlayer *player, bool loop)](#oh_avplayer_setlooping) | - | Enables loop playback.| 66| [OH_AVErrCode OH_AVPlayer_SetPlayerCallback(OH_AVPlayer *player, AVPlayerCallback callback)](#oh_avplayer_setplayercallback) | - | Sets an AVPlayer callback.<br>The callbacks [OH_AVPlayerOnInfo](capi-avplayer-base-h.md#oh_avplayeroninfo) and [OH_AVPlayerOnError](capi-avplayer-base-h.md#oh_avplayeronerror) set by using this function can transfer limited information. In addition, it is inconvenient for the application to distinguish between multiple AVPlayer instances. Therefore, since API version 12, [OH_AVPlayer_SetOnInfoCallback](capi-avplayer-h.md#oh_avplayer_setoninfocallback) and [OH_AVPlayer_SetOnErrorCallback](capi-avplayer-h.md#oh_avplayer_setonerrorcallback) are provided to set the callbacks [OH_AVPlayerOnInfoCallback](capi-avplayer-base-h.md#oh_avplayeroninfocallback) and [OH_AVPlayerOnErrorCallback](capi-avplayer-base-h.md#oh_avplayeronerrorcallback), respectively.| 67| [OH_AVErrCode OH_AVPlayer_SelectTrack(OH_AVPlayer *player, int32_t index)](#oh_avplayer_selecttrack) | - | Selects an audio or subtitle track.<br>By default, the first audio track with data is played, and the subtitle track is not played.<br>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.<br>This function is not supported yet.| 68| [OH_AVErrCode OH_AVPlayer_DeselectTrack(OH_AVPlayer *player, int32_t index)](#oh_avplayer_deselecttrack) | - | Deselects an audio or subtitle track.<br>This function is not supported yet.| 69| [OH_AVErrCode OH_AVPlayer_GetCurrentTrack(OH_AVPlayer *player, int32_t trackType, int32_t *index)](#oh_avplayer_getcurrenttrack) | - | Obtains the currently valid track. You can set the track to the prepared, playing, paused, or completed state.<br>This function is not supported yet.| 70| [OH_AVErrCode OH_AVPlayer_SetMediaKeySystemInfoCallback(OH_AVPlayer *player, Player_MediaKeySystemInfoCallback callback)](#oh_avplayer_setmediakeysysteminfocallback) | - | Sets a callback to return the media key system information for an AVPlayer.| 71| [OH_AVErrCode OH_AVPlayer_GetMediaKeySystemInfo(OH_AVPlayer *player, DRM_MediaKeySystemInfo *mediaKeySystemInfo)](#oh_avplayer_getmediakeysysteminfo) | - | Obtains the media key system information to create a media key session.| 72| [OH_AVErrCode OH_AVPlayer_SetDecryptionConfig(OH_AVPlayer *player, MediaKeySession *mediaKeySession, bool secureVideoPath)](#oh_avplayer_setdecryptionconfig) | - | Sets the decryption information.| 73| [OH_AVErrCode OH_AVPlayer_SetOnInfoCallback(OH_AVPlayer *player, OH_AVPlayerOnInfoCallback callback, void *userData)](#oh_avplayer_setoninfocallback) | - | Sets a callback for the event indicating that the AVPlayer receives a message.| 74| [OH_AVErrCode OH_AVPlayer_SetOnErrorCallback(OH_AVPlayer *player, OH_AVPlayerOnErrorCallback callback, void *userData)](#oh_avplayer_setonerrorcallback) | - | Sets a callback for the event indicating that an error occurs in the AVPlayer.| 75 76## Function Description 77 78### Player_MediaKeySystemInfoCallback() 79 80``` 81typedef void (*Player_MediaKeySystemInfoCallback)(OH_AVPlayer *player, DRM_MediaKeySystemInfo* mediaKeySystemInfo) 82``` 83 84**Description** 85 86Called when media key system information of the AVPlayer is updated. 87 88**Since**: 12 89 90 91**Parameters** 92 93| Parameter| Description| 94| -- | -- | 95| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 96| [DRM_MediaKeySystemInfo](capi-avplayer-drm-mediakeysysteminfo.md)* mediaKeySystemInfo | Pointer to the media key system information.| 97 98### OH_AVPlayer_Create() 99 100``` 101OH_AVPlayer *OH_AVPlayer_Create(void) 102``` 103 104**Description** 105 106Creates an OH_AVPlayer instance.<br>You are advised to create a maximum of 16 AVPlayer instances for an application in both audio and video playback scenarios. 107 108<!--Del-->The actual number of instances that can be created may be different. It depends on the specifications of the device chip in use. For example, in the case of RK3568, you are advised to create a maximum of 6 AVPlayer instances for an application in audio and video playback scenarios.<!--DelEnd--> 109 110**System capability**: SystemCapability.Multimedia.Media.AVPlayer 111 112**Since**: 11 113 114**Returns** 115 116| Type| Description| 117| -- | -- | 118| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) | Pointer to the OH_AVPlayer instance created if the operation is successful; nullptr otherwise.<br> The possible causes of an operation failure are as follows:<br> 1. The execution of **PlayerFactory::CreatePlayer** fails.<br> 2. The execution of **new PlayerObject** fails.| 119 120### OH_AVPlayer_SetURLSource() 121 122``` 123OH_AVErrCode OH_AVPlayer_SetURLSource(OH_AVPlayer *player, const char *url) 124``` 125 126**Description** 127 128Sets the HTTP URL of a media source to be played by an AVPlayer. 129 130**System capability**: SystemCapability.Multimedia.Media.AVPlayer 131 132**Since**: 11 133 134 135**Parameters** 136 137| Parameter| Description| 138| -- | -- | 139| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 140| const char *url | URL of the media source.| 141 142**Returns** 143 144| Type| Description| 145| -- | -- | 146| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The setting is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, the input parameter **url** is null, or the execution of **player SetUrlSource** fails.| 147 148### OH_AVPlayer_SetFDSource() 149 150``` 151OH_AVErrCode OH_AVPlayer_SetFDSource(OH_AVPlayer *player, int32_t fd, int64_t offset, int64_t size) 152``` 153 154**Description** 155 156Sets the file descriptor of a media source to be played by an AVPlayer. 157 158**System capability**: SystemCapability.Multimedia.Media.AVPlayer 159 160**Since**: 11 161 162 163**Parameters** 164 165| Parameter| Description| 166| -- | -- | 167| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 168| int32_t fd | File descriptor of the media source.| 169| int64_t offset | Offset of the media source in the file descriptor.| 170| int64_t size | Size of the media source.| 171 172**Returns** 173 174| Type| Description| 175| -- | -- | 176| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The file descriptor is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player SetFdSource** fails.| 177 178### OH_AVPlayer_Prepare() 179 180``` 181OH_AVErrCode OH_AVPlayer_Prepare(OH_AVPlayer *player) 182``` 183 184**Description** 185 186Prepares the playback environment and buffers media data.<br>This function must be called after **SetSource**. 187 188**System capability**: SystemCapability.Multimedia.Media.AVPlayer 189 190**Since**: 11 191 192 193**Parameters** 194 195| Parameter| Description| 196| -- | -- | 197| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 198 199**Returns** 200 201| Type| Description| 202| -- | -- | 203| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player Prepare** fails.| 204 205### OH_AVPlayer_Play() 206 207``` 208OH_AVErrCode OH_AVPlayer_Play(OH_AVPlayer *player) 209``` 210 211**Description** 212 213Starts playback.<br>This function must be called after [OH_AVPlayer_Prepare](capi-avplayer-h.md#oh_avplayer_prepare).<br>In other words, you can call this function when the AVPlayer is in the prepared state. 214 215**System capability**: SystemCapability.Multimedia.Media.AVPlayer 216 217**Since**: 11 218 219 220**Parameters** 221 222| Parameter| Description| 223| -- | -- | 224| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 225 226**Returns** 227 228| Type| Description| 229| -- | -- | 230| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player Play** fails.| 231 232### OH_AVPlayer_Pause() 233 234``` 235OH_AVErrCode OH_AVPlayer_Pause(OH_AVPlayer *player) 236``` 237 238**Description** 239 240Pauses playback. 241 242**System capability**: SystemCapability.Multimedia.Media.AVPlayer 243 244**Since**: 11 245 246 247**Parameters** 248 249| Parameter| Description| 250| -- | -- | 251| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 252 253**Returns** 254 255| Type| Description| 256| -- | -- | 257| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player Pause** fails.| 258 259### OH_AVPlayer_Stop() 260 261``` 262OH_AVErrCode OH_AVPlayer_Stop(OH_AVPlayer *player) 263``` 264 265**Description** 266 267Stops playback. 268 269**System capability**: SystemCapability.Multimedia.Media.AVPlayer 270 271**Since**: 11 272 273 274**Parameters** 275 276| Parameter| Description| 277| -- | -- | 278| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 279 280**Returns** 281 282| Type| Description| 283| -- | -- | 284| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player Stop** fails.| 285 286### OH_AVPlayer_Reset() 287 288``` 289OH_AVErrCode OH_AVPlayer_Reset(OH_AVPlayer *player) 290``` 291 292**Description** 293 294Restores the AVPlayer to the initial state.<br>After the function is called, you can call **SetSource** to set the media source to play, and then call [OH_AVPlayer_Prepare](capi-avplayer-h.md#oh_avplayer_prepare) and [OH_AVPlayer_Play](capi-avplayer-h.md#oh_avplayer_play) in sequence. 295 296**System capability**: SystemCapability.Multimedia.Media.AVPlayer 297 298**Since**: 11 299 300 301**Parameters** 302 303| Parameter| Description| 304| -- | -- | 305| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 306 307**Returns** 308 309| Type| Description| 310| -- | -- | 311| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player Reset** fails.| 312 313### OH_AVPlayer_Release() 314 315``` 316OH_AVErrCode OH_AVPlayer_Release(OH_AVPlayer *player) 317``` 318 319**Description** 320 321Asynchronously releases an OH_AVPlayer instance.<br>The asynchronous function improves performance, but cannot ensure that the surface buffer of the playback window is released. You must ensure the lifecycle of the playback window. 322 323**System capability**: SystemCapability.Multimedia.Media.AVPlayer 324 325**Since**: 11 326 327 328**Parameters** 329 330| Parameter| Description| 331| -- | -- | 332| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 333 334**Returns** 335 336| Type| Description| 337| -- | -- | 338| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player Release** fails.| 339 340### OH_AVPlayer_ReleaseSync() 341 342``` 343OH_AVErrCode OH_AVPlayer_ReleaseSync(OH_AVPlayer *player) 344``` 345 346**Description** 347 348Synchronously releases an OH_AVPlayer instance.<br>The synchronous function ensures that the display buffer of the playback window is released, with a long time. Therefore, you need to design an asynchronous mechanism. 349 350**System capability**: SystemCapability.Multimedia.Media.AVPlayer 351 352**Since**: 11 353 354 355**Parameters** 356 357| Parameter| Description| 358| -- | -- | 359| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 360 361**Returns** 362 363| Type| Description| 364| -- | -- | 365| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player ReleaseSync** fails.| 366 367### OH_AVPlayer_SetVolume() 368 369``` 370OH_AVErrCode OH_AVPlayer_SetVolume(OH_AVPlayer *player, float leftVolume, float rightVolume) 371``` 372 373**Description** 374 375Sets the volume for an AVPlayer.<br>This 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. 376 377**System capability**: SystemCapability.Multimedia.Media.AVPlayer 378 379**Since**: 11 380 381 382**Parameters** 383 384| Parameter| Description| 385| -- | -- | 386| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 387| float leftVolume | Target volume of the left channel.| 388| float rightVolume | Target volume of the right channel.| 389 390**Returns** 391 392| Type| Description| 393| -- | -- | 394| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The volume is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player SetVolume** fails.| 395 396### OH_AVPlayer_Seek() 397 398``` 399OH_AVErrCode OH_AVPlayer_Seek(OH_AVPlayer *player, int32_t mSeconds, AVPlayerSeekMode mode) 400``` 401 402**Description** 403 404Seeks to a playback position.<br>This function can be used when the AVPlayer is in the playing or paused state. 405 406**System capability**: SystemCapability.Multimedia.Media.AVPlayer 407 408**Since**: 11 409 410 411**Parameters** 412 413| Parameter| Description| 414| -- | -- | 415| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 416| int32_t mSeconds | Position to seek to, in ms.| 417| [AVPlayerSeekMode](capi-avplayer-base-h.md#avplayerseekmode) mode | Seek mode.| 418 419**Returns** 420 421| Type| Description| 422| -- | -- | 423| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player Seek** fails.| 424 425### OH_AVPlayer_GetCurrentTime() 426 427``` 428OH_AVErrCode OH_AVPlayer_GetCurrentTime(OH_AVPlayer *player, int32_t *currentTime) 429``` 430 431**Description** 432 433Obtains the playback position, in milliseconds. 434 435**System capability**: SystemCapability.Multimedia.Media.AVPlayer 436 437**Since**: 11 438 439 440**Parameters** 441 442| Parameter| Description| 443| -- | -- | 444| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 445| int32_t *currentTime | Pointer to the playback position.| 446 447**Returns** 448 449| Type| Description| 450| -- | -- | 451| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The playback position is obtained.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player GetCurrentTime** fails.| 452 453### OH_AVPlayer_GetVideoWidth() 454 455``` 456OH_AVErrCode OH_AVPlayer_GetVideoWidth(OH_AVPlayer *player, int32_t *videoWidth) 457``` 458 459**Description** 460 461Obtains the video width. 462 463**System capability**: SystemCapability.Multimedia.Media.AVPlayer 464 465**Since**: 11 466 467 468**Parameters** 469 470| Parameter| Description| 471| -- | -- | 472| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 473| int32_t *videoWidth | Pointer to the video width.| 474 475**Returns** 476 477| Type| Description| 478| -- | -- | 479| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The video width is obtained.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr.| 480 481### OH_AVPlayer_GetVideoHeight() 482 483``` 484OH_AVErrCode OH_AVPlayer_GetVideoHeight(OH_AVPlayer *player, int32_t *videoHeight) 485``` 486 487**Description** 488 489Obtains the video height. 490 491**System capability**: SystemCapability.Multimedia.Media.AVPlayer 492 493**Since**: 11 494 495 496**Parameters** 497 498| Parameter| Description| 499| -- | -- | 500| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 501| int32_t *videoHeight | Pointer to the video height.| 502 503**Returns** 504 505| Type| Description| 506| -- | -- | 507| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The video height is obtained.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr.| 508 509### OH_AVPlayer_SetPlaybackSpeed() 510 511``` 512OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed speed) 513``` 514 515**Description** 516 517Sets the playback speed of the AVPlayer. For details about the playback speed, see [AVPlaybackSpeed](capi-avplayer-base-h.md#avplaybackspeed). 518 519**System capability**: SystemCapability.Multimedia.Media.AVPlayer 520 521**Since**: 11 522 523 524**Parameters** 525 526| Parameter| Description| 527| -- | -- | 528| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 529| [AVPlaybackSpeed](capi-avplayer-base-h.md#avplaybackspeed) speed | Playback speed.| 530 531**Returns** 532 533| Type| Description| 534| -- | -- | 535| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The playback speed is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr.| 536 537### OH_AVPlayer_SetPlaybackRate() 538 539``` 540OH_AVErrCode OH_AVPlayer_SetPlaybackRate(OH_AVPlayer *player, float rate) 541``` 542 543**Description** 544 545Sets the playback rate of an AVPlayer within the valid range.<br>The supported states are prepared, playing, paused, and completed. 546 547**System capability**: SystemCapability.Multimedia.Media.AVPlayer 548 549**Since**: 20 550 551 552**Parameters** 553 554| Parameter| Description| 555| -- | -- | 556| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 557| float rate | Playback rate. The value ranges from 0.125 to 4.| 558 559**Returns** 560 561| Type| Description| 562| -- | -- | 563| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The playback speed is set successfully.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The function is called when the AVPlayer is not in the allowed state, or it is called during live streaming.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or **rate** is out of range.| 564 565### OH_AVPlayer_GetPlaybackSpeed() 566 567``` 568OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed *speed) 569``` 570 571**Description** 572 573Obtains the playback speed of an AVPlayer. 574 575**System capability**: SystemCapability.Multimedia.Media.AVPlayer 576 577**Since**: 11 578 579 580**Parameters** 581 582| Parameter| Description| 583| -- | -- | 584| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 585| [AVPlaybackSpeed](capi-avplayer-base-h.md#avplaybackspeed) *speed | Pointer to the playback speed.| 586 587**Returns** 588 589| Type| Description| 590| -- | -- | 591| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The playback rate is obtained.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player GetPlaybackSpeed** fails.| 592 593### OH_AVPlayer_SetAudioRendererInfo() 594 595``` 596OH_AVErrCode OH_AVPlayer_SetAudioRendererInfo(OH_AVPlayer *player, OH_AudioStream_Usage streamUsage) 597``` 598 599**Description** 600 601Sets the audio stream type for an AVPlayer. 602 603**System capability**: SystemCapability.Multimedia.Media.AVPlayer 604 605**Since**: 12 606 607 608**Parameters** 609 610| Parameter| Description| 611| -- | -- | 612| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 613| [OH_AudioStream_Usage](../apis-audio-kit/capi-native-audiostream-base-h.md#oh_audiostream_usage) streamUsage | Audio stream type.| 614 615**Returns** 616 617| Type| Description| 618| -- | -- | 619| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The audio stream type is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr or **streamUsage** is invalid.| 620 621### OH_AVPlayer_SetVolumeMode() 622 623``` 624OH_AVErrCode OH_AVPlayer_SetVolumeMode(OH_AVPlayer *player, OH_AudioStream_VolumeMode volumeMode) 625``` 626 627**Description** 628 629Sets the audio volume mode for an AVPlayer. 630 631**System capability**: SystemCapability.Multimedia.Media.AVPlayer 632 633**Since**: 18 634 635 636**Parameters** 637 638| Parameter| Description| 639| -- | -- | 640| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 641| [OH_AudioStream_VolumeMode](../apis-audio-kit/capi-native-audiostream-base-h.md#oh_audiostream_volumemode) volumeMode | Volume mode of the audio stream.| 642 643**Returns** 644 645| Type| Description| 646| -- | -- | 647| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The audio volume mode is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr or **volumeMode** is invalid.<br>**AV_ERR_INVALID_STATE**: The function is called in an invalid state. It must be in the prepared state.<br>**AV_ERR_SERVICE_DIED**: A system error occurs.| 648 649### OH_AVPlayer_SetAudioInterruptMode() 650 651``` 652OH_AVErrCode OH_AVPlayer_SetAudioInterruptMode(OH_AVPlayer *player, OH_AudioInterrupt_Mode interruptMode) 653``` 654 655**Description** 656 657Sets the audio interruption mode for an AVPlayer. 658 659**System capability**: SystemCapability.Multimedia.Media.AVPlayer 660 661**Since**: 12 662 663 664**Parameters** 665 666| Parameter| Description| 667| -- | -- | 668| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 669| [OH_AudioInterrupt_Mode](../apis-audio-kit/capi-native-audiostream-base-h.md#oh_audiointerrupt_mode) interruptMode | Audio interruption mode.| 670 671**Returns** 672 673| Type| Description| 674| -- | -- | 675| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The audio interruption mode is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr or **interruptMode** is invalid.| 676 677### OH_AVPlayer_SetAudioEffectMode() 678 679``` 680OH_AVErrCode OH_AVPlayer_SetAudioEffectMode(OH_AVPlayer *player, OH_AudioStream_AudioEffectMode effectMode) 681``` 682 683**Description** 684 685Sets the audio effect mode for an AVPlayer. 686 687**System capability**: SystemCapability.Multimedia.Media.AVPlayer 688 689**Since**: 12 690 691 692**Parameters** 693 694| Parameter| Description| 695| -- | -- | 696| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 697| [OH_AudioStream_AudioEffectMode](../apis-audio-kit/capi-native-audiostream-base-h.md#oh_audiostream_audioeffectmode) effectMode | Audio effect mode.| 698 699**Returns** 700 701| Type| Description| 702| -- | -- | 703| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The audio effect mode is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr or **effectMode** is invalid.| 704 705### OH_AVPlayer_SelectBitRate() 706 707``` 708OH_AVErrCode OH_AVPlayer_SelectBitRate(OH_AVPlayer *player, uint32_t bitRate) 709``` 710 711**Description** 712 713Sets the bit rate used by an HLS player. This function is valid only for HLS network streams.<br>By default, the AVPlayer selects a proper bit rate and speed based on the network connection.<br>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 and closest to the specified bit rate. When ready, you can query the selected bit rate. 714 715**System capability**: SystemCapability.Multimedia.Media.AVPlayer 716 717**Since**: 11 718 719 720**Parameters** 721 722| Parameter| Description| 723| -- | -- | 724| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 725| uint32_t bitRate | Bit rate, in kbit/s.| 726 727**Returns** 728 729| Type| Description| 730| -- | -- | 731| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The bit rate is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player SelectBitRate** fails.| 732 733### OH_AVPlayer_SetVideoSurface() 734 735``` 736OH_AVErrCode OH_AVPlayer_SetVideoSurface(OH_AVPlayer *player, OHNativeWindow *window) 737``` 738 739**Description** 740 741Sets a playback window.<br>This function must be called after **SetSource** and before **Prepare**. 742 743**System capability**: SystemCapability.Multimedia.Media.AVPlayer 744 745**Since**: 11 746 747 748**Parameters** 749 750| Parameter| Description| 751| -- | -- | 752| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 753| OHNativeWindow *window | Pointer to the OHNativeWindow instance.| 754 755**Returns** 756 757| Type| Description| 758| -- | -- | 759| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The playback window is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** or **window** is nullptr, or the execution of **player SetVideoSurface** fails.| 760 761### OH_AVPlayer_GetDuration() 762 763``` 764OH_AVErrCode OH_AVPlayer_GetDuration(OH_AVPlayer *player, int32_t *duration) 765``` 766 767**Description** 768 769Obtains the total duration of a media file, in milliseconds. 770 771**System capability**: SystemCapability.Multimedia.Media.AVPlayer 772 773**Since**: 11 774 775 776**Parameters** 777 778| Parameter| Description| 779| -- | -- | 780| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 781| int32_t *duration | Pointer to the total duration.| 782 783**Returns** 784 785| Type| Description| 786| -- | -- | 787| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The total duration is obtained.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player GetDuration** fails.| 788 789### OH_AVPlayer_GetState() 790 791``` 792OH_AVErrCode OH_AVPlayer_GetState(OH_AVPlayer *player, AVPlayerState *state) 793``` 794 795**Description** 796 797Obtains the AVPlayer state. 798 799**System capability**: SystemCapability.Multimedia.Media.AVPlayer 800 801**Since**: 11 802 803 804**Parameters** 805 806| Parameter| Description| 807| -- | -- | 808| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 809| [AVPlayerState](capi-avplayer-base-h.md#avplayerstate) *state | Pointer to the state of the AVPlayer.| 810 811**Returns** 812 813| Type| Description| 814| -- | -- | 815| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The AVPlayer state is obtained.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player GetState** fails.| 816 817### OH_AVPlayer_IsPlaying() 818 819``` 820bool OH_AVPlayer_IsPlaying(OH_AVPlayer *player) 821``` 822 823**Description** 824 825Checks whether an AVPlayer is playing. 826 827**System capability**: SystemCapability.Multimedia.Media.AVPlayer 828 829**Since**: 11 830 831 832**Parameters** 833 834| Parameter| Description| 835| -- | -- | 836| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 837 838**Returns** 839 840| Type| Description| 841| -- | -- | 842| bool | Check result for whether the AVPlayer is playing. **true** if yes, **false** if the AVPlayer is not playing or the input parameter **player** is nullptr.| 843 844### OH_AVPlayer_IsLooping() 845 846``` 847bool OH_AVPlayer_IsLooping(OH_AVPlayer *player) 848``` 849 850**Description** 851 852Checks whether an AVPlayer is looping. 853 854**System capability**: SystemCapability.Multimedia.Media.AVPlayer 855 856**Since**: 11 857 858 859**Parameters** 860 861| Parameter| Description| 862| -- | -- | 863| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 864 865**Returns** 866 867| Type| Description| 868| -- | -- | 869| bool | Check result for whether the AVPlayer is looping. **true** if yes, **false** if the AVPlayer is not looping or the input parameter **player** is nullptr.| 870 871### OH_AVPlayer_SetLooping() 872 873``` 874OH_AVErrCode OH_AVPlayer_SetLooping(OH_AVPlayer *player, bool loop) 875``` 876 877**Description** 878 879Enables loop playback. 880 881**System capability**: SystemCapability.Multimedia.Media.AVPlayer 882 883**Since**: 11 884 885 886**Parameters** 887 888| Parameter| Description| 889| -- | -- | 890| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 891| bool loop | Whether to enable loop playback.| 892 893**Returns** 894 895| Type| Description| 896| -- | -- | 897| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: Loop playback is enabled.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player SetLooping** fails.| 898 899### OH_AVPlayer_SetPlayerCallback() 900 901``` 902OH_AVErrCode OH_AVPlayer_SetPlayerCallback(OH_AVPlayer *player, AVPlayerCallback callback) 903``` 904 905**Description** 906 907Sets an AVPlayer callback.<br>The callbacks [OH_AVPlayerOnInfo](capi-avplayer-base-h.md#oh_avplayeroninfo) and [OH_AVPlayerOnError](capi-avplayer-base-h.md#oh_avplayeronerror) set by using this function can transfer limited information. In addition, it is inconvenient for the application to distinguish between multiple AVPlayer instances. 908 909Therefore, since API version 12, [OH_AVPlayer_SetOnInfoCallback](capi-avplayer-h.md#oh_avplayer_setoninfocallback) and [OH_AVPlayer_SetOnErrorCallback](capi-avplayer-h.md#oh_avplayer_setonerrorcallback) are provided to set the callbacks [OH_AVPlayerOnInfoCallback](capi-avplayer-base-h.md#oh_avplayeroninfocallback) and [OH_AVPlayerOnErrorCallback](capi-avplayer-base-h.md#oh_avplayeronerrorcallback), respectively. 910 911**System capability**: SystemCapability.Multimedia.Media.AVPlayer 912 913**Since**: 11 914 915 916**Parameters** 917 918| Parameter| Description| 919| -- | -- | 920| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 921| [AVPlayerCallback](capi-avplayer-avplayercallback.md) callback | Callback used to return the result.| 922 923**Returns** 924 925| Type| Description| 926| -- | -- | 927| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The callback is set successfully.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, the input parameter **callback.onInfo** or **onError** is null, or the execution of **player SetPlayerCallback** fails.| 928 929### OH_AVPlayer_SelectTrack() 930 931``` 932OH_AVErrCode OH_AVPlayer_SelectTrack(OH_AVPlayer *player, int32_t index) 933``` 934 935**Description** 936 937Selects an audio or subtitle track.<br>By default, the first audio track with data is played, and the subtitle track is not played.<br>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. 938 939This function is not supported yet. 940 941**System capability**: SystemCapability.Multimedia.Media.AVPlayer 942 943**Since**: 11 944 945 946**Parameters** 947 948| Parameter| Description| 949| -- | -- | 950| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 951| int32_t index | Index of the track.| 952 953**Returns** 954 955| Type| Description| 956| -- | -- | 957| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player SelectTrack** fails.| 958 959### OH_AVPlayer_DeselectTrack() 960 961``` 962OH_AVErrCode OH_AVPlayer_DeselectTrack(OH_AVPlayer *player, int32_t index) 963``` 964 965**Description** 966 967Deselects an audio or subtitle track. 968 969This function is not supported yet. 970 971**System capability**: SystemCapability.Multimedia.Media.AVPlayer 972 973**Since**: 11 974 975 976**Parameters** 977 978| Parameter| Description| 979| -- | -- | 980| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 981| int32_t index | Index of the track.| 982 983**Returns** 984 985| Type| Description| 986| -- | -- | 987| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player DeselectTrack** fails.| 988 989### OH_AVPlayer_GetCurrentTrack() 990 991``` 992OH_AVErrCode OH_AVPlayer_GetCurrentTrack(OH_AVPlayer *player, int32_t trackType, int32_t *index) 993``` 994 995**Description** 996 997Obtains the currently valid track. You can set the track to the prepared, playing, paused, or completed state. 998 999This function is not supported yet. 1000 1001**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1002 1003**Since**: 11 1004 1005 1006**Parameters** 1007 1008| Parameter| Description| 1009| -- | -- | 1010| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 1011| int32_t trackType | Media type. The value **0** means audio and **1** means video.| 1012| int32_t *index | Pointer to the index of the track.| 1013 1014**Returns** 1015 1016| Type| Description| 1017| -- | -- | 1018| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The track is obtained.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **player GetCurrentTrack** fails.| 1019 1020### OH_AVPlayer_SetMediaKeySystemInfoCallback() 1021 1022``` 1023OH_AVErrCode OH_AVPlayer_SetMediaKeySystemInfoCallback(OH_AVPlayer *player,Player_MediaKeySystemInfoCallback callback) 1024``` 1025 1026**Description** 1027 1028Sets a callback to return the media key system information for an AVPlayer. 1029 1030**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1031 1032**Since**: 12 1033 1034 1035**Parameters** 1036 1037| Parameter| Description| 1038| -- | -- | 1039| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 1040| [Player_MediaKeySystemInfoCallback](#player_mediakeysysteminfocallback) callback | Callback.| 1041 1042**Returns** 1043 1044| Type| Description| 1045| -- | -- | 1046| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br> **AV_ERR_INVALID_VAL**: The input parameter **player** or **callback** is nullptr, or the execution of **player SetDrmSystemInfoCallback** fails.| 1047 1048### OH_AVPlayer_GetMediaKeySystemInfo() 1049 1050``` 1051OH_AVErrCode OH_AVPlayer_GetMediaKeySystemInfo(OH_AVPlayer *player, DRM_MediaKeySystemInfo *mediaKeySystemInfo) 1052``` 1053 1054**Description** 1055 1056Obtains the media key system information to create a media key session. 1057 1058**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1059 1060**Since**: 12 1061 1062 1063**Parameters** 1064 1065| Parameter| Description| 1066| -- | -- | 1067| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 1068| [DRM_MediaKeySystemInfo](capi-avplayer-drm-mediakeysysteminfo.md) *mediaKeySystemInfo | Pointer to the media key system information.| 1069 1070**Returns** 1071 1072| Type| Description| 1073| -- | -- | 1074| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the memory is insufficient.| 1075 1076### OH_AVPlayer_SetDecryptionConfig() 1077 1078``` 1079OH_AVErrCode OH_AVPlayer_SetDecryptionConfig(OH_AVPlayer *player, MediaKeySession *mediaKeySession,bool secureVideoPath) 1080``` 1081 1082**Description** 1083 1084Sets the decryption information. 1085 1086**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1087 1088**Since**: 12 1089 1090 1091**Parameters** 1092 1093| Parameter| Description| 1094| -- | -- | 1095| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 1096| [MediaKeySession](capi-avplayer-mediakeysession.md) *mediaKeySession | Pointer to the media key session with the decryption feature.| 1097| bool secureVideoPath | Whether a secure decoder is required.| 1098 1099**Returns** 1100 1101| Type| Description| 1102| -- | -- | 1103| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr, or the execution of **SetDecryptionConfig** fails.| 1104 1105### OH_AVPlayer_SetOnInfoCallback() 1106 1107``` 1108OH_AVErrCode OH_AVPlayer_SetOnInfoCallback(OH_AVPlayer *player, OH_AVPlayerOnInfoCallback callback, void *userData) 1109``` 1110 1111**Description** 1112 1113Sets a callback for the event indicating that the AVPlayer receives a message. 1114 1115**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1116 1117**Since**: 12 1118 1119 1120**Parameters** 1121 1122| Parameter| Description| 1123| -- | -- | 1124| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 1125| [OH_AVPlayerOnInfoCallback](capi-avplayer-base-h.md#oh_avplayeroninfocallback) callback | Pointer to the callback. If nullptr is passed in, the listening for AVPlayer messages is canceled.| 1126| void *userData | Pointer to the instance set by the caller.| 1127 1128**Returns** 1129 1130| Type| Description| 1131| -- | -- | 1132| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: Memory allocation fails.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr or the function fails to be executed.| 1133 1134### OH_AVPlayer_SetOnErrorCallback() 1135 1136``` 1137OH_AVErrCode OH_AVPlayer_SetOnErrorCallback(OH_AVPlayer *player, OH_AVPlayerOnErrorCallback callback, void *userData) 1138``` 1139 1140**Description** 1141 1142Sets a callback for the event indicating that an error occurs in the AVPlayer. 1143 1144**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1145 1146**Since**: 12 1147 1148 1149**Parameters** 1150 1151| Parameter| Description| 1152| -- | -- | 1153| [OH_AVPlayer](capi-avplayer-oh-avplayer.md) *player | Pointer to the OH_AVPlayer instance.| 1154| [OH_AVPlayerOnErrorCallback](capi-avplayer-base-h.md#oh_avplayeronerrorcallback) callback | Pointer to the callback. If nullptr is passed in, the listening for AVPlayer errors is canceled.| 1155| void *userData | Pointer to the instance set by the caller.| 1156 1157**Returns** 1158 1159| Type| Description| 1160| -- | -- | 1161| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1) | **AV_ERR_OK**: The operation is successful.<br>**AV_ERR_NO_MEMORY**: Memory allocation fails.<br>**AV_ERR_INVALID_VAL**: The input parameter **player** is nullptr or the function fails to be executed.| 1162