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