harmony 鸿蒙OHAVSession

2025-06-12 浏览 (1)

OHAVSession

Overview

The OHAVSession module defines the C APIs of the playback control module.

You can use OHAVSession to access AVSession as a provider. For details about the development guide and samples, see AVSession Provider.

System capability: SystemCapability.Multimedia.AVSession.Core

Since: 13

Summary

Files

NameDescription
native_avmetadata.hDeclares the definitions of playback control metadata.
native_avsession.hDeclares the AVSession definition, which can be used to set metadata, playback state, and other information.
native_avsession_errors.hDeclares the playback control error codes.

Structs

NameDescription
struct AVSession_PlaybackPositionDescribes the information related to the playback position.

Types

NameDescription
typedef struct OH_AVMetadataBuilderStruct OH_AVMetadataBuilderDefines a struct for the session metadata builder. The builder is used to construct session metadata.
typedef struct OH_AVMetadataStruct OH_AVMetadataDefines a struct for the session metadata. It is an AVMetadata instance set for a media asset.
typedef struct AVSession_PlaybackPosition AVSession_PlaybackPositionDefines a struct for the information related to the playback position.
typedef enum AVSession_ControlCommand AVSession_ControlCommandDefines an enum for the playback control commands.
typedef AVSessionCallback_Result(* OH_AVSessionCallback_OnCommand) (OH_AVSession *session, AVSession_ControlCommand command, void *userData)Defines a callback for a common playback control command.
typedef AVSessionCallback_Result(* OH_AVSessionCallback_OnFastForward) (OH_AVSession *session, uint32_t seekTime, void *userData)Defines a callback for the fast-forward operation.
typedef AVSessionCallback_Result(* OH_AVSessionCallback_OnRewind) (OH_AVSession *session, uint32_t seekTime, void *userData)Defines a callback for the rewind operation.
typedef AVSessionCallback_Result(* OH_AVSessionCallback_OnSeek) (OH_AVSession *session, uint64_t seekTime, void *userData)Defines a callback for the seek operation.
typedef AVSessionCallback_Result(* OH_AVSessionCallback_OnSetLoopMode) (OH_AVSession *session, AVSession_LoopMode curLoopMode, void *userData)Defines a callback for the operation of setting the loop mode.
typedef AVSessionCallback_Result(* OH_AVSessionCallback_OnToggleFavorite) (OH_AVSession *session, const char *assetId, void *userData)Defines a callback for the operation of favoriting a media asset.
typedef struct OH_AVSession OH_AVSessionDefines a struct for the playback control session object.

Enums

NameDescription
AVMetadata_Result {
AVMETADATA_SUCCESS = 0,
AVMETADATA_ERROR_INVALID_PARAM = 1,
AVMETADATA_ERROR_NO_MEMORY = 2 }
Enumerates the error codes related to metadata operations.
AVMetadata_SkipIntervals {
SECONDS_10 = 10,
SECONDS_15 = 15,
SECONDS_30 = 30 }
Enumerates the fast-forward or rewind intervals supported by the media session.
AVMetadata_DisplayTag { AVSESSION_DISPLAYTAG_AUDIO_VIVID = 1 }Enumerates the display tags of the media asset. The display tag is a special type identifier of the media audio source.
AVSession_Type {
SESSION_TYPE_AUDIO = 0,
SESSION_TYPE_VIDEO = 1,
SESSION_TYPE_VOICE_CALL = 2,
SESSION_TYPE_VIDEO_CALL = 3 }
Enumerates the session types.
AVSession_PlaybackState {
PLAYBACK_STATE_INITIAL = 0,
PLAYBACK_STATE_PREPARING = 1,
PLAYBACK_STATE_PLAYING = 2,
PLAYBACK_STATE_PAUSED = 3,
PLAYBACK_STATE_FAST_FORWARDING = 4,
PLAYBACK_STATE_REWINDED = 5,
PLAYBACK_STATE_STOPPED = 6,
PLAYBACK_STATE_COMPLETED = 7,
PLAYBACK_STATE_RELEASED = 8,
PLAYBACK_STATE_ERROR = 9,
PLAYBACK_STATE_IDLE = 10,
PLAYBACK_STATE_BUFFERING = 11,
PLAYBACK_STATE_MAX = 12
}
Enumerates the media playback states.
AVSession_LoopMode {
LOOP_MODE_SEQUENCE = 0,
LOOP_MODE_SINGLE = 1,
LOOP_MODE_LIST = 2,
LOOP_MODE_SHUFFLE = 3,
LOOP_MODE_CUSTOM = 4
}
Enumerates the loop modes of media playback.
AVSession_ControlCommand {
CONTROL_CMD_INVALID = -1,
CONTROL_CMD_PLAY = 0,
CONTROL_CMD_PAUSE = 1,
CONTROL_CMD_STOP = 2,
CONTROL_CMD_PLAY_NEXT = 3,
CONTROL_CMD_PLAY_PREVIOUS = 4
}
Enumerates the playback control commands.
AVSessionCallback_Result {
AVSESSION_CALLBACK_RESULT_SUCCESS = 0,
AVSESSION_CALLBACK_RESULT_FAILURE = -1 }
Enumerates the callback execution results.
AVSession_ErrCode {
AV_SESSION_ERR_SUCCESS = 0,
AV_SESSION_ERR_INVALID_PARAMETER = 401,
AV_SESSION_ERR_SERVICE_EXCEPTION = 6600101,
AV_SESSION_ERR_CODE_SESSION_NOT_EXIST = 6600102,
AV_SESSION_ERR_CODE_COMMAND_INVALID = 6600105,
AV_SESSION_ERR_CODE_SESSION_INACTIVE = 6600106,
AV_SESSION_ERR_CODE_MESSAGE_OVERLOAD = 6600107
}
Enumerates the playback control error codes.

Functions

NameDescription
AVMetadata_Result OH_AVMetadataBuilder_Create (OH_AVMetadataBuilder **builder)Creates a metadata builder.
AVMetadata_Result OH_AVMetadataBuilder_Destroy (OH_AVMetadataBuilder *builder)Destroys a metadata builder.
AVMetadata_Result OH_AVMetadataBuilder_SetAssetId (OH_AVMetadataBuilder *builder, const char *assetId)Sets the ID of the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetTitle (OH_AVMetadataBuilder *builder, const char *title)Sets a title for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetArtist (OH_AVMetadataBuilder *builder, const char *artist)Sets an artist for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetAuthor (OH_AVMetadataBuilder *builder, const char *author)Sets an author for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetAlbum (OH_AVMetadataBuilder *builder, const char *album)Sets an album name for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetWriter (OH_AVMetadataBuilder *builder, const char *writer)Sets a writer for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetComposer (OH_AVMetadataBuilder *builder, const char *composer)Sets a composer for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetDuration (OH_AVMetadataBuilder *builder, int64_t duration)Sets the playback duration for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetMediaImageUri (OH_AVMetadataBuilder *builder, const char *mediaImageUri)Sets an image for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetSubtitle (OH_AVMetadataBuilder *builder, const char *subtitle)Sets a subtitle for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetDescription (OH_AVMetadataBuilder *builder, const char *description)Sets a description for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetLyric (OH_AVMetadataBuilder *builder, const char *lyric)Sets lyrics for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetSkipIntervals (OH_AVMetadataBuilder *builder, AVMetadata_SkipIntervals intervals)Sets the skip intervals for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_SetDisplayTags (OH_AVMetadataBuilder *builder, int32_t tags)Sets display tags for the media asset.
AVMetadata_Result OH_AVMetadataBuilder_GenerateAVMetadata (OH_AVMetadataBuilder *builder, OH_AVMetadata **avMetadata)Generates an OH_AVMetadata object.
AVMetadata_Result OH_AVMetadata_Destroy (OH_AVMetadata *avMetadata)Releases an OH_AVMetadata object.
AVSession_ErrCode OH_AVSession_Create (AVSession_Type sessionType, const char *sessionTag, const char *bundleName, const char *abilityName, OH_AVSession **avsession)Creates a session object.
AVSession_ErrCode OH_AVSession_Destroy (OH_AVSession *avsession)Destroys a session object.
AVSession_ErrCode OH_AVSession_Activate (OH_AVSession *avsession)Activates a session.
AVSession_ErrCode OH_AVSession_Deactivate (OH_AVSession *avsession)Deactivates a session.
AVSession_ErrCode OH_AVSession_GetSessionType (OH_AVSession *avsession, AVSession_Type *sessionType)Obtains the session type.
AVSession_ErrCode OH_AVSession_GetSessionId (OH_AVSession *avsession, const char **sessionId)Obtains the session ID.
AVSession_ErrCode OH_AVSession_SetAVMetadata (OH_AVSession *avsession, OH_AVMetadata *avmetadata)Sets media metadata.
AVSession_ErrCode OH_AVSession_SetPlaybackState (OH_AVSession *avsession, AVSession_PlaybackState playbackState)Sets the playback state.
AVSession_ErrCode OH_AVSession_SetPlaybackPosition (OH_AVSession *avsession, AVSession_PlaybackPosition *playbackPosition)Sets the playback position.
AVSession_ErrCode OH_AVSession_SetFavorite (OH_AVSession *avsession, bool favorite)Favorites or unfavorites the media asset.
AVSession_ErrCode OH_AVSession_SetLoopMode (OH_AVSession *avsession, AVSession_LoopMode loopMode)Sets a loop mode.
AVSession_ErrCode OH_AVSession_RegisterCommandCallback (OH_AVSession *avsession, AVSession_ControlCommand command, OH_AVSessionCallback_OnCommand callback, void *userData)Registers a callback for a common playback control command.
AVSession_ErrCode OH_AVSession_UnregisterCommandCallback (OH_AVSession *avsession, AVSession_ControlCommand command, OH_AVSessionCallback_OnCommand callback)Unregisters the callback for a common playback control command.
AVSession_ErrCode OH_AVSession_RegisterForwardCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnFastForward callback, void *userData)Registers a callback for the fast-forward operation.
AVSession_ErrCode OH_AVSession_UnregisterForwardCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnFastForward callback)Unregisters the callback for the fast-forward operation.
AVSession_ErrCode OH_AVSession_RegisterRewindCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnRewind callback, void *userData)Registers a callback for the rewind operation.
AVSession_ErrCode OH_AVSession_UnregisterRewindCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnRewind callback)Unregisters the callback for the rewind operation.
AVSession_ErrCode OH_AVSession_RegisterSeekCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnSeek callback, void *userData)Registers a callback for the seek operation.
AVSession_ErrCode OH_AVSession_UnregisterSeekCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnSeek callback)Unregisters the callback for the seek operation.
AVSession_ErrCode OH_AVSession_RegisterSetLoopModeCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnSetLoopMode callback, void *userData)Registers a callback for the operation of setting the loop mode.
AVSession_ErrCode OH_AVSession_UnregisterSetLoopModeCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnSetLoopMode callback)Unregisters the callback for the operation of setting the loop mode.
AVSession_ErrCode OH_AVSession_RegisterToggleFavoriteCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnToggleFavorite callback, void *userData)Registers a callback for the operation of favoriting a media asset.
AVSession_ErrCode OH_AVSession_UnregisterToggleFavoriteCallback (OH_AVSession *avsession, OH_AVSessionCallback_OnToggleFavorite callback)Unregisters the callback for the operation of favoriting a media asset.

Type Description

AVSession_ControlCommand

typedef enum AVSession_ControlCommand AVSession_ControlCommand

Description

Defines an enum for the playback control commands.

Since: 13

AVSession_PlaybackPosition

typedef struct AVSession_PlaybackPosition AVSession_PlaybackPosition

Description

Defines a struct for the information related to the playback position.

Since: 13

OH_AVMetadata

typedef struct OH_AVMetadataStruct OH_AVMetadata

Description

Defines a struct for the session metadata. It is an AVMetadata instance set for a media asset.

Since: 13

OH_AVMetadataBuilder

typedef struct OH_AVMetadataBuilderStruct OH_AVMetadataBuilder

Description

Defines a struct for the session metadata builder. The builder is used to construct session metadata.

Since: 13

OH_AVSession

typedef struct OH_AVSession OH_AVSession

Description

Defines a struct for the playback control session object.

You can use OH_AVSession_Create to create such an object.

Since: 13

OH_AVSessionCallback_OnCommand

typedef AVSessionCallback_Result (*OH_AVSessionCallback_OnCommand)(OH_AVSession* session, AVSession_ControlCommand command, void* userData)

Description

Defines a callback for a common playback control command.

Since: 13

OH_AVSessionCallback_OnFastForward

typedef AVSessionCallback_Result (*OH_AVSessionCallback_OnFastForward)(OH_AVSession* session, uint32_t seekTime, void* userData)

Description

Defines a callback for the fast-forward operation.

Since: 13

OH_AVSessionCallback_OnRewind

typedef AVSessionCallback_Result (*OH_AVSessionCallback_OnRewind)(OH_AVSession* session, uint32_t seekTime, void* userData)

Description

Defines a callback for the rewind operation.

Since: 13

OH_AVSessionCallback_OnSeek

typedef AVSessionCallback_Result (*OH_AVSessionCallback_OnSeek)(OH_AVSession* session, uint64_t seekTime, void* userData)

Description

Defines a callback for the seek operation.

Since: 13

OH_AVSessionCallback_OnSetLoopMode

typedef AVSessionCallback_Result (*OH_AVSessionCallback_OnSetLoopMode)(OH_AVSession* session, AVSession_LoopMode curLoopMode, void* userData)

Description

Defines a callback for the operation of setting the loop mode.

Since: 13

OH_AVSessionCallback_OnToggleFavorite

typedef AVSessionCallback_Result (*OH_AVSessionCallback_OnToggleFavorite)(OH_AVSession* session, const char* assetId, void* userData)

Description

Defines a callback for the operation of favoriting a media asset.

Since: 13

Enums

AVMetadata_DisplayTag

enum AVMetadata_DisplayTag

Description

Enumerates the display tags of the media asset. The display tag is a special type identifier of the media audio source.

Since: 13

ValueDescription
AVSESSION_DISPLAYTAG_AUDIO_VIVIDAUDIO VIVID.

AVMetadata_Result

enum AVMetadata_Result

Description

Enumerates the error codes related to metadata operations.

Since: 13

ValueDescription
AVMETADATA_SUCCESSOperation successful.
AVMETADATA_ERROR_INVALID_PARAMIncorrect parameter.
AVMETADATA_ERROR_NO_MEMORYInsufficient memory.

AVMetadata_SkipIntervals

enum AVMetadata_SkipIntervals

Description

Enumerates the fast-forward or rewind intervals supported by the media session.

Since: 13

ValueDescription
SECONDS_10The time is 10 seconds.
SECONDS_15The time is 15 seconds.
SECONDS_30The time is 30 seconds.

AVSession_ControlCommand

enum AVSession_ControlCommand

Description

Enumerates the playback control commands.

Since: 13

ValueDescription
CONTROL_CMD_INVALIDInvalid control command.
CONTROL_CMD_PLAYPlay command.
CONTROL_CMD_PAUSEPause command.
CONTROL_CMD_STOPStop command.
CONTROL_CMD_PLAY_NEXTCommand for playing the next media asset.
CONTROL_CMD_PLAY_PREVIOUSCommand for playing the previous media asset.

AVSession_ErrCode

enum AVSession_ErrCode

Description

Enumerates the playback control error codes.

Since: 13

ValueDescription
AV_SESSION_ERR_SUCCESSThe operation is successful.
AV_SESSION_ERR_INVALID_PARAMETERParameter check fails.
AV_SESSION_ERR_SERVICE_EXCEPTIONThe session server is abnormal.
AV_SESSION_ERR_CODE_SESSION_NOT_EXISTThe session does not exist.
AV_SESSION_ERR_CODE_COMMAND_INVALIDThe session command is invalid.
AV_SESSION_ERR_CODE_SESSION_INACTIVEThe session is not activated.
AV_SESSION_ERR_CODE_MESSAGE_OVERLOADCommand and message overflow.

AVSession_LoopMode

enum AVSession_LoopMode

Description

Enumerates the loop modes of media playback.

Since: 13

ValueDescription
LOOP_MODE_SEQUENCESequential playback.
LOOP_MODE_SINGLESingle loop.
LOOP_MODE_LISTPlaylist loop.
LOOP_MODE_SHUFFLEShuffle.
LOOP_MODE_CUSTOMCustom playback.

AVSession_PlaybackState

enum AVSession_PlaybackState

Description

Enumerates the media playback states.

Since: 13

ValueDescription
PLAYBACK_STATE_INITIALInitial state.
PLAYBACK_STATE_PREPARINGReady.
PLAYBACK_STATE_PLAYINGPlaying.
PLAYBACK_STATE_PAUSEDPaused.
PLAYBACK_STATE_FAST_FORWARDINGFast-forwarding.
PLAYBACK_STATE_REWINDEDRewinded.
PLAYBACK_STATE_STOPPEDStopped.
PLAYBACK_STATE_COMPLETEDPlayback complete.
PLAYBACK_STATE_RELEASEDReleased.
PLAYBACK_STATE_ERRORError.
PLAYBACK_STATE_IDLEIdle.
PLAYBACK_STATE_BUFFERINGBuffering.
PLAYBACK_STATE_MAXMaximum value. (Error code 401 is returned in this case.)

AVSession_Type

enum AVSession_Type

Description

Enumerates the session types.

Since: 13

ValueDescription
SESSION_TYPE_AUDIOAudio.
SESSION_TYPE_VIDEOVideo.
SESSION_TYPE_VOICE_CALLAudio call.
SESSION_TYPE_VIDEO_CALLVideo call.

AVSessionCallback_Result

enum AVSessionCallback_Result

Description

Enumerates the callback execution results.

Since: 13

ValueDescription
AVSESSION_CALLBACK_RESULT_SUCCESSThe operation is successful.
AVSESSION_CALLBACK_RESULT_FAILUREThe operation fails.

Function Description

OH_AVMetadata_Destroy()

AVMetadata_Result OH_AVMetadata_Destroy(OH_AVMetadata* avMetadata)

Description

Releases an OH_AVMetadata object.

Since: 13

Parameters

NameDescription
avMetadataPointer to an OH_AVMetadata object.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM: avMetadata is a null pointer.

OH_AVMetadataBuilder_Create()

AVMetadata_Result OH_AVMetadataBuilder_Create(OH_AVMetadataBuilder** builder)

Description

Creates a metadata builder.

Since: 13

Parameters

NameDescription
builderDouble pointer to the builder created.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM: builder is a null pointer.

AVMETADATA_ERROR_NO_MEMORY: There is no sufficient memory.

OH_AVMetadataBuilder_Destroy()

AVMetadata_Result OH_AVMetadataBuilder_Destroy(OH_AVMetadataBuilder* builder)

Description

Destroys a metadata builder.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM: builder is a null pointer.

OH_AVMetadataBuilder_GenerateAVMetadata()

AVMetadata_Result OH_AVMetadataBuilder_GenerateAVMetadata(OH_AVMetadataBuilder* builder, OH_AVMetadata** avMetadata)

Description

Generates an OH_AVMetadata object.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
avMetadataDouble pointer to the OH_AVMetadata object created.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_NO_MEMORY: The memory is insufficient.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. avMetadata is a null pointer.

OH_AVMetadataBuilder_SetAlbum()

AVMetadata_Result OH_AVMetadataBuilder_SetAlbum(OH_AVMetadataBuilder* builder, const char* album)

Description

Sets an album name for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
albumPointer to the album name.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. album is a null pointer.

OH_AVMetadataBuilder_SetArtist()

AVMetadata_Result OH_AVMetadataBuilder_SetArtist(OH_AVMetadataBuilder* builder, const char* artist)

Description

Sets an artist for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
artistPointer to the artist.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. artist is a null pointer.

OH_AVMetadataBuilder_SetAssetId()

AVMetadata_Result OH_AVMetadataBuilder_SetAssetId(OH_AVMetadataBuilder* builder, const char* assetId)

Description

Sets the ID of the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
assetIdPointer to the asset ID.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. assetId is a null pointer.

OH_AVMetadataBuilder_SetAuthor()

AVMetadata_Result OH_AVMetadataBuilder_SetAuthor(OH_AVMetadataBuilder* builder, const char* author)

Description

Sets an author for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
authorPointer to the author.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. author is a null pointer.

OH_AVMetadataBuilder_SetComposer()

AVMetadata_Result OH_AVMetadataBuilder_SetComposer(OH_AVMetadataBuilder* builder, const char* composer)

Description

Sets a composer for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
composerPointer to the composer.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. composer is a null pointer.

OH_AVMetadataBuilder_SetDescription()

AVMetadata_Result OH_AVMetadataBuilder_SetDescription(OH_AVMetadataBuilder* builder, const char* description)

Description

Sets a description for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
descriptionPointer to the description.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. description is a null pointer.

OH_AVMetadataBuilder_SetDisplayTags()

AVMetadata_Result OH_AVMetadataBuilder_SetDisplayTags(OH_AVMetadataBuilder* builder, int32_t tags)

Description

Sets display tags for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
tagsTags of the media asset displayed on the playback control page.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM: builder is a null pointer.

OH_AVMetadataBuilder_SetDuration()

AVMetadata_Result OH_AVMetadataBuilder_SetDuration(OH_AVMetadataBuilder* builder, int64_t duration)

Description

Sets the playback duration for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
durationPlayback duration, in ms.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM: builder is a null pointer.

OH_AVMetadataBuilder_SetLyric()

AVMetadata_Result OH_AVMetadataBuilder_SetLyric(OH_AVMetadataBuilder* builder, const char* lyric)

Description

Sets lyrics for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
lyricPointer to the lyrics in the lrc format.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. lyric is a null pointer.

OH_AVMetadataBuilder_SetMediaImageUri()

AVMetadata_Result OH_AVMetadataBuilder_SetMediaImageUri(OH_AVMetadataBuilder* builder, const char* mediaImageUri)

Description

Sets an image for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
mediaImageUriPointer to the URI of the image.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. mediaImageUri is a null pointer.

OH_AVMetadataBuilder_SetSkipIntervals()

AVMetadata_Result OH_AVMetadataBuilder_SetSkipIntervals(OH_AVMetadataBuilder* builder, AVMetadata_SkipIntervals intervals)

Description

Sets the skip intervals for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
intervalsSkip intervals.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. intervals is invalid.

OH_AVMetadataBuilder_SetSubtitle()

AVMetadata_Result OH_AVMetadataBuilder_SetSubtitle(OH_AVMetadataBuilder* builder, const char* subtitle)

Description

Sets a subtitle for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
subtitlePointer to the subtitle.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. subtitle is a null pointer.

OH_AVMetadataBuilder_SetTitle()

AVMetadata_Result OH_AVMetadataBuilder_SetTitle(OH_AVMetadataBuilder* builder, const char* title)

Description

Sets a title for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
titlePointer to the title.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. title is a null pointer.

OH_AVMetadataBuilder_SetWriter()

AVMetadata_Result OH_AVMetadataBuilder_SetWriter(OH_AVMetadataBuilder* builder, const char* writer)

Description

Sets a writer for the media asset.

Since: 13

Parameters

NameDescription
builderPointer to an OH_AVMetadataBuilder instance.
writerPointer to the writer.

Returns

Returns one of the following result codes defined in AVMetadata_Result:

AVMETADATA_SUCCESS: The function is executed successfully.

AVMETADATA_ERROR_INVALID_PARAM:

  1. builder is a null pointer.

  2. writer is a null pointer.

OH_AVSession_Activate()

AVSession_ErrCode OH_AVSession_Activate(OH_AVSession* avsession)

Description

Activates a session.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_INVALID_PARAMETER: avsession is a null pointer.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

OH_AVSession_Create()

AVSession_ErrCode OH_AVSession_Create(AVSession_Type sessionType, const char* sessionTag, const char* bundleName, const char* abilityName, OH_AVSession** avsession)

Description

Creates a session object.

Since: 13

Parameters

NameDescription
sessionTypeSession type. For details about the available options, see AVSession_Type.
sessionTagPointer to the session tag.
bundleNamePointer to the bundle name.
abilityNamePointer to the ability name.
avsessionDouble pointer to the session object created.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

link AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal or the session object already exists.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. sessionType is invalid.

  2. sessionTag is a null pointer.

  3. bundleName is a null pointer.

  4. abilityName is a null pointer.

  5. avsession is a null pointer.

OH_AVSession_Deactivate()

AVSession_ErrCode OH_AVSession_Deactivate(OH_AVSession* avsession)

Description

Deactivates a session.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_INVALID_PARAMETER: avsession is a null pointer.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

OH_AVSession_Destroy()

AVSession_ErrCode OH_AVSession_Destroy(OH_AVSession* avsession)

Description

Destroys a session object.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_INVALID_PARAMETER: avsession is a null pointer.

OH_AVSession_GetSessionId()

AVSession_ErrCode OH_AVSession_GetSessionId(OH_AVSession* avsession, const char** sessionId)

Description

Obtains the session ID.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
sessionIdDouble pointer to the session ID obtained.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal or an error occurs.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. sessionId is a null pointer.

OH_AVSession_GetSessionType()

AVSession_ErrCode OH_AVSession_GetSessionType(OH_AVSession* avsession, AVSession_Type* sessionType)

Description

Obtains the session type.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
sessionTypePointer to the session type obtained.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal or an error occurs.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. sessionType is a null pointer.

OH_AVSession_RegisterCommandCallback()

AVSession_ErrCode OH_AVSession_RegisterCommandCallback(OH_AVSession* avsession, AVSession_ControlCommand command, OH_AVSessionCallback_OnCommand callback, void* userData)

Description

Registers a callback for a common playback control command.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
commandPlayback control command.
callbackCallback to register, which is OH_AVSessionCallback_OnCommand.
userDataPointer to the application data passed through the callback functions.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_CODE_COMMAND_INVALID: The playback control command is invalid.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_RegisterForwardCallback()

AVSession_ErrCode OH_AVSession_RegisterForwardCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnFastForward callback, void* userData)

Description

Registers a callback for the fast-forward operation.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to register, which issue OH_AVSessionCallback_OnFastForward.
userDataPointer to the application data passed through the callback functions.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_RegisterRewindCallback()

AVSession_ErrCode OH_AVSession_RegisterRewindCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnRewind callback, void* userData)

Description

Registers a callback for the rewind operation.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to register, which is OH_AVSessionCallback_OnRewind.
userDataPointer to the application data passed through the callback functions.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_RegisterSeekCallback()

AVSession_ErrCode OH_AVSession_RegisterSeekCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnSeek callback, void* userData)

Description

Registers a callback for the seek operation.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to register, which is OH_AVSessionCallback_OnSeek.
userDataPointer to the application data passed through the callback functions.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_RegisterSetLoopModeCallback()

AVSession_ErrCode OH_AVSession_RegisterSetLoopModeCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnSetLoopMode callback, void* userData)

Description

Registers a callback for the operation of setting the loop mode.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to register, which is OH_AVSessionCallback_OnSetLoopMode.
userDataPointer to the application data passed through the callback functions.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_RegisterToggleFavoriteCallback()

AVSession_ErrCode OH_AVSession_RegisterToggleFavoriteCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnToggleFavorite callback, void* userData)

Description

Registers a callback for the operation of favoriting a media asset.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to register, which is OH_AVSessionCallback_OnToggleFavorite.
userDataPointer to the application data passed through the callback functions.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_SetAVMetadata()

AVSession_ErrCode OH_AVSession_SetAVMetadata(OH_AVSession* avsession, OH_AVMetadata* avmetadata)

Description

Sets media metadata.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
avmetadataPointer to the media metadata.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. avmetadata is a null pointer.

OH_AVSession_SetFavorite()

AVSession_ErrCode OH_AVSession_SetFavorite(OH_AVSession* avsession, bool favorite)

Description

Favorites or unfavorites the media asset.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
favoriteWhether to favorite or unfavorite the media asset. The value true means to favorite the media asset, and false means the opposite.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER: avsession is a null pointer.

OH_AVSession_SetLoopMode()

AVSession_ErrCode OH_AVSession_SetLoopMode(OH_AVSession* avsession, AVSession_LoopMode loopMode)

Description

Sets a loop mode.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
loopModeLoop mode.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. loopMode is invalid.

OH_AVSession_SetPlaybackPosition()

AVSession_ErrCode OH_AVSession_SetPlaybackPosition(OH_AVSession* avsession, AVSession_PlaybackPosition* playbackPosition)

Description

Sets the playback position.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
playbackPositionPointer to the playback position.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. playbackPosition is a null pointer.

OH_AVSession_SetPlaybackState()

AVSession_ErrCode OH_AVSession_SetPlaybackState(OH_AVSession* avsession, AVSession_PlaybackState playbackState)

Description

Sets the playback state.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
playbackStatePlayback state.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. playbackState is invalid.

OH_AVSession_UnregisterCommandCallback()

AVSession_ErrCode OH_AVSession_UnregisterCommandCallback(OH_AVSession* avsession, AVSession_ControlCommand command, OH_AVSessionCallback_OnCommand callback)

Description

Unregisters the callback for a common playback control command.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
commandPlayback control command.
callbackCallback to unregister, which is OH_AVSessionCallback_OnCommand.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_CODE_COMMAND_INVALID: The playback control command is invalid.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_UnregisterForwardCallback()

AVSession_ErrCode OH_AVSession_UnregisterForwardCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnFastForward callback)

Description

Unregisters the callback for the fast-forward operation.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to unregister, which issue OH_AVSessionCallback_OnFastForward.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_UnregisterRewindCallback()

AVSession_ErrCode OH_AVSession_UnregisterRewindCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnRewind callback)

Description

Unregisters the callback for the rewind operation.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to unregister, which is OH_AVSessionCallback_OnRewind.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_UnregisterSeekCallback()

AVSession_ErrCode OH_AVSession_UnregisterSeekCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnSeek callback)

Description

Unregisters the callback for the seek operation.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to unregister, which is OH_AVSessionCallback_OnSeek.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_UnregisterSetLoopModeCallback()

AVSession_ErrCode OH_AVSession_UnregisterSetLoopModeCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnSetLoopMode callback)

Description

Unregisters the callback for the operation of setting the loop mode.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to unregister, which is OH_AVSessionCallback_OnSetLoopMode.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

OH_AVSession_UnregisterToggleFavoriteCallback()

AVSession_ErrCode OH_AVSession_UnregisterToggleFavoriteCallback(OH_AVSession* avsession, OH_AVSessionCallback_OnToggleFavorite callback)

Description

Unregisters the callback for the operation of favoriting a media asset.

Since: 13

Parameters

NameDescription
avsessionPointer to a session object.
callbackCallback to unregister, which is OH_AVSessionCallback_OnToggleFavorite.

Returns

Returns one of the following result codes defined in AVSession_ErrCode:

AV_SESSION_ERR_SUCCESS: The function is executed successfully.

AV_SESSION_ERR_SERVICE_EXCEPTION: The session service is abnormal.

AV_SESSION_ERR_INVALID_PARAMETER:

  1. avsession is a null pointer.

  2. callback is a null pointer.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙AVSession Kit

harmony 鸿蒙AVSession_PlaybackPosition

harmony 鸿蒙AVSession Management Error Codes

harmony 鸿蒙@ohos.app.ability.MediaControlExtensionAbility (ExtensionAbility for Media Playback Control) (System API)

harmony 鸿蒙@ohos.multimedia.avCastPickerParam (AVCastPicker Parameters)

harmony 鸿蒙@ohos.multimedia.avsession (AVSession Management) (System API)

harmony 鸿蒙js-apis-avsession

harmony 鸿蒙MediaControlExtensionContext (ExtensionAbility Context for Media Playback Control) (System API)

harmony 鸿蒙native_avmetadata.h

harmony 鸿蒙native_avsession.h

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