openharmony 鸿蒙 capi-avplayer-h

2025-06-12 浏览 (1)

avplayer.h

Overview

The avplayer.h file declares the AVPlayer APIs. You can use the native AVPlayer APIs to play a media asset.

File to include: <multimedia/player_framework/avplayer.h>

Library: libavplayer.so

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Related module: AVPlayer

Summary

Structs

Nametypedef KeywordDescription
MediaKeySessionMediaKeySessionDescribes the media key session.
DRM_MediaKeySystemInfoDRM_MediaKeySystemInfoDescribes the media key system information.

Functions

Nametypedef KeywordDescription
typedef void (*Player_MediaKeySystemInfoCallback)(OH_AVPlayer *player, DRM_MediaKeySystemInfo* mediaKeySystemInfo)Player_MediaKeySystemInfoCallbackCalled when media key system information of the AVPlayer is updated.
OH_AVPlayer *OH_AVPlayer_Create(void)-Creates an OH_AVPlayer instance.
You are advised to create a maximum of 16 AVPlayer instances for an application in both audio and video playback scenarios.
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.
OH_AVErrCode OH_AVPlayer_SetURLSource(OH_AVPlayer *player, const char *url)-Sets the HTTP URL of a media source to be played by an AVPlayer.
OH_AVErrCode 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.
OH_AVErrCode OH_AVPlayer_Prepare(OH_AVPlayer *player)-Prepares the playback environment and buffers media data.
This function must be called after SetSource.
OH_AVErrCode OH_AVPlayer_Play(OH_AVPlayer *player)-Starts playback.
This function must be called after OH_AVPlayer_Prepare.
In other words, you can call this function when the AVPlayer is in the prepared state.
OH_AVErrCode OH_AVPlayer_Pause(OH_AVPlayer *player)-Pauses playback.
OH_AVErrCode OH_AVPlayer_Stop(OH_AVPlayer *player)-Stops playback.
OH_AVErrCode OH_AVPlayer_Reset(OH_AVPlayer *player)-Restores the AVPlayer to the initial state.
After the function is called, you can call SetSource to set the media source to play, and then call OH_AVPlayer_Prepare and OH_AVPlayer_Play in sequence.
OH_AVErrCode OH_AVPlayer_Release(OH_AVPlayer *player)-Asynchronously releases an OH_AVPlayer instance. The asynchronous function improves performance, but cannot ensure that the surface buffer of the playback window is released. You must ensure the lifecycle of the playback window.
OH_AVErrCode OH_AVPlayer_ReleaseSync(OH_AVPlayer *player)-Synchronously releases an OH_AVPlayer instance.
The synchronous function ensures that the display buffer of the playback window is released, with a long time. Therefore, you need to design an asynchronous mechanism.
OH_AVErrCode OH_AVPlayer_SetVolume(OH_AVPlayer *player, float leftVolume, float rightVolume)-Sets the volume for an AVPlayer.
This function can be used when the AVPlayer is in the playing or paused state. The value 0 means that the AVPlayer is muted, and 1 means that the original volume is used.
OH_AVErrCode OH_AVPlayer_Seek(OH_AVPlayer *player, int32_t mSeconds, AVPlayerSeekMode mode)-Seeks to a playback position.
This function can be used when the AVPlayer is in the playing or paused state.
OH_AVErrCode OH_AVPlayer_GetCurrentTime(OH_AVPlayer *player, int32_t *currentTime)-Obtains the playback position, in milliseconds.
OH_AVErrCode OH_AVPlayer_GetVideoWidth(OH_AVPlayer *player, int32_t *videoWidth)-Obtains the video width.
OH_AVErrCode OH_AVPlayer_GetVideoHeight(OH_AVPlayer *player, int32_t *videoHeight)-Obtains the video height.
OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed speed)-Sets the playback speed of an AVPlayer.
OH_AVErrCode OH_AVPlayer_SetPlaybackRate(OH_AVPlayer *player, float rate)-Sets the playback rate of an AVPlayer within the valid range.
The supported states are prepared, playing, paused, and completed.
OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed *speed)-Obtains the playback speed of an AVPlayer.
OH_AVErrCode OH_AVPlayer_SetAudioRendererInfo(OH_AVPlayer *player, OH_AudioStream_Usage streamUsage)-Sets the audio stream type for an AVPlayer.
OH_AVErrCode OH_AVPlayer_SetVolumeMode(OH_AVPlayer *player, OH_AudioStream_VolumeMode volumeMode)-Sets the audio volume mode for an AVPlayer.
OH_AVErrCode OH_AVPlayer_SetAudioInterruptMode(OH_AVPlayer *player, OH_AudioInterrupt_Mode interruptMode)-Sets the audio interruption mode for an AVPlayer.
OH_AVErrCode OH_AVPlayer_SetAudioEffectMode(OH_AVPlayer *player, OH_AudioStream_AudioEffectMode effectMode)-Sets the audio effect mode for an AVPlayer.
OH_AVErrCode OH_AVPlayer_SelectBitRate(OH_AVPlayer *player, uint32_t bitRate)-Sets the bit rate used by an HLS player. This function is valid only for HLS network streams.
By default, the AVPlayer 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. When ready, you can query the selected bit rate.
OH_AVErrCode OH_AVPlayer_SetVideoSurface(OH_AVPlayer *player, OHNativeWindow *window)-Sets a playback window.
This function must be called after SetSource and before Prepare.
OH_AVErrCode OH_AVPlayer_GetDuration(OH_AVPlayer *player, int32_t *duration)-Obtains the total duration of a media file, in milliseconds.
OH_AVErrCode OH_AVPlayer_GetState(OH_AVPlayer *player, AVPlayerState *state)-Obtains the AVPlayer state.
bool OH_AVPlayer_IsPlaying(OH_AVPlayer *player)-Checks whether an AVPlayer is playing.
bool OH_AVPlayer_IsLooping(OH_AVPlayer *player)-Checks whether an AVPlayer is looping.
OH_AVErrCode OH_AVPlayer_SetLooping(OH_AVPlayer *player, bool loop)-Enables loop playback.
OH_AVErrCode OH_AVPlayer_SetPlayerCallback(OH_AVPlayer *player, AVPlayerCallback callback)-Sets an AVPlayer callback.
The callbacks OH_AVPlayerOnInfo and 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 and OH_AVPlayer_SetOnErrorCallback are provided to set the callbacks OH_AVPlayerOnInfoCallback and OH_AVPlayerOnErrorCallback, respectively.
OH_AVErrCode OH_AVPlayer_SelectTrack(OH_AVPlayer *player, int32_t index)-Selects an audio or subtitle track.
By default, the first audio track with data is played, and the subtitle track is not played.
After the setting takes effect, the original track becomes invalid. Set the subtitle track to the prepared, playing, paused, or completed state, and set the audio track to the prepared state.
This function is not supported yet.
OH_AVErrCode OH_AVPlayer_DeselectTrack(OH_AVPlayer *player, int32_t index)-Deselects an audio or subtitle track.
This function is not supported yet.
OH_AVErrCode OH_AVPlayer_GetCurrentTrack(OH_AVPlayer *player, int32_t trackType, int32_t *index)-Obtains the currently valid track. You can set the track to the prepared, playing, paused, or completed state.
This function is not supported yet.
OH_AVErrCode OH_AVPlayer_SetMediaKeySystemInfoCallback(OH_AVPlayer *player,Player_MediaKeySystemInfoCallback callback)-Sets a callback to return the media key system information for an AVPlayer.
OH_AVErrCode OH_AVPlayer_GetMediaKeySystemInfo(OH_AVPlayer *player, DRM_MediaKeySystemInfo *mediaKeySystemInfo)-Obtains the media key system information to create a media key session.
OH_AVErrCode OH_AVPlayer_SetDecryptionConfig(OH_AVPlayer *player, MediaKeySession *mediaKeySession,bool secureVideoPath)-Sets the decryption information.
OH_AVErrCode OH_AVPlayer_SetOnInfoCallback(OH_AVPlayer *player, OH_AVPlayerOnInfoCallback callback, void *userData)-Sets a callback for the event indicating that the AVPlayer receives a message.
OH_AVErrCode OH_AVPlayer_SetOnErrorCallback(OH_AVPlayer *player, OH_AVPlayerOnErrorCallback callback, void *userData)-Sets a callback for the event indicating that an error occurs in the AVPlayer.

Function Description

Player_MediaKeySystemInfoCallback()

typedef void (*Player_MediaKeySystemInfoCallback)(OH_AVPlayer *player, DRM_MediaKeySystemInfo* mediaKeySystemInfo)

Description

Called when media key system information of the AVPlayer is updated.

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
DRM_MediaKeySystemInfo* mediaKeySystemInfoPointer to the media key system information.

OH_AVPlayer_Create()

OH_AVPlayer *OH_AVPlayer_Create(void)

Description

Creates an OH_AVPlayer instance.
You are advised to create a maximum of 16 AVPlayer instances for an application in both audio and video playback scenarios.

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.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Returns

TypeDescription
OH_AVPlayerPointer to the OH_AVPlayer instance created if the operation is successful; a null pointer otherwise.
The possible causes of an operation failure are as follows:
1. The execution of PlayerFactory::CreatePlayer fails.
2. The execution of new PlayerObject fails.

OH_AVPlayer_SetURLSource()

OH_AVErrCode OH_AVPlayer_SetURLSource(OH_AVPlayer *player, const char *url)

Description

Sets the HTTP URL of a media source to be played by an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
const char *urlURL of the media source.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The setting is successful.
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.

OH_AVPlayer_SetFDSource()

OH_AVErrCode OH_AVPlayer_SetFDSource(OH_AVPlayer *player, int32_t fd, int64_t offset, int64_t size)

Description

Sets the file descriptor of a media source to be played by an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t fdFile descriptor of the media source.
int64_t offsetOffset of the media source in the file descriptor.
int64_t sizeSize of the media source.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The file descriptor is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player SetFdSource fails.

OH_AVPlayer_Prepare()

OH_AVErrCode OH_AVPlayer_Prepare(OH_AVPlayer *player)

Description

Prepares the playback environment and buffers media data.
This function must be called after SetSource.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player Prepare fails.

OH_AVPlayer_Play()

OH_AVErrCode OH_AVPlayer_Play(OH_AVPlayer *player)

Description

Starts playback.
This function must be called after OH_AVPlayer_Prepare.
In other words, you can call this function when the AVPlayer is in the prepared state.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player Play fails.

OH_AVPlayer_Pause()

OH_AVErrCode OH_AVPlayer_Pause(OH_AVPlayer *player)

Description

Pauses playback.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player Pause fails.

OH_AVPlayer_Stop()

OH_AVErrCode OH_AVPlayer_Stop(OH_AVPlayer *player)

Description

Stops playback.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player Stop fails.

OH_AVPlayer_Reset()

OH_AVErrCode OH_AVPlayer_Reset(OH_AVPlayer *player)

Description

Restores the AVPlayer to the initial state.
After the function is called, you can call SetSource to set the media source to play, and then call OH_AVPlayer_Prepare and OH_AVPlayer_Play in sequence.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player Reset fails.

OH_AVPlayer_Release()

OH_AVErrCode OH_AVPlayer_Release(OH_AVPlayer *player)

Description

Asynchronously releases an OH_AVPlayer instance.
The asynchronous function improves performance, but cannot ensure that the surface buffer of the playback window is released. You must ensure the lifecycle of the playback window.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player Release fails.

OH_AVPlayer_ReleaseSync()

OH_AVErrCode OH_AVPlayer_ReleaseSync(OH_AVPlayer *player)

Description

Synchronously releases an OH_AVPlayer instance.
The synchronous function ensures that the display buffer of the playback window is released, with a long time. Therefore, you need to design an asynchronous mechanism.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player ReleaseSync fails.

OH_AVPlayer_SetVolume()

OH_AVErrCode OH_AVPlayer_SetVolume(OH_AVPlayer *player, float leftVolume, float rightVolume)

Description

Sets the volume for an AVPlayer.
This function can be used when the AVPlayer is in the playing or paused state. The value 0 means that the AVPlayer is muted, and 1 means that the original volume is used.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
float leftVolumeTarget volume of the left channel.
float rightVolumeTarget volume of the right channel.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The volume is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player SetVolume fails.

OH_AVPlayer_Seek()

OH_AVErrCode OH_AVPlayer_Seek(OH_AVPlayer *player, int32_t mSeconds, AVPlayerSeekMode mode)

Description

Seeks to a playback position.
This function can be used when the AVPlayer is in the playing or paused state.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t mSecondsPosition to seek to, in ms.
AVPlayerSeekMode modeSeek mode.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player Seek fails.

OH_AVPlayer_GetCurrentTime()

OH_AVErrCode OH_AVPlayer_GetCurrentTime(OH_AVPlayer *player, int32_t *currentTime)

Description

Obtains the playback position, in milliseconds.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t *currentTimePointer to the playback position.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The playback position is obtained.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player GetCurrentTime fails.

OH_AVPlayer_GetVideoWidth()

OH_AVErrCode OH_AVPlayer_GetVideoWidth(OH_AVPlayer *player, int32_t *videoWidth)

Description

Obtains the video width.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t *videoWidthPointer to the video width.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The video width is obtained.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer.

OH_AVPlayer_GetVideoHeight()

OH_AVErrCode OH_AVPlayer_GetVideoHeight(OH_AVPlayer *player, int32_t *videoHeight)

Description

Obtains the video height.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t *videoHeightPointer to the video height.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The video height is obtained.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer.

OH_AVPlayer_SetPlaybackSpeed()

OH_AVErrCode OH_AVPlayer_SetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed speed)

Description

Sets the playback speed of the AVPlayer. For details about the playback speed, see AVPlaybackSpeed.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
AVPlaybackSpeed speedPlayback speed.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The playback speed is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer.

OH_AVPlayer_SetPlaybackRate()

OH_AVErrCode OH_AVPlayer_SetPlaybackRate(OH_AVPlayer *player, float rate)

Description

Sets the playback rate of an AVPlayer within the valid range.
The supported states are prepared, playing, paused, and completed.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 20

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
float ratePlayback rate. The value ranges from 0.125 to 4.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The playback speed is set successfully.
AV_ERR_OPERATE_NOT_PERMIT: The function is called when the AVPlayer is not in the allowed state, or it is called during live streaming.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or rate is out of range.

OH_AVPlayer_GetPlaybackSpeed()

OH_AVErrCode OH_AVPlayer_GetPlaybackSpeed(OH_AVPlayer *player, AVPlaybackSpeed *speed)

Description

Obtains the playback speed of an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
AVPlaybackSpeed *speedPointer to the playback speed.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The playback rate is obtained.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player GetPlaybackSpeed fails.

OH_AVPlayer_SetAudioRendererInfo()

OH_AVErrCode OH_AVPlayer_SetAudioRendererInfo(OH_AVPlayer *player, OH_AudioStream_Usage streamUsage)

Description

Sets the audio stream type for an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
OH_AudioStream_Usage streamUsageAudio stream type.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The audio stream type is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer or streamUsage is invalid.

OH_AVPlayer_SetVolumeMode()

OH_AVErrCode OH_AVPlayer_SetVolumeMode(OH_AVPlayer *player, OH_AudioStream_VolumeMode volumeMode)

Description

Sets the audio volume mode for an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 18

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
OH_AudioStream_VolumeMode volumeModeVolume mode of the audio stream.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The audio volume mode is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer or volumeMode is invalid.
AV_ERR_INVALID_STATE: The function is called in an invalid state. It must be in the prepared state.
AV_ERR_SERVICE_DIED: A system error occurs.

OH_AVPlayer_SetAudioInterruptMode()

OH_AVErrCode OH_AVPlayer_SetAudioInterruptMode(OH_AVPlayer *player, OH_AudioInterrupt_Mode interruptMode)

Description

Sets the audio interruption mode for an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
OH_AudioInterrupt_Mode interruptModeAudio interruption mode.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The audio interruption mode is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer or interruptMode is invalid.

OH_AVPlayer_SetAudioEffectMode()

OH_AVErrCode OH_AVPlayer_SetAudioEffectMode(OH_AVPlayer *player, OH_AudioStream_AudioEffectMode effectMode)

Description

Sets the audio effect mode for an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
OH_AudioStream_AudioEffectMode effectModeAudio effect mode.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The audio effect mode is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer or effectMode is invalid.

OH_AVPlayer_SelectBitRate()

OH_AVErrCode OH_AVPlayer_SelectBitRate(OH_AVPlayer *player, uint32_t bitRate)

Description

Sets the bit rate used by an HLS player. This function is valid only for HLS network streams.
By default, the AVPlayer 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. When ready, you can query the selected bit rate.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
uint32_t bitRateBit rate, in kbit/s.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The bit rate is set successfully.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player SelectBitRate fails.

OH_AVPlayer_SetVideoSurface()

OH_AVErrCode OH_AVPlayer_SetVideoSurface(OH_AVPlayer *player, OHNativeWindow *window)

Description

Sets a playback window.
This function must be called after SetSource and before Prepare.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
OHNativeWindow *windowPointer to the OHNativeWindow instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The playback window is set successfully.
AV_ERR_INVALID_VAL: The input parameter player or window is a null pointer, or the execution of player SetVideoSurface fails.

OH_AVPlayer_GetDuration()

OH_AVErrCode OH_AVPlayer_GetDuration(OH_AVPlayer *player, int32_t *duration)

Description

Obtains the total duration of a media file, in milliseconds.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t *durationPointer to the total duration.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The total duration is obtained.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player GetDuration fails.

OH_AVPlayer_GetState()

OH_AVErrCode OH_AVPlayer_GetState(OH_AVPlayer *player, AVPlayerState *state)

Description

Obtains the AVPlayer state.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
AVPlayerState *statePointer to the state of the AVPlayer.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The AVPlayer state is obtained.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player GetState fails.

OH_AVPlayer_IsPlaying()

bool OH_AVPlayer_IsPlaying(OH_AVPlayer *player)

Description

Checks whether an AVPlayer is playing.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
boolCheck result. The value true is returned if the AVPlayer is playing, and false is returned if the AVPlayer is not playing or the input parameter player is a null pointer.

OH_AVPlayer_IsLooping()

bool OH_AVPlayer_IsLooping(OH_AVPlayer *player)

Description

Checks whether an AVPlayer is looping.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.

Returns

TypeDescription
boolCheck result. The value true is returned if the AVPlayer is looping, and false is returned if the AVPlayer is not looping or the input parameter player is a null pointer.

OH_AVPlayer_SetLooping()

OH_AVErrCode OH_AVPlayer_SetLooping(OH_AVPlayer *player, bool loop)

Description

Enables loop playback.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
bool loopWhether to enable loop playback.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: Loop playback is enabled.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player SetLooping fails.

OH_AVPlayer_SetPlayerCallback()

OH_AVErrCode OH_AVPlayer_SetPlayerCallback(OH_AVPlayer *player, AVPlayerCallback callback)

Description

Sets an AVPlayer callback.
The callbacks OH_AVPlayerOnInfo and 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 and OH_AVPlayer_SetOnErrorCallback are provided to set the callbacks OH_AVPlayerOnInfoCallback and OH_AVPlayerOnErrorCallback, respectively.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
AVPlayerCallback callbackCallback used to return the result.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The callback is set successfully.
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.

OH_AVPlayer_SelectTrack()

OH_AVErrCode OH_AVPlayer_SelectTrack(OH_AVPlayer *player, int32_t index)

Description

Selects an audio or subtitle track.
By default, the first audio track with data is played, and the subtitle track is not played.
After the setting takes effect, the original track becomes invalid. Set the subtitle track to the prepared, playing, paused, or completed state, and set the audio track to the prepared state.

This function is not supported yet.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t indexIndex of the track.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player SelectTrack fails.

OH_AVPlayer_DeselectTrack()

OH_AVErrCode OH_AVPlayer_DeselectTrack(OH_AVPlayer *player, int32_t index)

Description

Deselects an audio or subtitle track.

This function is not supported yet.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t indexIndex of the track.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player DeselectTrack fails.

OH_AVPlayer_GetCurrentTrack()

OH_AVErrCode OH_AVPlayer_GetCurrentTrack(OH_AVPlayer *player, int32_t trackType, int32_t *index)

Description

Obtains the currently valid track. You can set the track to the prepared, playing, paused, or completed state.

This function is not supported yet.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 11

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
int32_t trackTypeMedia type. The value 0 means audio and 1 means video.
int32_t *indexPointer to the index of the track.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The track is obtained.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of player GetCurrentTrack fails.

OH_AVPlayer_SetMediaKeySystemInfoCallback()

OH_AVErrCode OH_AVPlayer_SetMediaKeySystemInfoCallback(OH_AVPlayer *player,Player_MediaKeySystemInfoCallback callback)

Description

Sets a callback to return the media key system information for an AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
Player_MediaKeySystemInfoCallback callbackCallback.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player or callback is a null pointer, or the execution of player SetDrmSystemInfoCallback
SetDrmSystemInfoCallback or SetDrmSystemInfoCallback fails.

OH_AVPlayer_GetMediaKeySystemInfo()

OH_AVErrCode OH_AVPlayer_GetMediaKeySystemInfo(OH_AVPlayer *player, DRM_MediaKeySystemInfo *mediaKeySystemInfo)

Description

Obtains the media key system information to create a media key session.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
DRM_MediaKeySystemInfo *mediaKeySystemInfoPointer to the media key system information.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the memory is insufficient.

OH_AVPlayer_SetDecryptionConfig()

OH_AVErrCode OH_AVPlayer_SetDecryptionConfig(OH_AVPlayer *player, MediaKeySession *mediaKeySession,bool secureVideoPath)

Description

Sets the decryption information.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
MediaKeySession *mediaKeySessionPointer to the media key session with the decryption feature.
bool secureVideoPathWhether a secure decoder is required.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer, or the execution of SetDecryptionConfig fails.

OH_AVPlayer_SetOnInfoCallback()

OH_AVErrCode OH_AVPlayer_SetOnInfoCallback(OH_AVPlayer *player, OH_AVPlayerOnInfoCallback callback, void *userData)

Description

Sets a callback for the event indicating that the AVPlayer receives a message.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
OH_AVPlayerOnInfoCallback callbackPointer to the callback. If a null pointer is passed in, the listening for AVPlayer messages is canceled.
void *userDataPointer to the instance set by the caller.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An error occurs during memory allocation.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer or the function fails to be executed.

OH_AVPlayer_SetOnErrorCallback()

OH_AVErrCode OH_AVPlayer_SetOnErrorCallback(OH_AVPlayer *player, OH_AVPlayerOnErrorCallback callback, void *userData)

Description

Sets a callback for the event indicating that an error occurs in the AVPlayer.

System capability: SystemCapability.Multimedia.Media.AVPlayer

Since: 12

Parameters

ParameterDescription
OH_AVPlayer *playerPointer to the OH_AVPlayer instance.
OH_AVPlayerOnErrorCallback callbackPointer to the callback. If a null pointer is passed in, the listening for AVPlayer errors is canceled.
void *userDataPointer to the instance set by the caller.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_NO_MEMORY: An error occurs during memory allocation.
AV_ERR_INVALID_VAL: The input parameter player is a null pointer or the function fails to be executed.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Media Kit

harmony 鸿蒙AVImageGenerator

harmony 鸿蒙AVMetadataExtractor

harmony 鸿蒙AVPlayer

harmony 鸿蒙AVPlayerCallback

harmony 鸿蒙AVRecorder

harmony 鸿蒙AVScreenCapture

harmony 鸿蒙OH_AVRecorder_Config

harmony 鸿蒙OH_AVRecorder_EncoderInfo

harmony 鸿蒙OH_AVRecorder_Location

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/f6HA2u