1# AVPlayer 2 3 4## Overview 5 6The AVPlayer module provides APIs related to media playback. 7 8You can refer to the corresponding development guide and samples based on your development requirements. 9 10- [Using AVPlayer to Play Audio](../../media/media/using-ndk-avplayer-for-playback.md) 11- [Using AVPlayer to Play Video](../../media/media/using-ndk-avplayer-for-video-playback.md) 12 13**System capability**: SystemCapability.Multimedia.Media.AVPlayer 14 15**Since**: 11 16 17 18## Summary 19 20 21### Files 22 23| Name| Description| 24| -------- | -------- | 25| [avplayer.h](avplayer_8h.md) | Declares the AVPlayer APIs. You can use the native AVPlayer APIs to play a media asset. | 26| [avplayer_base.h](avplayer__base_8h.md) | Declares the structs and enums of the AVPlayer. | 27 28 29### Structs 30 31| Name| Description| 32| -------- | -------- | 33| struct [AVPlayerCallback](_a_v_player_callback.md) | (Deprecated) Contains the set of the **OH_AVPlayerOnInfo** and **OH_AVPlayerOnInfo** callback function pointers. | 34 35 36### Types 37 38| Name| Description| 39| -------- | -------- | 40| typedef struct [MediaKeySession](#mediakeysession) [MediaKeySession](#mediakeysession) | Defines a struct for the media key session. | 41| typedef struct [DRM_MediaKeySystemInfo](#drm_mediakeysysteminfo) [DRM_MediaKeySystemInfo](#drm_mediakeysysteminfo) | Defines a struct for the media key system information. | 42| typedef void(\* [Player_MediaKeySystemInfoCallback](#player_mediakeysysteminfocallback)) (OH_AVPlayer \*player, [DRM_MediaKeySystemInfo](#drm_mediakeysysteminfo) \*mediaKeySystemInfo) | Defines the callback invoked when media key system information of the AVPlayer is updated. | 43| typedef enum [AVPlayerState](#avplayerstate-1) [AVPlayerState](#avplayerstate) | Defines an enum for the AVPlayer states. | 44| typedef enum [AVPlayerSeekMode](#avplayerseekmode-1) [AVPlayerSeekMode](#avplayerseekmode) | Defines an enum for the seek modes of the AVPlayer. | 45| typedef enum [AVPlaybackSpeed](#avplaybackspeed-1) [AVPlaybackSpeed](#avplaybackspeed) | Defines an enum for the playback speeds of the AVPlayer. | 46| typedef enum [AVPlayerOnInfoType](#avplayeroninfotype-1) [AVPlayerOnInfoType](#avplayeroninfotype) | Defines an enum for the types of messages received by the AVPlayer. | 47| typedef enum [AVPlayerBufferingType](#avplayerbufferingtype-1) [AVPlayerBufferingType](#avplayerbufferingtype) | Defines an enum for the types of buffer messages of the AVPlayer. | 48| typedef void(\*[OH_AVPlayerOnInfo](#oh_avplayeroninfo)) (OH_AVPlayer \*player, [AVPlayerOnInfoType](#avplayeroninfotype) type, int32_t extra) | (Deprecated) Defines the callback invoked when the AVPlayer receives a message. | 49| typedef void(\*[OH_AVPlayerOnInfoCallback](#oh_avplayeroninfocallback)) (OH_AVPlayer \*player, [AVPlayerOnInfoType](#avplayeroninfotype) type, OH_AVFormat \*infoBody, void \*userData) | Defines the callback invoked when the AVPlayer receives a message. If this callback is successfully set, the **OH_AVPlayerOnInfo** function will not be invoked. | 50| typedef void(\* [OH_AVPlayerOnError](#oh_avplayeronerror)) (OH_AVPlayer \*player, int32_t errorCode, const char \*errorMsg) | (Deprecated) Defines the callback invoked when an error occurs in the AVPlayer. This type is available in API version 9 or later. | 51| typedef void(\* [OH_AVPlayerOnErrorCallback](#oh_avplayeronerrorcallback)) (OH_AVPlayer \*player, int32_t errorCode, const char \*errorMsg, void \*userData) | Defines the callback invoked when an error occurs in the AVPlayer. If this callback is successfully set, the **OH_AVPlayerOnError** function will not be invoked. | 52| typedef struct [AVPlayerCallback](_a_v_player_callback.md) [AVPlayerCallback](#avplayercallback) | (Deprecated) Contains the set of the **OH_AVPlayerOnInfo** and **OH_AVPlayerOnInfo** callback function pointers. | 53 54 55### Enums 56 57| Name| Description| 58| -------- | -------- | 59| [AVPlayerState](#avplayerstate-1) {<br>AV_IDLE = 0, <br>AV_INITIALIZED = 1, <br>AV_PREPARED = 2, <br>AV_PLAYING = 3,<br>AV_PAUSED = 4, <br>AV_STOPPED = 5, <br>AV_COMPLETED = 6, <br>AV_RELEASED = 7,<br>AV_ERROR = 8<br>} | Enumerates the AVPlayer states.| 60| [AVPlayerSeekMode](#avplayerseekmode) { <br>AV_SEEK_NEXT_SYNC = 0, <br>AV_SEEK_PREVIOUS_SYNC, <br>AV_SEEK_CLOSEST = 2<br>} | Enumerates the seek modes of the AVPlayer.| 61| [AVPlaybackSpeed](#avplaybackspeed-1) {<br>AV_SPEED_FORWARD_0_75_X, <br>AV_SPEED_FORWARD_1_00_X, <br>AV_SPEED_FORWARD_1_25_X, <br> AV_SPEED_FORWARD_1_75_X,<br>AV_SPEED_FORWARD_2_00_X, <br>AV_SPEED_FORWARD_0_50_X, <br>AV_SPEED_FORWARD_1_50_X<br>, <br>AV_SPEED_FORWARD_3_00_X, <br>AV_SPEED_FORWARD_0_25_X, <br>AV_SPEED_FORWARD_0_125_X} | Enumerates the playback speeds of the AVPlayer. | 62| [AVPlayerOnInfoType](#avplayeroninfotype-1) {<br>AV_INFO_TYPE_SEEKDONE = 0, <br>AV_INFO_TYPE_SPEEDDONE = 1, <br>AV_INFO_TYPE_BITRATEDONE = 2, <br>AV_INFO_TYPE_EOS = 3,<br>AV_INFO_TYPE_STATE_CHANGE = 4, <br>AV_INFO_TYPE_POSITION_UPDATE = 5, <br>AV_INFO_TYPE_MESSAGE = 6, <br>AV_INFO_TYPE_VOLUME_CHANGE = 7,<br>AV_INFO_TYPE_RESOLUTION_CHANGE = 8, <br>AV_INFO_TYPE_BUFFERING_UPDATE = 9, <br>AV_INFO_TYPE_BITRATE_COLLECT = 10, <br>AV_INFO_TYPE_INTERRUPT_EVENT = 11,<br>AV_INFO_TYPE_DURATION_UPDATE = 12, <br>AV_INFO_TYPE_IS_LIVE_STREAM = 13, <br>AV_INFO_TYPE_TRACKCHANGE = 14, <br>AV_INFO_TYPE_TRACK_INFO_UPDATE = 15,<br>AV_INFO_TYPE_SUBTITLE_UPDATE = 16, AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE = 17<br>} | Enumerates the types of messages received by the AVPlayer.| 63| [AVPlayerBufferingType](#avplayerbufferingtype-1) { <br>AVPLAYER_BUFFERING_START = 1, <br>AVPLAYER_BUFFERING_END, <br>AVPLAYER_BUFFERING_PERCENT, <br>AVPLAYER_BUFFERING_CACHED_DURATION <br>} | Enumerates the types of buffer messages of the AVPlayer. | 64 65 66### Functions 67 68| Name| Description| 69| -------- | -------- | 70| OH_AVPlayer \*[OH_AVPlayer_Create](#oh_avplayer_create) (void) | Creates an **OH_AVPlayer** instance.| 71| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [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. | 72| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [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.| 73| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_Prepare](#oh_avplayer_prepare) (OH_AVPlayer \*player) | Prepares the playback environment and buffers media data.| 74| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_Play](#oh_avplayer_play) (OH_AVPlayer \*player) | Starts playback.| 75| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_Pause](#oh_avplayer_pause) (OH_AVPlayer \*player) | Pauses playback.| 76| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_Stop](#oh_avplayer_stop) (OH_AVPlayer \*player) | Stops playback.| 77| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_Reset](#oh_avplayer_reset) (OH_AVPlayer \*player) | Restores the AVPlayer to the initial state.| 78| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_Release](#oh_avplayer_release) (OH_AVPlayer \*player) | Asynchronously releases an **OH_AVPlayer** instance.| 79| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_ReleaseSync](#oh_avplayer_releasesync) (OH_AVPlayer \*player) | Synchronously releases an **OH_AVPlayer** instance.| 80| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetVolume](#oh_avplayer_setvolume) (OH_AVPlayer \*player, float leftVolume, float rightVolume) | Sets the volume for an AVPlayer.| 81| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_Seek](#oh_avplayer_seek) (OH_AVPlayer \*player, int32_t mSeconds, [AVPlayerSeekMode](#avplayerseekmode) mode) | Seeks to a playback position.| 82| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetCurrentTime](#oh_avplayer_getcurrenttime) (OH_AVPlayer \*player, int32_t \*currentTime) | Obtains the playback position, in milliseconds.| 83| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetVideoWidth](#oh_avplayer_getvideowidth) (OH_AVPlayer \*player, int32_t \*videoWidth) | Obtains the video width.| 84| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetVideoHeight](#oh_avplayer_getvideoheight) (OH_AVPlayer \*player, int32_t \*videoHeight) | Obtains the video height.| 85| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetPlaybackSpeed](#oh_avplayer_setplaybackspeed) (OH_AVPlayer \*player, [AVPlaybackSpeed](#avplaybackspeed) speed) | Sets the playback speed for an AVPlayer.| 86| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetPlaybackSpeed](#oh_avplayer_getplaybackspeed) (OH_AVPlayer \*player, [AVPlaybackSpeed](#avplaybackspeed) \*speed) | Obtains the playback speed of an AVPlayer.| 87| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetAudioRendererInfo](#oh_avplayer_setaudiorendererinfo) (OH_AVPlayer \*player, OH_AudioStream_Usage streamUsage) | Sets the audio stream type for an AVPlayer. | 88| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetAudioInterruptMode](#oh_avplayer_setaudiointerruptmode) (OH_AVPlayer \*player, OH_AudioInterrupt_Mode interruptMode) | Sets the audio interruption mode for an AVPlayer. | 89| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetAudioEffectMode](#oh_avplayer_setaudioeffectmode) (OH_AVPlayer \*player, OH_AudioStream_AudioEffectMode effectMode) | Sets the audio effect mode for an AVPlayer. | 90| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SelectBitRate](#oh_avplayer_selectbitrate) (OH_AVPlayer \*player, uint32_t bitRate) | Sets the bit rate used by an HLS player.| 91| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetVideoSurface](#oh_avplayer_setvideosurface) (OH_AVPlayer \*player, OHNativeWindow \*window) | Sets a playback window.| 92| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetDuration](#oh_avplayer_getduration) (OH_AVPlayer \*player, int32_t \*duration) | Obtains the total duration of a media file, in milliseconds.| 93| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetState](#oh_avplayer_getstate) (OH_AVPlayer \*player, [AVPlayerState](#avplayerstate) \*state) | Obtains the AVPlayer state.| 94| bool [OH_AVPlayer_IsPlaying](#oh_avplayer_isplaying) (OH_AVPlayer \*player) | Checks whether an AVPlayer is playing.| 95| bool [OH_AVPlayer_IsLooping](#oh_avplayer_islooping) (OH_AVPlayer \*player) | Checks whether an AVPlayer is looping.| 96| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetLooping](#oh_avplayer_setlooping) (OH_AVPlayer \*player, bool loop) | Enables loop playback.| 97| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetPlayerCallback](#oh_avplayer_setplayercallback) (OH_AVPlayer \*player, [AVPlayerCallback](_a_v_player_callback.md) callback) | Sets a callback for an AVPlayer.| 98| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SelectTrack](#oh_avplayer_selecttrack) (OH_AVPlayer \*player, int32_t index) | Selects an audio track. This function is not supported yet.| 99| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_DeselectTrack](#oh_avplayer_deselecttrack) (OH_AVPlayer \*player, int32_t index) | Deselects an audio track. This function is not supported yet.| 100| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetCurrentTrack](#oh_avplayer_getcurrenttrack) (OH_AVPlayer \*player, int32_t trackType, int32_t \*index) | Obtains the currently valid track. This function is not supported yet.| 101| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetMediaKeySystemInfoCallback](#oh_avplayer_setmediakeysysteminfocallback) (OH_AVPlayer \*player, Player_MediaKeySystemInfoCallback callback) | Sets a callback to return the media key system information for an AVPlayer.| 102| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_GetMediaKeySystemInfo](#oh_avplayer_getmediakeysysteminfo) (OH_AVPlayer \*player, [DRM_MediaKeySystemInfo](../apis-drm-kit/_d_r_m___media_key_system_info.md) \*mediaKeySystemInfo) | Obtains the media key system information to create a media key session.| 103| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetDecryptionConfig](#oh_avplayer_setdecryptionconfig) (OH_AVPlayer \*player, [MediaKeySession](../apis-drm-kit/_drm.md#mediakeysession) \*mediaKeySession, bool secureVideoPath) | Sets the decryption information.| 104| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetOnInfoCallback](#oh_avplayer_setoninfocallback) (OH_AVPlayer \*player, [OH_AVPlayerOnInfoCallback](#oh_avplayeroninfocallback) callback, void \*userData) | Sets a callback for the event indicating that the AVPlayer receives a message. | 105| [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode) [OH_AVPlayer_SetOnErrorCallback](#oh_avplayer_setonerrorcallback) (OH_AVPlayer \*player, [OH_AVPlayerOnErrorCallback](#oh_avplayeronerrorcallback) callback, void \*userData) | Sets a callback for the event indicating that an error occurs in the AVPlayer. | 106 107 108### Variables 109 110| Name| Description| 111| -------- | -------- | 112| const char \* [OH_PLAYER_STATE](#oh_player_state) | Pointer to the key for obtaining the AVPlayer state. The value is of the int32_t type. | 113| const char \* [OH_PLAYER_STATE_CHANGE_REASON](#oh_player_state_change_reason) | Pointer to the key for obtaining the AVPlayer state change reason. The value is of the int32_t type. | 114| const char \* [OH_PLAYER_VOLUME](#oh_player_volume) | Pointer to the key for obtaining the volume. The value type is float. | 115| const char \* [OH_PLAYER_BITRATE_ARRAY](#oh_player_bitrate_array) | Pointer to the key for obtaining the bit rate array. The value is of the uint8_t byte array type, which is expressed by [AV_INFO_TYPE_BITRATE_COLLECT](#avplayeroninfotype-1). | 116| const char \* [OH_PLAYER_AUDIO_INTERRUPT_TYPE](#oh_player_audio_interrupt_type) | Pointer to the key for obtaining the audio interruption type. The value is of the int32_t type. | 117| const char \* [OH_PLAYER_AUDIO_INTERRUPT_FORCE](#oh_player_audio_interrupt_force) | Pointer to the key for obtaining the FORCE type of audio interruption. The value is of the int32_t type. | 118| const char \* [OH_PLAYER_AUDIO_INTERRUPT_HINT](#oh_player_audio_interrupt_hint) | Pointer to the key for obtaining the HINT type of audio interruption. The value is of the int32_t type. | 119| const char \* [OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON](#oh_player_audio_device_change_reason) | Pointer to the key for obtaining the audio device change reason. The value is of the int32_t type. | 120| const char \* [OH_PLAYER_BUFFERING_TYPE](#oh_player_buffering_type) | Pointer to the key for obtaining the type of the buffer update message. The value type is [AVPlayerBufferingType](#avplayerbufferingtype-1). | 121| const char \* [OH_PLAYER_BUFFERING_VALUE](#oh_player_buffering_value) | Pointer to the key for obtaining the value of the buffer update message. The value is of the int32_t type. | 122| const char \* [OH_PLAYER_SEEK_POSITION](#oh_player_seek_position) | Pointer to the key for obtaining the playback progress after the seek operation. The value is of the int32_t type. | 123| const char \* [OH_PLAYER_PLAYBACK_SPEED](#oh_player_playback_speed) | Pointer to the key for obtaining the playback speed. The value type is [AVPlaybackSpeed](#avplaybackspeed-1). | 124| const char \* [OH_PLAYER_BITRATE](#oh_player_bitrate) | Pointer to the key for obtaining the bit rate. The value is of the int32_t type. | 125| const char \* [OH_PLAYER_CURRENT_POSITION](#oh_player_current_position) | Pointer to the key for obtaining the playback progress information. The value is of the int32_t type. | 126| const char \* [OH_PLAYER_DURATION](#oh_player_duration) | Pointer to the key for obtaining the media asset duration. The value type is int64_t. | 127| const char \* [OH_PLAYER_VIDEO_WIDTH](#oh_player_video_width) | Pointer to the key for obtaining the video width. The value is of the int32_t type. | 128| const char \* [OH_PLAYER_VIDEO_HEIGHT](#oh_player_video_height) | Pointer to the key for obtaining the video height. The value is of the int32_t type. | 129| const char \* [OH_PLAYER_MESSAGE_TYPE](#oh_player_message_type) | Pointer to the key for obtaining the type of message received by the AVPlayer. The value is of the int32_t type. | 130| const char \* [OH_PLAYER_IS_LIVE_STREAM](#oh_player_is_live_stream) | Pointer to the key for checking whether a media asset is live streaming. The value is of the int32_t type. | 131 132 133## Type Description 134 135 136### AVPlaybackSpeed 137 138``` 139typedef enum AVPlaybackSpeed AVPlaybackSpeed 140``` 141**Description** 142Defines an enum for the playback speeds of the AVPlayer. 143 144**System capability**: SystemCapability.Multimedia.Media.AVPlayer 145 146**Since**: 11 147 148 149### AVPlayerBufferingType 150 151``` 152typedef enum AVPlayerBufferingType AVPlayerBufferingType 153``` 154**Description** 155Defines an enum for the types of buffer messages of the AVPlayer. 156 157**System capability**: SystemCapability.Multimedia.Media.AVPlayer 158 159**Since**: 12 160 161 162### AVPlayerCallback 163 164``` 165typedef struct AVPlayerCallback AVPlayerCallback 166``` 167**Description** 168Contains the set of the **OH_AVPlayerOnInfo** and **OH_AVPlayerOnInfo** callback function pointers. 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. 169 170**System capability**: SystemCapability.Multimedia.Media.AVPlayer 171 172**Since**: 11 173 174**Deprecated from**: 12 175 176**Substitute**: [OH_AVPlayerOnInfoCallback](#oh_avplayeroninfocallback) and [OH_AVPlayerOnErrorCallback](#oh_avplayeronerrorcallback) 177 178**Parameters** 179 180| Name| Description| 181| -------- | -------- | 182| onInfo | Callback for AVPlayer message information. For details about the available options, see [OH_AVPlayerOnInfo](#oh_avplayeroninfo).| 183| onError | Callback for AVPlayer error information. For details about the available options, see [OH_AVPlayerOnError](#oh_avplayeronerror).| 184 185 186### AVPlayerOnInfoType 187 188``` 189typedef enum AVPlayerOnInfoType AVPlayerOnInfoType 190``` 191**Description** 192Defines an enum for the types of messages received by the AVPlayer. 193 194**System capability**: SystemCapability.Multimedia.Media.AVPlayer 195 196**Since**: 11 197 198 199### AVPlayerSeekMode 200 201``` 202typedef enum AVPlayerSeekMode AVPlayerSeekMode 203``` 204**Description** 205Defines an enum for the seek modes of the AVPlayer. 206 207**System capability**: SystemCapability.Multimedia.Media.AVPlayer 208 209**Since**: 11 210 211 212### AVPlayerState 213 214``` 215typedef enum AVPlayerState AVPlayerState 216``` 217**Description** 218Defines an enum for the AVPlayer states. 219 220**System capability**: SystemCapability.Multimedia.Media.AVPlayer 221 222**Since**: 11 223 224 225### DRM_MediaKeySystemInfo 226 227``` 228typedef struct DRM_MediaKeySystemInfo DRM_MediaKeySystemInfo 229``` 230**Description** 231Defines a struct for the media key system information. 232 233**Since**: 12 234 235 236### MediaKeySession 237 238``` 239typedef struct MediaKeySession MediaKeySession 240``` 241**Description** 242Defines a struct for the media key session. 243 244**Since**: 12 245 246 247### OH_AVPlayerOnError 248 249``` 250typedef void(* OH_AVPlayerOnError) (OH_AVPlayer *player, int32_t errorCode, const char *errorMsg) 251``` 252**Description** 253Defines the callback when an error occurs in the AVPlayer. This type is available in API version 9 or later. 254 255**System capability**: SystemCapability.Multimedia.Media.AVPlayer 256 257**Since**: 11 258 259**Deprecated from**: 12 260 261**Substitute**: [OH_AVPlayerOnErrorCallback](#oh_avplayeronerrorcallback) 262 263**Parameters** 264 265| Name| Description| 266| -------- | -------- | 267| Pointer to an **OH_AVPlayer** instance.| | 268| errorCode | Error code.<br> **AV_ERR_NO_MEMORY**: No memory. The value is **1**.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The value is **2**.<br>**AV_ERR_INVALID_VAL**: Invalid value. The value is **3**.<br>**AV_ERR_IO**: I/O error. The value is **4**.<br>**AV_ERR_TIMEOUT**: Timeout. The value is **5**.<br>**AV_ERR_UNKNOWN**: Unknown error. The value is **6**.<br>**AV_ERR_SERVICE_DIED**: The service is dead. The value is **7**.<br>**AV_ERR_INVALID_STATE**: The operation is not supported in the current state. The value is **8**.<br>**AV_ERR_UNSUPPORT**: The function is not supported. The value is **9**.<br>**AV_ERR_EXTEND_START**: Initial value for extended error codes. The value is **100**.| 269| errorMsg | Pointer to an error message. | 270 271 272### OH_AVPlayerOnErrorCallback 273 274``` 275typedef void(* OH_AVPlayerOnErrorCallback) (OH_AVPlayer *player, int32_t errorCode, const char *errorMsg, void *userData) 276``` 277**Description** 278Defines the callback invoked when an error occurs in the AVPlayer. If this callback is successfully set, the **OH_AVPlayerOnError** function will not be invoked. 279 280**System capability**: SystemCapability.Multimedia.Media.AVPlayer 281 282**Since**: 12 283 284**Parameters** 285 286| Name| Description| 287| -------- | -------- | 288| player | Pointer to an **OH_AVPlayer** instance. | 289| errorCode | Error code.<br> **AV_ERR_NO_MEMORY**: No memory. The value is **1**.<br>**AV_ERR_OPERATE_NOT_PERMIT**: The operation is not allowed. The value is **2**.<br>**AV_ERR_INVALID_VAL**: Invalid value. The value is **3**.<br>**AV_ERR_IO**: I/O error. The value is **4**.<br>**AV_ERR_TIMEOUT**: Timeout. The value is **5**.<br>**AV_ERR_UNKNOWN**: Unknown error. The value is **6**.<br>**AV_ERR_SERVICE_DIED**: The service is dead. The value is **7**.<br>**AV_ERR_INVALID_STATE**: The operation is not supported in the current state. The value is **8**.<br>**AV_ERR_UNSUPPORT**: The function is not supported. The value is **9**.<br>**AV_ERR_EXTEND_START**: Initial value for extended error codes. The value is **100**.| 290| errorMsg | Pointer to the error message. | 291| userData | Pointer to the user data passed in. The same data is returned. | 292 293 294### OH_AVPlayerOnInfo 295 296``` 297typedef void(* OH_AVPlayerOnInfo) (OH_AVPlayer *player, AVPlayerOnInfoType type, int32_t extra) 298``` 299**Description** 300Defines the callback invoked when the AVPlayer receives a message. 301 302The following table lists the mappings between **type** and **extra** values. 303 304| Value of type| Value of extra| 305| -------- | -------- | 306| AV_INFO_TYPE_SEEKDONE | Message returned when seeking to a playback position is complete. **extra** indicates the position after the seek operation.| 307| AV_INFO_TYPE_SPEEDDONE | Message returned when the playback speed setting is complete. **extra** indicates the playback speed. For details about the available options, see [AVPlaybackSpeed](#avplaybackspeed-1).| 308| AV_INFO_TYPE_BITRATEDONE | Message returned when the bit rate setting is complete. **extra** indicates the bit rate.| 309| AV_INFO_TYPE_EOS | Message returned when the playback is complete.| 310| AV_INFO_TYPE_STATE_CHANGE | Message returned when the AVPlayer state changes. **extra** indicates the new state. For details about the available options, see [AVPlayerState](#avplayerstate-1).| 311| AV_INFO_TYPE_POSITION_UPDATE | Message returned when the playback position changes. **extra** indicates the current position.| 312| AV_INFO_TYPE_MESSAGE | Message returned when video rendering starts. **extra** indicates the first video frame rendered.| 313| AV_INFO_TYPE_VOLUME_CHANGE | Message returned when the playback volume changes. **extra** is not defined in this scenario.| 314| AV_INFO_TYPE_RESOLUTION_CHANGE | Message returned when the video size is obtained for the first time or the video size is updated. **extra** is not defined in this scenario.| 315| AV_INFO_TYPE_BUFFERING_UPDATE | Message returned when multi-queue buffering changes. **extra** indicates the video duration.| 316| AV_INFO_TYPE_BITRATE_COLLECT | Message returned to report the HLS video bit rates. Each bit rate has been converted into a uint8_t byte array during the reporting. You need to forcibly convert the uint8_t byte array into a uint32_t integer array. | 317| AV_INFO_TYPE_INTERRUPT_EVENT | Message returned when the audio focus changes. **extra** indicates the hints provided along with audio interruption. For details about the available options, see [OH_AudioInterrupt_Hint](../apis-audio-kit/_o_h_audio.md#oh_audiointerrupt_hint). The application can determine whether to perform further processing based on the hint.| 318| AV_INFO_TYPE_DURATION_UPDATE | Message returned when the playback duration changes. **extra** indicates the video duration.| 319| AV_INFO_TYPE_IS_LIVE_STREAM | Message returned when live streams are played. **extra** indicates whether the stream is a live stream. The value **0** means a non-live stream, and **1** means a live stream.| 320| AV_INFO_TYPE_TRACKCHANGE | Message returned when the track changes. **extra** is not defined in this scenario.| 321| AV_INFO_TYPE_TRACK_INFO_UPDATE |Message returned when the track information updates. **extra** is not defined in this scenario.| 322| AV_INFO_TYPE_SUBTITLE_UPDATE | Message returned when the subtitle information changes. **extra** is not defined in this scenario.| 323| AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE | Message returned when the audio output device changes. **extra** indicates the device change reason. For details about the available options, see [OH_AudioStream_DeviceChangeReason](../apis-audio-kit/_o_h_audio.md#oh_audiostream_devicechangereason).| 324 325**System capability**: SystemCapability.Multimedia.Media.AVPlayer 326 327**Since**: 11 328 329**Deprecated from**: 12 330 331**Substitute**: [OH_AVPlayerOnInfoCallback](#oh_avplayeroninfocallback) 332 333**Parameters** 334 335| Name| Description| 336| -------- | -------- | 337| player | Pointer to an **OH_AVPlayer** instance. | 338| type | Message type. For details about the available options, see [AVPlayerOnInfoType](#avplayeroninfotype-1). For details about the mappings between **type** and **extra** values, see the function description.| 339| extra | Other information, such as the start time and position of the media file to play. | 340 341 342### OH_AVPlayerOnInfoCallback 343 344``` 345typedef void(* OH_AVPlayerOnInfoCallback) (OH_AVPlayer *player, AVPlayerOnInfoType type, OH_AVFormat *infoBody, void *userData) 346``` 347**Description** 348Defines the callback invoked when the AVPlayer receives a message. If this callback is successfully set, the **OH_AVPlayerOnInfo** function will not be invoked. 349 350**System capability**: SystemCapability.Multimedia.Media.AVPlayer 351 352**Since**: 12 353 354**Parameters** 355 356| Name| Description| 357| -------- | -------- | 358| player | Pointer to an **OH_AVPlayer** instance. | 359| type | Message type. For details about the available options, see [AVPlayerOnInfoType](#avplayeroninfotype-1). | 360| infoBody | Pointer to the message. The pointer is valid only in this callback. | 361| userData | Pointer to the user data passed in. The same data is returned. | 362 363 364### Player_MediaKeySystemInfoCallback 365 366``` 367typedef void(* Player_MediaKeySystemInfoCallback) (OH_AVPlayer *player, DRM_MediaKeySystemInfo *mediaKeySystemInfo) 368``` 369**Description** 370Defines the callback invoked when media key system information of the AVPlayer is updated. 371 372**Since**: 12 373 374**Parameters** 375 376| Name| Description| 377| -------- | -------- | 378| player | Pointer to an **OH_AVPlayer** instance. | 379| mediaKeySystemInfo | Pointer to the media key system information. | 380 381**Returns** 382 383void 384 385 386## Enum Description 387 388 389### AVPlaybackSpeed 390 391``` 392enum AVPlaybackSpeed 393``` 394**Description** 395Defines an enum for the playback speeds of the AVPlayer. 396 397**System capability**: SystemCapability.Multimedia.Media.AVPlayer 398 399**Since**: 11 400 401| Value| Description| 402| -------- | -------- | 403| AV_SPEED_FORWARD_0_75_X | Plays the video at 0.75 times the normal speed.| 404| AV_SPEED_FORWARD_1_00_X | Plays the video at the normal speed.| 405| AV_SPEED_FORWARD_1_25_X | Plays the video at 1.25 times the normal speed.| 406| AV_SPEED_FORWARD_1_75_X | Plays the video at 1.75 times the normal speed.| 407| AV_SPEED_FORWARD_2_00_X | Plays the video at 2.0 times the normal speed.| 408| AV_SPEED_FORWARD_0_50_X | Plays the video at 0.5 times the normal speed.<br>**Since**: 12| 409| AV_SPEED_FORWARD_1_50_X | Plays the video at 1.5 times the normal speed.<br>**Since**: 12| 410| AV_SPEED_FORWARD_3_00_X | Plays the video at 3.0 times the normal speed.<br>**Since**: 13| 411| AV_SPEED_FORWARD_0_25_X | Plays the video at 0.25 times the normal speed.<br>**Since**: 13| 412| AV_SPEED_FORWARD_0_125_X | Plays the video at 0.125 times the normal speed.<br>**Since**: 13| 413 414 415### AVPlayerBufferingType 416 417``` 418enum AVPlayerBufferingType 419``` 420**Description** 421Defines an enum for the types of buffer messages of the AVPlayer. 422 423**System capability**: SystemCapability.Multimedia.Media.AVPlayer 424 425**Since**: 12 426 427| Value| Description| 428| -------- | -------- | 429| AVPLAYER_BUFFERING_START | Buffering start message. | 430| AVPLAYER_BUFFERING_END | Buffering end message. | 431| AVPLAYER_BUFFERING_PERCENT | Buffer execution progress, in percentage. The value is an integer in the range [0, 100]. | 432| AVPLAYER_BUFFERING_CACHED_DURATION | Duration that cached data can be played, in milliseconds. | 433 434 435### AVPlayerOnInfoType 436 437``` 438enum AVPlayerOnInfoType 439``` 440**Description** 441Enumerates the types of messages received by the AVPlayer. 442 443The enum can be used in [OH_AVPlayerOnInfoCallback](#oh_avplayeroninfocallback) and [OH_AVPlayerOnInfo (deprecated)](#oh_avplayeroninfo) to indicate the type of information received by the AVPlayer. 444 445- Since API version 12, you are advised to use [OH_AVPlayerOnInfoCallback](#oh_avplayeroninfocallback) instead. Different information (**infoBody**) can be obtained for different **OnInfo** types. **infoBody** contains the key-value pairs. For details, see the following enumerated value table. 446 447- If you are using API version 11 for development, use **OH_AVPlayerOnInfo (deprecated)**. For details about the mappings used in this deprecated API, see [OH_AVPlayerOnInfo API Description](#oh_avplayeroninfo). 448 449**System capability**: SystemCapability.Multimedia.Media.AVPlayer 450 451**Since**: 11 452 453| Value| Description| 454| -------- | -------- | 455| AV_INFO_TYPE_SEEKDONE | Message returned when seeking to a playback position is complete.<br>If **key** is set to **OH_PLAYER_SEEK_POSITION**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value.| 456| AV_INFO_TYPE_SPEEDDONE | Message returned when the playback speed setting is complete.<br>If **key** is set to **OH_PLAYER_PLAYBACK_SPEED**, the value is an enumerated value of [AVPlaybackSpeed](#avplaybackspeed-1). The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value and forcibly converts the value to an enumerated value of [AVPlaybackSpeed](#avplaybackspeed-1).| 457| AV_INFO_TYPE_BITRATEDONE | Message returned when the bit rate setting is complete.<br>If **key** is set to **OH_PLAYER_BITRATE**, the value type is uint32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value and forcibly converts the value to the uint32_t type.| 458| AV_INFO_TYPE_EOS | Message returned when the playback is complete.| 459| AV_INFO_TYPE_STATE_CHANGE | Message returned when the AVPlayer state changes.<br>- If **key** is set to **OH_PLAYER_STATE**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value and forcibly converts the value to an enumerated value of [AVPlayerState](#avplayerstate-1).<br>- If **key** is set to **OH_PLAYER_STATE_CHANGE_REASON**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value. The value **1** means that the change is triggered by user operations, and **2** means that the change is triggered by the system.| 460| AV_INFO_TYPE_POSITION_UPDATE | Message returned when the playback position changes.<br>If **key** is set to **OH_PLAYER_CURRENT_POSITION**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value.| 461| AV_INFO_TYPE_MESSAGE | Message returned when video rendering starts.<br>If **key** is set to **OH_PLAYER_MESSAGE_TYPE**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value. The value **1** means that video rendering starts.| 462| AV_INFO_TYPE_VOLUME_CHANGE | Message returned when the playback volume changes.<br>If **key** is set to **OH_PLAYER_VOLUME**, the value type is float. The system uses float to transfer the value, and the application uses float to obtain the value. The value range is [0.0, 1.0].| 463| AV_INFO_TYPE_RESOLUTION_CHANGE | Message returned when the video size is obtained for the first time or the video size is updated.<br>If **key** is set to **OH_PLAYER_VIDEO_WIDTH** or **OH_PLAYER_VIDEO_HEIGHT**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value.| 464| AV_INFO_TYPE_BUFFERING_UPDATE | Message returned when multi-queue buffering changes.<br>- If **key** is set to **OH_PLAYER_BUFFERING_TYPE**, the value type is [AVPlayerBufferingType](#avplayerbufferingtype-1). The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value and forcibly converts the value to an enumerated value of [AVPlayerBufferingType](#avplayerbufferingtype-1).<br>- If **key** is set to **OH_PLAYER_BUFFERING_VALUE**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value. This value is valid when the buffer update message type is **AVPLAYER_BUFFERING_PERCENT** or **AVPLAYER_BUFFERING_CACHED_DURATION**, which indicate the percentage of the buffer progress and the duration that the cached data can play, respectively.| 465| AV_INFO_TYPE_BITRATE_COLLECT | Message returned to report the HLS video bit rates.<br>If **key** is set to **OH_PLAYER_BITRATE_ARRAY**, the value type is uint8_t. The application uses a pointer variable of the uint8_t type to store the bit rate list and uses a variable of the size_t type to store the byte array length. Then it allocates several storage spaces of the uint32_t type to receive the bit rate integer of the uint32_t type, which is converted from the uint8_t byte array. | 466| AV_INFO_TYPE_INTERRUPT_EVENT | Message returned when the audio focus changes.<br>The value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value.<br>**key** can be set to any of the following values:<br>- **OH_PLAYER_AUDIO_INTERRUPT_TYPE**: The value **1** means that the audio interruption event starts, and **2** means that the event ends.<br>- **OH_PLAYER_AUDIO_INTERRUPT_FORCE**: The value **0** means forcible interruption (the system changes the audio playback status), and **1** means sharing interruption (the application changes the audio playback status).<br>- **OH_PLAYER_AUDIO_INTERRUPT_HINT**: The value **0** (NONE) means no hint; **1** (RESUME) means that the audio playback is resumed; **2** (PAUSE) means that the audio playback is paused and loses focus; **3** (STOP) means that the audio playback is stopped; **4** (DUCK) means that the audio volume is reduced; **5** (UNDUCK) means that the audio volume is restored.| 467| AV_INFO_TYPE_DURATION_UPDATE | Message returned when the playback duration changes.<br>If **key** is set to **OH_PLAYER_DURATION**, the value type is int64_t. The system uses int64_t to transfer the value, and the application uses int64_t to obtain the value.| 468| AV_INFO_TYPE_IS_LIVE_STREAM | Message returned when live streams are played.<br>If **key** is set to **OH_PLAYER_IS_LIVE_STREAM**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value. The value **0** means a non-live stream, and **1** means a live stream.| 469| AV_INFO_TYPE_TRACKCHANGE | Message returned when the track changes. **extra** is not defined in this scenario.| 470| AV_INFO_TYPE_TRACK_INFO_UPDATE |Message returned when the track information updates. **extra** is not defined in this scenario.| 471| AV_INFO_TYPE_SUBTITLE_UPDATE | Message returned when the subtitle information changes. **extra** is not defined in this scenario.| 472| AV_INFO_TYPE_AUDIO_OUTPUT_DEVICE_CHANGE | Message returned when the audio output device changes.<br>If **key** is set to **OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON**, the value type is int32_t. The system uses int32_t to transfer the value, and the application uses int32_t to obtain the value.| 473 474 475### AVPlayerSeekMode 476 477``` 478enum AVPlayerSeekMode 479``` 480**Description** 481Defines an enum for the seek modes of the AVPlayer. 482 483**System capability**: SystemCapability.Multimedia.Media.AVPlayer 484 485**Since**: 11 486 487| Value| Description| 488| -------- | -------- | 489| AV_SEEK_NEXT_SYNC | Seeks to the next key frame at the specified position.| 490| AV_SEEK_PREVIOUS_SYNC | Seeks to the previous key frame at the specified position.| 491| AV_SEEK_CLOSEST | Seeks to the frame closest to the specified position.<br>**Since**: 12| 492 493 494### AVPlayerState 495 496``` 497enum AVPlayerState 498``` 499**Description** 500Defines an enum for the AVPlayer states. 501 502**System capability**: SystemCapability.Multimedia.Media.AVPlayer 503 504**Since**: 11 505 506| Value| Description| 507| -------- | -------- | 508| AV_IDLE | Idle.| 509| AV_INITIALIZED | Initialized.| 510| AV_PREPARED | Ready.| 511| AV_PLAYING | Playing.| 512| AV_PAUSED | Paused.| 513| AV_STOPPED | Stopped.| 514| AV_COMPLETED | Completed.| 515| AV_RELEASED | Released.| 516| AV_ERROR | Error.| 517 518 519## Function Description 520 521 522### OH_AVPlayer_Create() 523 524``` 525OH_AVPlayer* OH_AVPlayer_Create (void) 526``` 527**Description** 528Creates an **OH_AVPlayer** instance. 529 530> **NOTE** 531> 532> - You are advised to create a maximum of 16 **AVPlayer** instances for an application in both audio and video playback scenarios.<!--Del--> 533> - 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--> 534 535**System capability**: SystemCapability.Multimedia.Media.AVPlayer 536 537**Since**: 11 538 539**Returns** 540 541Returns the pointer to the **OH_AVPlayer** instance created if the operation is successful; returns a null pointer otherwise. 542 543The possible causes of an operation failure are as follows: 544 5451. The execution of **PlayerFactory::CreatePlayer** fails. 5462. The execution of **new PlayerObject** fails. 547 548 549### OH_AVPlayer_DeselectTrack() 550 551``` 552OH_AVErrCode OH_AVPlayer_DeselectTrack (OH_AVPlayer *player, int32_t index) 553``` 554**Description** 555Deselects an audio track. This function is not supported yet. 556 557**System capability**: SystemCapability.Multimedia.Media.AVPlayer 558 559**Since**: 11 560 561**Parameters** 562 563| Name| Description| 564| -------- | -------- | 565| player | Pointer to an **OH_AVPlayer** instance.| 566| index | Index of the track. | 567 568**Returns** 569 570Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 571 572**AV_ERR_OK**: The deselection is successful. 573 574**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player DeselectTrack** fails. 575 576 577### OH_AVPlayer_GetCurrentTime() 578 579``` 580OH_AVErrCode OH_AVPlayer_GetCurrentTime (OH_AVPlayer *player, int32_t *currentTime) 581``` 582**Description** 583Obtains the playback position, in milliseconds. 584 585**System capability**: SystemCapability.Multimedia.Media.AVPlayer 586 587**Since**: 11 588 589**Parameters** 590 591| Name| Description| 592| -------- | -------- | 593| player | Pointer to an **OH_AVPlayer** instance.| 594| currentTime | Pointer to the playback position.| 595 596**Returns** 597 598Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 599 600**AV_ERR_OK**: The playback position is obtained. 601 602**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player GetCurrentTime** fails. 603 604 605### OH_AVPlayer_GetCurrentTrack() 606 607``` 608OH_AVErrCode OH_AVPlayer_GetCurrentTrack (OH_AVPlayer *player, int32_t trackType, int32_t *index) 609``` 610**Description** 611Obtains the currently valid track. This function is not supported yet. 612 613You can set the track to the prepared, playing, paused, or completed state. 614 615**System capability**: SystemCapability.Multimedia.Media.AVPlayer 616 617**Since**: 11 618 619**Parameters** 620 621| Name| Description| 622| -------- | -------- | 623| player | Pointer to an **OH_AVPlayer** instance.| 624| trackType | Media type. The value **0** means audio and **1** means video.| 625| index | Index of the track.| 626 627**Returns** 628 629Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 630 631**AV_ERR_OK**: The track is obtained. 632 633**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player GetCurrentTrack** fails. 634 635 636### OH_AVPlayer_GetDuration() 637 638``` 639OH_AVErrCode OH_AVPlayer_GetDuration (OH_AVPlayer *player, int32_t *duration) 640``` 641**Description** 642Obtains the total duration of a media file, in milliseconds. 643 644**System capability**: SystemCapability.Multimedia.Media.AVPlayer 645 646**Since**: 11 647 648**Parameters** 649 650| Name| Description| 651| -------- | -------- | 652| player | Pointer to an **OH_AVPlayer** instance.| 653| duration | Pointer to the total duration.| 654 655**Returns** 656 657Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 658 659**AV_ERR_OK**: The total duration is obtained. 660 661**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player GetDuration** fails. 662 663 664### OH_AVPlayer_GetMediaKeySystemInfo() 665 666``` 667OH_AVErrCode OH_AVPlayer_GetMediaKeySystemInfo (OH_AVPlayer *player, DRM_MediaKeySystemInfo *mediaKeySystemInfo) 668``` 669**Description** 670Obtains the media key system information to create a media key session. 671 672**System capability**: SystemCapability.Multimedia.Media.AVPlayer 673 674**Since**: 12 675 676**Parameters** 677 678| Name| Description| 679| -------- | -------- | 680| player | Pointer to an **OH_AVPlayer** instance.| 681| mediaKeySystemInfo | Pointer to the media key system information.| 682 683**Returns** 684 685Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 686 687**AV_ERR_OK**: The setting is successful. 688 689**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the memory is insufficient. 690 691### OH_AVPlayer_GetPlaybackSpeed() 692 693``` 694OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed (OH_AVPlayer *player, AVPlaybackSpeed *speed) 695``` 696**Description** 697Obtains the playback speed of an AVPlayer. 698 699**System capability**: SystemCapability.Multimedia.Media.AVPlayer 700 701**Since**: 11 702 703**Parameters** 704 705| Name| Description| 706| -------- | -------- | 707| player | Pointer to an **OH_AVPlayer** instance.| 708| speed | Pointer to the playback speed. For details about the available options, see [AVPlaybackSpeed](#avplaybackspeed).| 709 710**Returns** 711 712Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 713 714**AV_ERR_OK**: The playback rate is obtained. 715 716**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player GetPlaybackSpeed** fails. 717 718 719### OH_AVPlayer_GetState() 720 721``` 722OH_AVErrCode OH_AVPlayer_GetState (OH_AVPlayer *player, AVPlayerState *state) 723``` 724**Description** 725Obtains the AVPlayer state. 726 727**System capability**: SystemCapability.Multimedia.Media.AVPlayer 728 729**Since**: 11 730 731**Parameters** 732 733| Name| Description| 734| -------- | -------- | 735| player | Pointer to an **OH_AVPlayer** instance.| 736| state | Pointer to the state.| 737 738**Returns** 739 740Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 741 742**AV_ERR_OK**: The AVPlayer state is obtained. 743 744**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player GetState** fails. 745 746 747### OH_AVPlayer_GetVideoHeight() 748 749``` 750OH_AVErrCode OH_AVPlayer_GetVideoHeight (OH_AVPlayer *player, int32_t *videoHeight) 751``` 752**Description** 753Obtains the video height. 754 755**System capability**: SystemCapability.Multimedia.Media.AVPlayer 756 757**Since**: 11 758 759**Parameters** 760 761| Name| Description| 762| -------- | -------- | 763| player | Pointer to an **OH_AVPlayer** instance.| 764| videoHeights | Pointer to the video height.| 765 766**Returns** 767 768Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 769 770**AV_ERR_OK**: The video height is obtained. 771 772**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer. 773 774 775### OH_AVPlayer_GetVideoWidth() 776 777``` 778OH_AVErrCode OH_AVPlayer_GetVideoWidth (OH_AVPlayer *player, int32_t *videoWidth) 779``` 780**Description** 781Obtains the video width. 782 783**System capability**: SystemCapability.Multimedia.Media.AVPlayer 784 785**Since**: 11 786 787**Parameters** 788 789| Name| Description| 790| -------- | -------- | 791| player | Pointer to an **OH_AVPlayer** instance.| 792| videoWidth | Pointer to the video width.| 793 794**Returns** 795 796Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 797 798**AV_ERR_OK**: The video width is obtained. 799 800**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer. 801 802 803### OH_AVPlayer_IsLooping() 804 805``` 806bool OH_AVPlayer_IsLooping (OH_AVPlayer *player) 807``` 808**Description** 809Checks whether an AVPlayer is looping. 810 811**System capability**: SystemCapability.Multimedia.Media.AVPlayer 812 813**Since**: 11 814 815**Parameters** 816 817| Name| Description| 818| -------- | -------- | 819| player | Pointer to an **OH_AVPlayer** instance.| 820 821**Returns** 822 823Returns **true** if the AVPlayer is looping; returns **false** if the AVPlayer is not looping or the input parameter **player** is a null pointer. 824 825 826### OH_AVPlayer_IsPlaying() 827 828``` 829bool OH_AVPlayer_IsPlaying (OH_AVPlayer *player) 830``` 831**Description** 832Checks whether an AVPlayer is playing. 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 844**Returns** 845 846Returns **true** if the AVPlayer is playing; returns **false** if the AVPlayer is not playing or the input parameter **player** is a null pointer. 847 848 849### OH_AVPlayer_Pause() 850 851``` 852OH_AVErrCode OH_AVPlayer_Pause (OH_AVPlayer *player) 853``` 854**Description** 855Pauses playback. 856 857**System capability**: SystemCapability.Multimedia.Media.AVPlayer 858 859**Since**: 11 860 861**Parameters** 862 863| Name| Description| 864| -------- | -------- | 865| player | Pointer to an **OH_AVPlayer** instance.| 866 867**Returns** 868 869Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 870 871**AV_ERR_OK**: The **Pause** operation is added to the task queue. 872 873**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player Pause** fails. 874 875 876### OH_AVPlayer_Play() 877 878``` 879OH_AVErrCode OH_AVPlayer_Play (OH_AVPlayer *player) 880``` 881**Description** 882Starts playback. 883 884This function must be called after **Prepare**. In other words, you can call this function when the AVPlayer is in the prepared state. 885 886**System capability**: SystemCapability.Multimedia.Media.AVPlayer 887 888**Since**: 11 889 890**Parameters** 891 892| Name| Description| 893| -------- | -------- | 894| player | Pointer to an **OH_AVPlayer** instance.| 895 896**Returns** 897 898Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 899 900**AV_ERR_OK**: The playback starts. 901 902**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player Play** fails. 903 904 905### OH_AVPlayer_Prepare() 906 907``` 908OH_AVErrCode OH_AVPlayer_Prepare (OH_AVPlayer *player) 909``` 910**Description** 911Prepares the playback environment and buffers media data. 912 913This function must be called after **SetSource**. 914 915**System capability**: SystemCapability.Multimedia.Media.AVPlayer 916 917**Since**: 11 918 919**Parameters** 920 921| Name| Description| 922| -------- | -------- | 923| player | Pointer to an **OH_AVPlayer** instance.| 924 925**Returns** 926 927Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 928 929**AV_ERR_OK**: The **Prepare** operation is added to the task queue. 930 931**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player Prepare** fails. 932 933 934### OH_AVPlayer_Release() 935 936``` 937OH_AVErrCode OH_AVPlayer_Release (OH_AVPlayer *player) 938``` 939**Description** 940Asynchronously releases an **OH_AVPlayer** instance. 941 942The 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. 943 944**System capability**: SystemCapability.Multimedia.Media.AVPlayer 945 946**Since**: 11 947 948**Parameters** 949 950| Name| Description| 951| -------- | -------- | 952| player | Pointer to an **OH_AVPlayer** instance.| 953 954**Returns** 955 956Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 957 958**AV_ERR_OK**: The **Release** operation is added to the task queue. 959 960**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player Release** fails. 961 962 963### OH_AVPlayer_ReleaseSync() 964 965``` 966OH_AVErrCode OH_AVPlayer_ReleaseSync (OH_AVPlayer *player) 967``` 968**Description** 969Synchronously releases an **OH_AVPlayer** instance. 970 971The 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. 972 973**System capability**: SystemCapability.Multimedia.Media.AVPlayer 974 975**Since**: 11 976 977**Parameters** 978 979| Name| Description| 980| -------- | -------- | 981| player | Pointer to an **OH_AVPlayer** instance.| 982 983**Returns** 984 985Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 986 987**AV_ERR_OK**: The AVPlayer is released. 988 989**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player ReleaseSync** fails. 990 991### OH_AVPlayer_Reset() 992 993``` 994OH_AVErrCode OH_AVPlayer_Reset (OH_AVPlayer *player) 995``` 996**Description** 997Restores the AVPlayer to the initial state. 998 999After the function is called, you can call **SetSource** to set the media source to play, and then call **Prepare** and **Play** in sequence. 1000 1001**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1002 1003**Since**: 11 1004 1005**Parameters** 1006 1007| Name| Description| 1008| -------- | -------- | 1009| player | Pointer to an **OH_AVPlayer** instance.| 1010 1011**Returns** 1012 1013Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1014 1015**AV_ERR_OK**: The **reset** operation is added to the task queue. 1016 1017**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player Reset** fails. 1018 1019 1020### OH_AVPlayer_Seek() 1021 1022``` 1023OH_AVErrCode OH_AVPlayer_Seek (OH_AVPlayer *player, int32_t mSeconds, AVPlayerSeekMode mode) 1024``` 1025**Description** 1026Seeks to a playback position. 1027 1028This function can be used when the AVPlayer is in the playing or paused state. 1029 1030**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1031 1032**Parameters** 1033 1034| Name| Description| 1035| -------- | -------- | 1036| player | Pointer to an **OH_AVPlayer** instance.| 1037| mSeconds | Position to seek to, in ms.| 1038| mode | Seek mode. For details about the available options, see [AVPlayerSeekMode](#avplayerseekmode).| 1039 1040**Returns** 1041 1042Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1043 1044AV_ERR_OK: The seek operation is complete. 1045 1046**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player Seek** fails. 1047 1048 1049### OH_AVPlayer_SelectBitRate() 1050 1051``` 1052OH_AVErrCode OH_AVPlayer_SelectBitRate (OH_AVPlayer *player, uint32_t bitRate) 1053``` 1054**Description** 1055Sets the bit rate used by an HLS player, 1056 1057in 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. 1058 1059**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1060 1061**Since**: 11 1062 1063**Parameters** 1064 1065| Name| Description| 1066| -------- | -------- | 1067| player | Pointer to an **OH_AVPlayer** instance.| 1068| bitRate | Bit rate, in kbit/s.| 1069 1070**Returns** 1071 1072**Returns** 1073 1074Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1075 1076**AV_ERR_OK**: The bit rate is set. 1077 1078**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player SelectBitRate** fails. 1079 1080 1081### OH_AVPlayer_SelectTrack() 1082 1083``` 1084OH_AVErrCode OH_AVPlayer_SelectTrack (OH_AVPlayer *player, int32_t index) 1085``` 1086**Description** 1087Selects an audio track. This function is not supported yet. 1088 1089By default, the first audio stream with data is played. After the setting takes effect, the original track becomes invalid. This API sets the audio track to the ready state. 1090 1091**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1092 1093**Since**: 11 1094 1095**Parameters** 1096 1097| Name| Description| 1098| -------- | -------- | 1099| player | Pointer to an **OH_AVPlayer** instance.| 1100| index | Index of the track.| 1101 1102**Returns** 1103 1104Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1105 1106**AV_ERR_OK**: A track is selected. 1107 1108**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player SelectTrack** fails. 1109 1110 1111### OH_AVPlayer_SetAudioEffectMode() 1112 1113``` 1114OH_AVErrCode OH_AVPlayer_SetAudioEffectMode (OH_AVPlayer *player, OH_AudioStream_AudioEffectMode effectMode) 1115``` 1116**Description** 1117Sets the audio effect mode for an AVPlayer. 1118 1119**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1120 1121**Since**: 12 1122 1123**Parameters** 1124 1125| Name| Description| 1126| -------- | -------- | 1127| player | Pointer to an **OH_AVPlayer** instance. | 1128| interruptMode | Audio effect mode. For details about the available options, see [OH_AudioStream_AudioEffectMode](../apis-audio-kit/_o_h_audio.md#oh_audiostream_audioeffectmode). | 1129 1130**Returns** 1131 1132Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1133 1134**AV_ERR_OK**: The setting is successful. 1135 1136**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer or **effectMode** is invalid. 1137 1138 1139### OH_AVPlayer_SetAudioInterruptMode() 1140 1141``` 1142OH_AVErrCode OH_AVPlayer_SetAudioInterruptMode (OH_AVPlayer *player, OH_AudioInterrupt_Mode interruptMode) 1143``` 1144**Description** 1145Sets the audio interruption mode for an AVPlayer. 1146 1147**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1148 1149**Since**: 12 1150 1151**Parameters** 1152 1153| Name| Description| 1154| -------- | -------- | 1155| player | Pointer to an **OH_AVPlayer** instance. | 1156| interruptMode | Audio interruption mode. For details about the available options, see [OH_AudioInterrupt_Mode](../apis-audio-kit/_o_h_audio.md#oh_audiointerrupt_mode). | 1157 1158**Returns** 1159 1160Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1161 1162**AV_ERR_OK**: The setting is successful. 1163 1164**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer or **interruptMode** is invalid. 1165 1166 1167### OH_AVPlayer_SetAudioRendererInfo() 1168 1169``` 1170OH_AVErrCode OH_AVPlayer_SetAudioRendererInfo (OH_AVPlayer *player, OH_AudioStream_Usage streamUsage) 1171``` 1172**Description** 1173Sets the audio stream type for an AVPlayer. 1174 1175**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1176 1177**Since**: 12 1178 1179**Parameters** 1180 1181| Name| Description| 1182| -------- | -------- | 1183| player | Pointer to an **OH_AVPlayer** instance. | 1184| streamUsage | Audio stream type. For details about the available options, see [OH_AudioStream_Usage](../apis-audio-kit/_o_h_audio.md#oh_audiostream_usage). | 1185 1186**Returns** 1187 1188Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1189 1190**AV_ERR_OK**: The setting is successful. 1191 1192**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer or **streamUsage** is invalid. 1193 1194 1195### OH_AVPlayer_SetDecryptionConfig() 1196 1197``` 1198OH_AVErrCode OH_AVPlayer_SetDecryptionConfig (OH_AVPlayer *player, MediaKeySession *mediaKeySession, bool secureVideoPath) 1199``` 1200**Description** 1201Sets the decryption information. 1202 1203**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1204 1205**Since**: 12 1206 1207**Parameters** 1208 1209| Name| Description| 1210| -------- | -------- | 1211| player | Pointer to an **OH_AVPlayer** instance.| 1212| mediaKeySession | Pointer to the media key session with the decryption feature.| 1213| secureVideoPath | Whether a secure decoder is required.| 1214 1215**Returns** 1216 1217Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1218 1219**AV_ERR_OK**: The setting is successful. 1220 1221**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player SetDecryptionConfig** fails. 1222 1223 1224### OH_AVPlayer_SetFDSource() 1225 1226``` 1227OH_AVErrCode OH_AVPlayer_SetFDSource (OH_AVPlayer *player, int32_t fd, int64_t offset, int64_t size) 1228``` 1229**Description** 1230Sets the file descriptor of a media source to be played by an AVPlayer. 1231 1232**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1233 1234**Since**: 11 1235 1236**Parameters** 1237 1238| Name| Description| 1239| -------- | -------- | 1240| player | Pointer to an **OH_AVPlayer** instance.| 1241| fd | File descriptor of the media source.| 1242| offset | Offset of the media source in the file descriptor.| 1243| size | Size of the media source.| 1244 1245**Returns** 1246 1247Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1248 1249**AV_ERR_OK**: The file descriptor is set. 1250 1251**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player SetFdSource** fails. 1252 1253 1254### OH_AVPlayer_SetLooping() 1255 1256``` 1257OH_AVErrCode OH_AVPlayer_SetLooping (OH_AVPlayer *player, bool loop) 1258``` 1259**Description** 1260Enables loop playback. 1261 1262**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1263 1264**Since**: 11 1265 1266**Parameters** 1267 1268| Name| Description| 1269| -------- | -------- | 1270| player | Pointer to an **OH_AVPlayer** instance.| 1271| loop | Whether to enable loop playback.| 1272 1273**Returns** 1274 1275Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1276 1277**AV_ERR_OK**: Loop playback is enabled. 1278 1279**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player SetLooping** fails. 1280 1281 1282### OH_AVPlayer_SetMediaKeySystemInfoCallback() 1283 1284``` 1285OH_AVErrCode OH_AVPlayer_SetMediaKeySystemInfoCallback (OH_AVPlayer *player, Player_MediaKeySystemInfoCallback callback) 1286``` 1287**Description** 1288Sets a callback to return the media key system information for an AVPlayer. 1289 1290**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1291 1292**Since**: 12 1293 1294**Parameters** 1295 1296| Name| Description| 1297| -------- | -------- | 1298| player | Pointer to an **OH_AVPlayer** instance.| 1299| callback | Callback.| 1300 1301**Returns** 1302 1303Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1304 1305**AV_ERR_OK**: The setting is successful. 1306 1307**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, the input parameter **callback** is null, or the execution of **player SetDrmSystemInfoCallback** fails. 1308 1309 1310### OH_AVPlayer_SetOnErrorCallback() 1311 1312``` 1313OH_AVErrCode OH_AVPlayer_SetOnErrorCallback (OH_AVPlayer * player, OH_AVPlayerOnErrorCallback callback, void * userData ) 1314``` 1315**Description** 1316Sets a callback for the event indicating that an error occurs in the AVPlayer. 1317 1318**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1319 1320**Since**: 12 1321 1322**Parameters** 1323 1324| Name| Description| 1325| -------- | -------- | 1326| player | Pointer to an **OH_AVPlayer** instance. | 1327| callback | Pointer to the callback. If a null pointer is passed in, the listening for AVPlayer errors is canceled. | 1328| userData | Pointer to the instance set by the caller. | 1329 1330**Returns** 1331 1332Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1333 1334**AV_ERR_OK**: The operation is successful. 1335 1336**AV_ERR_NO_MEMORY**: An error occurs during memory allocation. 1337 1338**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer or the function fails to be executed. 1339 1340 1341### OH_AVPlayer_SetOnInfoCallback() 1342 1343``` 1344OH_AVErrCode OH_AVPlayer_SetOnInfoCallback (OH_AVPlayer * player, OH_AVPlayerOnInfoCallback callback, void * userData ) 1345``` 1346**Description** 1347Sets a callback for the event indicating that the AVPlayer receives a message. 1348 1349**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1350 1351**Since**: 12 1352 1353**Parameters** 1354 1355| Name| Description| 1356| -------- | -------- | 1357| player | Pointer to an **OH_AVPlayer** instance. | 1358| callback | Pointer to the callback. If a null pointer is passed in, the listening for AVPlayer messages is canceled. | 1359| userData | Pointer to the instance set by the caller. | 1360 1361**Returns** 1362 1363Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1364 1365**AV_ERR_OK**: The operation is successful. 1366 1367**AV_ERR_NO_MEMORY**: An error occurs during memory allocation. 1368 1369**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer or the function fails to be executed. 1370 1371 1372### OH_AVPlayer_SetPlaybackSpeed() 1373 1374``` 1375OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed (OH_AVPlayer *player, AVPlaybackSpeed speed) 1376``` 1377**Description** 1378Sets the playback speed for an AVPlayer. 1379 1380**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1381 1382**Parameters** 1383 1384| Name| Description| 1385| -------- | -------- | 1386| player | Pointer to an **OH_AVPlayer** instance.| 1387| speed | Playback speed. For details about the available options, see [AVPlaybackSpeed](#avplaybackspeed).| 1388 1389**Returns** 1390 1391Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1392 1393**AV_ERR_OK**: The playback speed is set. 1394 1395**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer. 1396 1397 1398### OH_AVPlayer_SetPlayerCallback() 1399 1400``` 1401OH_AVErrCode OH_AVPlayer_SetPlayerCallback (OH_AVPlayer *player, AVPlayerCallback callback) 1402``` 1403**Description** 1404Sets an AVPlayer callback. The callbacks [OH_AVPlayerOnInfo](#oh_avplayeroninfo) and [OH_AVPlayerOnError](#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()](#oh_avplayer_setoninfocallback) and [OH_AVPlayer_SetOnErrorCallback()](#oh_avplayer_setonerrorcallback) are provided to set the callbacks [OH_AVPlayerOnInfoCallback](../../reference/apis-media-kit/_a_v_player.md#oh_avplayeroninfocallback) and [OH_AVPlayerOnErrorCallback](../../reference/apis-media-kit/_a_v_player.md#oh_avplayeronerrorcallback), respectively. 1405 1406**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1407 1408**Since**: 11 1409 1410**Parameters** 1411 1412| Name| Description| 1413| -------- | -------- | 1414| player | Pointer to an **OH_AVPlayer** instance.| 1415| callback | Callback used to return the result.| 1416 1417**Returns** 1418 1419Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1420 1421**AV_ERR_OK**: The callback is set. 1422 1423**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, the input parameter **callback.onInfo** or **onError** is null, or the execution of **player SetPlayerCallback** fails. 1424 1425 1426### OH_AVPlayer_SetURLSource() 1427 1428``` 1429OH_AVErrCode OH_AVPlayer_SetURLSource (OH_AVPlayer *player, const char *url) 1430``` 1431**Description** 1432Sets the HTTP URL of a media source to be played by an AVPlayer. 1433 1434**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1435 1436**Since**: 11 1437 1438**Parameters** 1439 1440| Name| Description| 1441| -------- | -------- | 1442| player | Pointer to an **OH_AVPlayer** instance.| 1443| url | URL of the media source.| 1444 1445**Returns** 1446 1447Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1448 1449**AV_ERR_OK**: The setting is successful. 1450 1451**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, the input parameter **url** is null, or the execution of **player SetUrlSource** fails. 1452 1453 1454### OH_AVPlayer_SetVideoSurface() 1455 1456``` 1457OH_AVErrCode OH_AVPlayer_SetVideoSurface (OH_AVPlayer *player, OHNativeWindow *window) 1458``` 1459**Description** 1460Sets a playback window. 1461This function must be called after **SetSource** and before **Prepare**. 1462 1463**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1464 1465**Parameters** 1466 1467| Name| Description| 1468| -------- | -------- | 1469| player | Pointer to an **OH_AVPlayer** instance.| 1470| window | Pointer to an **OHNativeWindow** instance.| 1471 1472**Returns** 1473 1474Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1475 1476AV_ERR_OK: The playback window is set. 1477 1478**AV_ERR_INVALID_VAL**: The input parameter **player** or **window** is a null pointer, or the execution of **player SetVideoSurface** fails. 1479 1480 1481### OH_AVPlayer_SetVolume() 1482 1483``` 1484OH_AVErrCode OH_AVPlayer_SetVolume (OH_AVPlayer *player, float leftVolume, float rightVolume) 1485``` 1486**Description** 1487Sets the volume for an AVPlayer. 1488 1489This 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. 1490 1491**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1492 1493**Since**: 11 1494 1495**Parameters** 1496 1497| Name| Description| 1498| -------- | -------- | 1499| player | Pointer to an **OH_AVPlayer** instance.| 1500| leftVolume | Target volume of the left channel.| 1501| rightVolume | Target volume of the right channel.| 1502 1503**Returns** 1504 1505Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1506 1507AV_ERR_OK: The volume is set. 1508 1509**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player SetVolume** fails. 1510 1511 1512### OH_AVPlayer_Stop() 1513 1514``` 1515OH_AVErrCode OH_AVPlayer_Stop (OH_AVPlayer *player) 1516``` 1517**Description** 1518Stops playback. 1519 1520**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1521 1522**Since**: 11 1523 1524**Parameters** 1525 1526| Name| Description| 1527| -------- | -------- | 1528| player | Pointer to an **OH_AVPlayer** instance.| 1529 1530**Returns** 1531 1532Returns a result code defined in [OH_AVErrCode](../apis-avcodec-kit/_core.md#oh_averrcode-1). The following result codes are possible: 1533 1534**AV_ERR_OK**: The **stop** operation is added to the task queue. 1535 1536**AV_ERR_INVALID_VAL**: The input parameter **player** is a null pointer, or the execution of **player Stop** fails. 1537 1538 1539## Variable Description 1540 1541 1542### OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON 1543 1544``` 1545const char* OH_PLAYER_AUDIO_DEVICE_CHANGE_REASON 1546``` 1547**Description** 1548Pointer to the key for obtaining the audio device change reason. The value is of the int32_t type. 1549 1550**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1551 1552**Since**: 12 1553 1554 1555### OH_PLAYER_AUDIO_INTERRUPT_FORCE 1556 1557``` 1558const char* OH_PLAYER_AUDIO_INTERRUPT_FORCE 1559``` 1560**Description** 1561Pointer to the key for obtaining the FORCE type of audio interruption. The value is of the int32_t type. 1562 1563**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1564 1565**Since**: 12 1566 1567 1568### OH_PLAYER_AUDIO_INTERRUPT_HINT 1569 1570``` 1571const char* OH_PLAYER_AUDIO_INTERRUPT_HINT 1572``` 1573**Description** 1574Pointer to the key for obtaining the HINT type of audio interruption. The value is of the int32_t type. 1575 1576**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1577 1578**Since**: 12 1579 1580 1581### OH_PLAYER_AUDIO_INTERRUPT_TYPE 1582 1583``` 1584const char* OH_PLAYER_AUDIO_INTERRUPT_TYPE 1585``` 1586**Description** 1587Pointer to the key for obtaining the audio interruption type. The value is of the int32_t type. 1588 1589**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1590 1591**Since**: 12 1592 1593 1594### OH_PLAYER_BITRATE 1595 1596``` 1597const char* OH_PLAYER_BITRATE 1598``` 1599**Description** 1600Pointer to the key for obtaining the bit rate. The value is of the int32_t type. 1601 1602**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1603 1604**Since**: 12 1605 1606 1607### OH_PLAYER_BITRATE_ARRAY 1608 1609``` 1610const char* OH_PLAYER_BITRATE_ARRAY 1611``` 1612**Description** 1613Pointer to the key for obtaining the bit rate array. The value is of the uint8_t byte array type. When this key is used to obtain information, you need to: 1614- Use a pointer variable of the uint8_t type to store the bit rate list and use a variable of the size_t type to store the byte array length. 1615- Allocate several storage spaces of the uint32_t type to receive the bit rate integer of the uint32_t type, which is converted from the uint8_t byte array. For details, see the **OHAVPlayerOnInfoCallback** function in [Sample Code](../../media/media/using-ndk-avplayer-for-playback.md#sample-code). 1616 1617**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1618 1619**Since**: 12 1620 1621 1622### OH_PLAYER_BUFFERING_TYPE 1623 1624``` 1625const char* OH_PLAYER_BUFFERING_TYPE 1626``` 1627**Description** 1628Pointer to the key for obtaining the type of the buffer update message. The value type is [AVPlayerBufferingType](#avplayerbufferingtype-1). When this key is used to obtain information, you must use a variable of the int32_t type to save the result and then convert the result to a value of [AVPlayerBufferingType](#avplayerbufferingtype-1). 1629 1630**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1631 1632**Since**: 12 1633 1634 1635### OH_PLAYER_BUFFERING_VALUE 1636 1637``` 1638const char* OH_PLAYER_BUFFERING_VALUE 1639``` 1640**Description** 1641Pointer to the key for obtaining the value of the buffer update message. The value is of the int32_t type. For details about the available options, see [AVPlayerBufferingType](#avplayerbufferingtype-1). This key is valid when the buffer update message type is **AVPLAYER_BUFFERING_PERCENT** or **AVPLAYER_BUFFERING_CACHED_DURATION**. 1642 1643**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1644 1645**Since**: 12 1646 1647 1648### OH_PLAYER_CURRENT_POSITION 1649 1650``` 1651const char* OH_PLAYER_CURRENT_POSITION 1652``` 1653**Description** 1654Pointer to the key for obtaining the playback progress information. The value is of the int32_t type. 1655 1656**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1657 1658**Since**: 12 1659 1660 1661### OH_PLAYER_DURATION 1662 1663``` 1664const char* OH_PLAYER_DURATION 1665``` 1666**Description** 1667Pointer to the key for obtaining the media asset duration. The value type is int64_t. 1668 1669**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1670 1671**Since**: 12 1672 1673 1674### OH_PLAYER_IS_LIVE_STREAM 1675 1676``` 1677const char* OH_PLAYER_IS_LIVE_STREAM 1678``` 1679**Description** 1680Pointer to the key for checking whether a media asset is live streaming. The value is of the int32_t type. 1681 1682The value **1** means live streaming. 1683 1684**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1685 1686**Since**: 12 1687 1688 1689### OH_PLAYER_MESSAGE_TYPE 1690 1691``` 1692const char* OH_PLAYER_MESSAGE_TYPE 1693``` 1694**Description** 1695Pointer to the key for obtaining the type of message received by the AVPlayer. The value is of the int32_t type. 1696 1697The value **1** means that the video frame starts to be rendered. 1698 1699**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1700 1701**Since**: 12 1702 1703 1704### OH_PLAYER_PLAYBACK_SPEED 1705 1706``` 1707const char* OH_PLAYER_PLAYBACK_SPEED 1708``` 1709**Description** 1710Pointer to the key for obtaining the playback speed. The value type is [AVPlaybackSpeed](#avplaybackspeed-1). When this key is used to obtain information, you must use a variable of the int32_t type to save the result and then convert the result to a value of [AVPlaybackSpeed](#avplaybackspeed-1). 1711 1712**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1713 1714**Since**: 12 1715 1716 1717### OH_PLAYER_SEEK_POSITION 1718 1719``` 1720const char* OH_PLAYER_SEEK_POSITION 1721``` 1722**Description** 1723Pointer to the key for obtaining the playback progress after the seek operation. The value is of the int32_t type. 1724 1725**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1726 1727**Since**: 12 1728 1729 1730### OH_PLAYER_STATE 1731 1732``` 1733const char* OH_PLAYER_STATE 1734``` 1735**Description** 1736Pointer to the key for obtaining the AVPlayer state. The value is of the int32_t type. 1737 1738**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1739 1740**Since**: 12 1741 1742 1743### OH_PLAYER_STATE_CHANGE_REASON 1744 1745``` 1746const char* OH_PLAYER_STATE_CHANGE_REASON 1747``` 1748**Description** 1749Pointer to the key for obtaining the AVPlayer state change reason. The value is of the int32_t type. 1750 1751The value **1** means that the change is triggered by user operations, and **2** means that the change is triggered by the system. 1752 1753**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1754 1755**Since**: 12 1756 1757 1758### OH_PLAYER_VIDEO_HEIGHT 1759 1760``` 1761const char* OH_PLAYER_VIDEO_HEIGHT 1762``` 1763**Description** 1764Pointer to the key for obtaining the video height. The value is of the int32_t type. 1765 1766**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1767 1768**Since**: 12 1769 1770 1771### OH_PLAYER_VIDEO_WIDTH 1772 1773``` 1774const char* OH_PLAYER_VIDEO_WIDTH 1775``` 1776**Description** 1777Pointer to the key for obtaining the video width. The value is of the int32_t type. 1778 1779**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1780 1781**Since**: 12 1782 1783 1784### OH_PLAYER_VOLUME 1785 1786``` 1787const char* OH_PLAYER_VOLUME 1788``` 1789**Description** 1790Pointer to the key for obtaining the volume. The value type is float. 1791 1792**System capability**: SystemCapability.Multimedia.Media.AVPlayer 1793 1794**Since**: 12 1795