harmony 鸿蒙avplayer.h
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:
Library: libavplayer.so
System capability: SystemCapability.Multimedia.Media.AVPlayer
Since: 11
Related module: AVPlayer
Summary
Structs
|Name|typedef Keyword|Description| |–|–|–| |MediaKeySession|MediaKeySession|Describes the media key session.| |DRM_MediaKeySystemInfo|DRM_MediaKeySystemInfo|Describes the media key system information.|
Functions
|Name|typedef Keyword|Description|
|–|–|–|
|typedef void (*Player_MediaKeySystemInfoCallback)(OH_AVPlayer *player, DRM_MediaKeySystemInfo* mediaKeySystemInfo)|Player_MediaKeySystemInfoCallback|Called 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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |DRM_MediaKeySystemInfo* mediaKeySystemInfo|Pointer 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
|Type|Description|
|–|–|
|OH_AVPlayer|Pointer 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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |const char *url|URL of the media source.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t fd|File descriptor of the media source.| |int64_t offset|Offset of the media source in the file descriptor.| |int64_t size|Size of the media source.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |float leftVolume|Target volume of the left channel.| |float rightVolume|Target volume of the right channel.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t mSeconds|Position to seek to, in ms.| |AVPlayerSeekMode mode|Seek mode.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t *currentTime|Pointer to the playback position.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t *videoWidth|Pointer to the video width.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t *videoHeight|Pointer to the video height.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |AVPlaybackSpeed speed|Playback speed.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |float rate|Playback rate. The value ranges from 0.125 to 4.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |AVPlaybackSpeed *speed|Pointer to the playback speed.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |OH_AudioStream_Usage streamUsage|Audio stream type.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |OH_AudioStream_VolumeMode volumeMode|Volume mode of the audio stream.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |OH_AudioInterrupt_Mode interruptMode|Audio interruption mode.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |OH_AudioStream_AudioEffectMode effectMode|Audio effect mode.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |uint32_t bitRate|Bit rate, in kbit/s.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |OHNativeWindow *window|Pointer to the OHNativeWindow instance.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t *duration|Pointer to the total duration.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |AVPlayerState *state|Pointer to the state of the AVPlayer.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description| |–|–| |bool|Check 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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.|
Returns
|Type|Description| |–|–| |bool|Check 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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |bool loop|Whether to enable loop playback.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |AVPlayerCallback callback|Callback used to return the result.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t index|Index of the track.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t index|Index of the track.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |int32_t trackType|Media type. The value 0 means audio and 1 means video.| |int32_t *index|Pointer to the index of the track.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |Player_MediaKeySystemInfoCallback callback|Callback.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |DRM_MediaKeySystemInfo *mediaKeySystemInfo|Pointer to the media key system information.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |MediaKeySession *mediaKeySession|Pointer to the media key session with the decryption feature.| |bool secureVideoPath|Whether a secure decoder is required.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |OH_AVPlayerOnInfoCallback callback|Pointer to the callback. If a null pointer is passed in, the listening for AVPlayer messages is canceled.| |void *userData|Pointer to the instance set by the caller.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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
|Parameter|Description| |–|–| |OH_AVPlayer *player|Pointer to the OH_AVPlayer instance.| |OH_AVPlayerOnErrorCallback callback|Pointer to the callback. If a null pointer is passed in, the listening for AVPlayer errors is canceled.| |void *userData|Pointer to the instance set by the caller.|
Returns
|Type|Description|
|–|–|
|OH_AVErrCode|AV_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 鸿蒙OH_AVRecorder_Config
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦