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