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