同步操作将从 OpenHarmony/docs 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
Audio and video playback is a process to decode audio and video files or stream data and play them by an output device. During the process, playback tasks are managed.
The following table describes APIs available for audio and video playback.
Table 1 APIs available for media playback
When the input source is a media stream, the playback progress cannot be controlled and the file duration cannot be obtained.
Implement a PlayerCallback function, register the callback via SetPlayerCallback for event processing.
class TestPlayerCallback : public PlayerCallback{
void OnPlaybackComplete() override
{
// Process the event that the file playback is complete.
}
void OnError(int32_t errorType, int32_t errorCode) override
{
// Process the error event.
}
void OnInfo(int type, int extra) override
{
// Process a common event.
}
void OnRewindToComplete() override
{
// Process the event that playback position is changed.
}
};
Create a Player instance, set the playback source, and start playback.
Player *player = new Player();
std::shared_ptr<PlayerCallback> callback = std::make_shared<TestPlayerCallback>();
player->SetPlayerCallback(callback);// Set a player callback.
std::string uri(filePath);// filePath is a local file path.
Source source(uri);// Create a Source instance and save the URI to the instance.
player->SetSource(source);// Set the Source instance to the player.
player->Prepare(); // Prepare for the playback.
player->SetVideoSurface(surface);// Set the playback surface.
player->Play(); // Start playback.
Control the playback as needed.
player->SetVolume(lvolume, rvolume);// Set volume for left and right channels.
player->EnableSingleLooping(true);// Enable loop playback.
player->Pause(); // Pause playback.
player->Play(); // Resume playing.
Release resources after the playback is complete.
player->Stop(); // Stop playback.
player->Release(); // Release resources.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。