harmony 鸿蒙OHAVSession

  • 2025-06-12
  • 浏览 (5)

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

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

Structs

Name Description
struct AVSession_PlaybackPosition Describes the information related to the playback position.

Types

Name Description
typedef struct OH_AVMetadataBuilderStruct OH_AVMetadataBuilder Defines a struct for the session metadata builder. The builder is used to construct session metadata.
typedef struct OH_AVMetadataStruct OH_AVMetadata Defines a struct for the session metadata. It is an AVMetadata instance set for a media asset.
typedef struct AVSession_PlaybackPosition AVSession_PlaybackPosition Defines a struct for the information related to the playback position.
typedef enum AVSession_ControlCommand AVSession_ControlCommand Defines 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_AVSession Defines a struct for the playback control session object.

Enums

Name Description
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

Name Description
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

Value Description
AVSESSION_DISPLAYTAG_AUDIO_VIVID AUDIO VIVID.

AVMetadata_Result

enum AVMetadata_Result

Description

Enumerates the error codes related to metadata operations.

Since: 13

Value Description
AVMETADATA_SUCCESS Operation successful.
AVMETADATA_ERROR_INVALID_PARAM Incorrect parameter.
AVMETADATA_ERROR_NO_MEMORY Insufficient memory.

AVMetadata_SkipIntervals

enum AVMetadata_SkipIntervals

Description

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

Since: 13

Value Description
SECONDS_10 The time is 10 seconds.
SECONDS_15 The time is 15 seconds.
SECONDS_30 The time is 30 seconds.

AVSession_ControlCommand

enum AVSession_ControlCommand

Description

Enumerates the playback control commands.

Since: 13

Value Description
CONTROL_CMD_INVALID Invalid control command.
CONTROL_CMD_PLAY Play command.
CONTROL_CMD_PAUSE Pause command.
CONTROL_CMD_STOP Stop command.
CONTROL_CMD_PLAY_NEXT Command for playing the next media asset.
CONTROL_CMD_PLAY_PREVIOUS Command for playing the previous media asset.

AVSession_ErrCode

enum AVSession_ErrCode

Description

Enumerates the playback control error codes.

Since: 13

Value Description
AV_SESSION_ERR_SUCCESS The operation is successful.
AV_SESSION_ERR_INVALID_PARAMETER Parameter check fails.
AV_SESSION_ERR_SERVICE_EXCEPTION The session server is abnormal.
AV_SESSION_ERR_CODE_SESSION_NOT_EXIST The session does not exist.
AV_SESSION_ERR_CODE_COMMAND_INVALID The session command is invalid.
AV_SESSION_ERR_CODE_SESSION_INACTIVE The session is not activated.
AV_SESSION_ERR_CODE_MESSAGE_OVERLOAD Command and message overflow.

AVSession_LoopMode

enum AVSession_LoopMode

Description

Enumerates the loop modes of media playback.

Since: 13

Value Description
LOOP_MODE_SEQUENCE Sequential playback.
LOOP_MODE_SINGLE Single loop.
LOOP_MODE_LIST Playlist loop.
LOOP_MODE_SHUFFLE Shuffle.
LOOP_MODE_CUSTOM Custom playback.

AVSession_PlaybackState

enum AVSession_PlaybackState

Description

Enumerates the media playback states.

Since: 13

Value Description
PLAYBACK_STATE_INITIAL Initial state.
PLAYBACK_STATE_PREPARING Ready.
PLAYBACK_STATE_PLAYING Playing.
PLAYBACK_STATE_PAUSED Paused.
PLAYBACK_STATE_FAST_FORWARDING Fast-forwarding.
PLAYBACK_STATE_REWINDED Rewinded.
PLAYBACK_STATE_STOPPED Stopped.
PLAYBACK_STATE_COMPLETED Playback complete.
PLAYBACK_STATE_RELEASED Released.
PLAYBACK_STATE_ERROR Error.
PLAYBACK_STATE_IDLE Idle.
PLAYBACK_STATE_BUFFERING Buffering.
PLAYBACK_STATE_MAX Maximum value. (Error code 401 is returned in this case.)

AVSession_Type

enum AVSession_Type

Description

Enumerates the session types.

Since: 13

Value Description
SESSION_TYPE_AUDIO Audio.
SESSION_TYPE_VIDEO Video.
SESSION_TYPE_VOICE_CALL Audio call.
SESSION_TYPE_VIDEO_CALL Video call.

AVSessionCallback_Result

enum AVSessionCallback_Result

Description

Enumerates the callback execution results.

Since: 13

Value Description
AVSESSION_CALLBACK_RESULT_SUCCESS The operation is successful.
AVSESSION_CALLBACK_RESULT_FAILURE The operation fails.

Function Description

OH_AVMetadata_Destroy()

AVMetadata_Result OH_AVMetadata_Destroy(OH_AVMetadata* avMetadata)

Description

Releases an OH_AVMetadata object.

Since: 13

Parameters

Name Description
avMetadata Pointer 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

Name Description
builder Double 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

Name Description
builder Pointer 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
avMetadata Double 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
album Pointer 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.

  1. 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
artist Pointer 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.

  1. 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
assetId Pointer 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
author Pointer 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
composer Pointer 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.

  1. 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
description Pointer 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
tags Tags 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
duration Playback 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
lyric Pointer 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
mediaImageUri Pointer 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
intervals Skip 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
subtitle Pointer 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
title Pointer 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.

  1. 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

Name Description
builder Pointer to an OH_AVMetadataBuilder instance.
writer Pointer 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.

  1. writer is a null pointer.

OH_AVSession_Activate()

AVSession_ErrCode OH_AVSession_Activate(OH_AVSession* avsession)

Description

Activates a session.

Since: 13

Parameters

Name Description
avsession Pointer 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

Name Description
sessionType Session type. For details about the available options, see AVSession_Type.
sessionTag Pointer to the session tag.
bundleName Pointer to the bundle name.
abilityName Pointer to the ability name.
avsession Double 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

Name Description
avsession Pointer 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

Name Description
avsession Pointer 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

Name Description
avsession Pointer to a session object.
sessionId Double 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

Name Description
avsession Pointer to a session object.
sessionType Pointer 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

Name Description
avsession Pointer to a session object.
command Playback control command.
callback Callback to register, which is OH_AVSessionCallback_OnCommand.
userData Pointer 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

Name Description
avsession Pointer to a session object.
callback Callback to register, which issue OH_AVSessionCallback_OnFastForward.
userData Pointer 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

Name Description
avsession Pointer to a session object.
callback Callback to register, which is OH_AVSessionCallback_OnRewind.
userData Pointer 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

Name Description
avsession Pointer to a session object.
callback Callback to register, which is OH_AVSessionCallback_OnSeek.
userData Pointer 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

Name Description
avsession Pointer to a session object.
callback Callback to register, which is OH_AVSessionCallback_OnSetLoopMode.
userData Pointer 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

Name Description
avsession Pointer to a session object.
callback Callback to register, which is OH_AVSessionCallback_OnToggleFavorite.
userData Pointer 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

Name Description
avsession Pointer to a session object.
avmetadata Pointer 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

Name Description
avsession Pointer to a session object.
favorite Whether 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

Name Description
avsession Pointer to a session object.
loopMode Loop 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

Name Description
avsession Pointer to a session object.
playbackPosition Pointer 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

Name Description
avsession Pointer to a session object.
playbackState Playback 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

Name Description
avsession Pointer to a session object.
command Playback control command.
callback Callback 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

Name Description
avsession Pointer to a session object.
callback Callback 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

Name Description
avsession Pointer to a session object.
callback Callback 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

Name Description
avsession Pointer to a session object.
callback Callback 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

Name Description
avsession Pointer to a session object.
callback Callback 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

Name Description
avsession Pointer to a session object.
callback Callback 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

0  赞