同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Defines the Player class and provides functions related to media playback.
Since:
1.0
Version:
1.0
Declares the Player class, which is used to implement player-related operations. |
OHOS::Media::PlayerSeekMode : int32_t { OHOS::Media::PLAYER_SEEK_PREVIOUS_SYNC = 0, OHOS::Media::PLAYER_SEEK_NEXT_SYNC, OHOS::Media::PLAYER_SEEK_CLOSEST_SYNC, OHOS::Media::PLAYER_SEEK_CLOSEST, OHOS::Media::PLAYER_SEEK_FRAME_INDEX } |
Enumerates player seek modes. You can move the current playback position of the media to a given time position using the specified mode. |
OHOS::Media::PlayerStates : uint32_t { OHOS::Media::PLAYER_STATE_ERROR = 0, OHOS::Media::PLAYER_IDLE = 1 << 0, OHOS::Media::PLAYER_INITIALIZED = 1 << 1, OHOS::Media::PLAYER_PREPARING = 1 << 2, OHOS::Media::PLAYER_PREPARED = 1 << 3, OHOS::Media::PLAYER_STARTED = 1 << 4, OHOS::Media::PLAYER_PAUSED = 1 << 5, OHOS::Media::PLAYER_STOPPED = 1 << 6, OHOS::Media::PLAYER_PLAYBACK_COMPLETE = 1 << 7 } |
|
OHOS::Media::PlayerCallback::PlayerInfoType : int32_t { OHOS::Media::PlayerCallback::PLAYER_INFO_RENDER_START = 0 } |
OHOS::Media::PlayerCallback::OnError (int32_t errorType, int32_t errorCode)=0 |
|
OHOS::Media::PlayerCallback::OnInfo (int type, int extra)=0 |
|
OHOS::Media::PlayerCallback::OnVideoSizeChanged (int width, int height)=0 |
|
OHOS::Media::Player::SetSource (const Source &source) |
Sets the playback source for the player. The corresponding source can be the file descriptor (FD) of the local file, local file URI, network URI, or media stream. |
OHOS::Media::Player::Rewind (int64_t mSeconds, int32_t mode) |
|
OHOS::Media::Player::SetVolume (float leftVolume, float rightVolume) |
|
OHOS::Media::Player::SetVideoSurface (Surface *surface) |
|
OHOS::Media::Player::EnableSingleLooping (bool loop) |
|
OHOS::Media::Player::GetCurrentTime (int64_t &time) const |
|
OHOS::Media::Player::GetDuration (int64_t &duration) const |
|
OHOS::Media::Player::GetVideoWidth (int32_t &videoWidth) |
|
OHOS::Media::Player::GetVideoHeight (int32_t &videoHeight) |
|
OHOS::Media::Player::SetPlayerCallback (const std::shared_ptr< PlayerCallback > &cb) |
Registers a listener to receive events and exception notifications from the player. |
enum [OHOS::Media::PlayerCallback::PlayerInfoType](MultiMedia_Player.md#ga7dac9dac65cbbea7e411adcf2c314ac5) : int32_t
PLAYER_INFO_RENDER_START |
enum [OHOS::Media::PlayerSeekMode](MultiMedia_Player.md#gad1574e5769b3174c2103a2a8b49e20d4) : int32_t
Description:
Enumerates player seek modes. You can move the current playback position of the media to a given time position using the specified mode.
enum [OHOS::Media::PlayerStates](MultiMedia_Player.md#ga8b1147e57c4a67f63f193836302da2b7) : uint32_t
Description:
Enumerates player states.
PLAYER_STATE_ERROR | |
PLAYER_IDLE | |
PLAYER_INITIALIZED | |
PLAYER_PREPARING | |
PLAYER_PREPARED | |
PLAYER_STARTED | |
PLAYER_PAUSED | |
PLAYER_STOPPED | |
PLAYER_PLAYBACK_COMPLETE |
int32_t OHOS::Media::Player::EnableSingleLooping (bool loop)
Description:
Sets loop playback.
Parameters:
loop | Specifies whether to enable loop playback. The value true means to enable loop playback, and false means to disable loop playback. |
Returns:
Returns 0 if the setting is successful; returns -1 otherwise.
int32_t OHOS::Media::Player::GetCurrentTime (int64_t & time) const
Description:
Obtains the playback position, accurate to millisecond.
Parameters:
time | Indicates the playback position. |
Returns:
Returns 0 if the playback position is obtained; returns -1 otherwise.
int32_t OHOS::Media::Player::GetDuration (int64_t & duration) const
Description:
Obtains the total duration of media files, in milliseconds.
Parameters:
duration | Indicates the total duration of media files. |
Returns:
Returns 0 if the total duration is obtained; returns -1 otherwise.
int32_t OHOS::Media::Player::GetVideoHeight (int32_t & videoHeight)
Description:
Obtains the height of the video.
Parameters:
videoHeight | Indicates the video height. |
Returns:
Returns 0 if the video height is obtained; returns -1 otherwise.
int32_t OHOS::Media::Player::GetVideoWidth (int32_t & videoWidth)
Description:
Obtains the width of the video.
Parameters:
videoWidth | Indicates the video width. |
Returns:
Returns 0 if the video width is obtained; returns -1 otherwise.
bool OHOS::Media::Player::IsPlaying ()
Description:
Checks whether the player is playing.
Returns:
Returns true if the player is playing; returns false otherwise.
bool OHOS::Media::Player::IsSingleLooping ()
Description:
Checks whether the player is looping.
Returns:
Returns true if the player is looping; returns false otherwise.
virtual void OHOS::Media::PlayerCallback::OnError (int32_t errorType, int32_t errorCode )
Description:
Called when a playback error occurs.
Parameters:
errorType | Indicates the error type. For details, see PlayerErrorType. |
errorCode | Indicates the error code. |
virtual void OHOS::Media::PlayerCallback::OnInfo (int type, int extra )
Description:
Called when playback information is received.
Parameters:
type | Indicates the information type. For details, see PlayerInfoType. |
extra | Indicates the information code. |
virtual void OHOS::Media::PlayerCallback::OnPlaybackComplete ()
Description:
Called when the playback is complete.
virtual void OHOS::Media::PlayerCallback::OnRewindToComplete ()
Description:
Called when the rewind is complete.
virtual void OHOS::Media::PlayerCallback::OnVideoSizeChanged (int width, int height )
Description:
Called when the video image size changes.
Parameters:
width | Indicates the video width. |
height | Indicates the video height. |
int32_t OHOS::Media::Player::Pause ()
Description:
Pauses playback.
Returns:
Returns 0 if the playback is paused; returns -1 otherwise.
int32_t OHOS::Media::Player::Play ()
Description:
Starts or resumes playback.
This function must be called after Prepare. If the player state is Prepared, this function is called to start playback. If the player state is Playback paused, this function is called to resume playback. If the media is playing in an abnormal speed, this function is called to restore the playback speed to normal.
Returns:
Returns 0 if the playback starts or resumes; returns -1 otherwise.
int32_t OHOS::Media::Player::Prepare ()
Description:
Prepares the playback environment and buffers media data.
This function must be called after SetSource.
Returns:
Returns 0 if the playback environment is prepared and media data is buffered; returns -1 otherwise.
int32_t OHOS::Media::Player::Release ()
Description:
Releases player resources.
Returns:
Returns 0 if player resources are released; returns -1 otherwise.
int32_t OHOS::Media::Player::Reset ()
Description:
Restores the player to the initial state.
Returns:
Returns 0 if the player is restored; returns -1 otherwise.
int32_t OHOS::Media::Player::Rewind (int64_t mSeconds, int32_t mode )
Description:
Changes the playback position.
This function can be used during playback or pause.
Parameters:
mSeconds | Indicates the target playback position, accurate to second. |
mode | Indicates the player seek mode. For details, see PlayerSeekMode. |
Returns:
Returns 0 if the playback position is changed; returns -1 otherwise.
void OHOS::Media::Player::SetPlayerCallback (const std::shared_ptr< [PlayerCallback](OHOS-Media-PlayerCallback.md) > & cb)
Description:
Registers a listener to receive events and exception notifications from the player.
Parameters:
cb | Indicates the listener to register. For details, see PlayerCallback. |
int32_t OHOS::Media::Player::SetSource (const [Source](OHOS-Media-Source.md) & source)
Description:
Sets the playback source for the player. The corresponding source can be the file descriptor (FD) of the local file, local file URI, network URI, or media stream.
Parameters:
source | Indicates the playback source. Currently, only local file URIs and media streams are supported. For details, see Source. |
Returns:
Returns 0 if the setting is successful; returns -1 otherwise.
int32_t OHOS::Media::Player::SetVideoSurface ([Surface](OHOS-Surface.md) * surface)
Description:
Sets a surface for video playback.
Parameters:
surface | Indicates the surface to set. For details, see Surface. |
Returns:
Returns 0 if the setting is successful; returns -1 otherwise.
int32_t OHOS::Media::Player::SetVolume (float leftVolume, float rightVolume )
Description:
Sets the volume of the player.
This function can be used during playback or pause. The value 0 indicates no sound, and 100 indicates the original volume. If no audio device is started or no audio stream exists, the value -1 is returned.
Parameters:
leftVolume | Indicates the target volume of the left audio channel to set, ranging from 0 to 300. |
rightVolume | Indicates the target volume of the right audio channel to set, ranging from 0 to 300. |
Returns:
Returns 0 if the setting is successful; returns -1 otherwise.
int32_t OHOS::Media::Player::Stop ()
Description:
Stops playback.
Returns:
Returns 0 if the playback is stopped; returns -1 otherwise.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。