mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 15:10:30 +00:00
!46814 回退video资源管理需求代码
Merge pull request !46814 from hw_ljz/kb_avoid_pr
This commit is contained in:
commit
5a55becbf8
@ -253,16 +253,6 @@ VideoPattern::VideoPattern(const RefPtr<VideoControllerV2>& videoController)
|
||||
: instanceId_(Container::CurrentId()), videoControllerV2_(videoController)
|
||||
{}
|
||||
|
||||
void VideoPattern::ResetInitializingPlayerTask()
|
||||
{
|
||||
initializingTask_.Reset([weak = WeakClaim(this)]() {
|
||||
auto video = weak.Upgrade();
|
||||
CHECK_NULL_VOID(video);
|
||||
auto targetPattern = video->GetTargetVideoPattern();
|
||||
CHECK_NULL_VOID(targetPattern);
|
||||
targetPattern->InitializeMediaPlayer();
|
||||
});
|
||||
}
|
||||
void VideoPattern::ResetStatus()
|
||||
{
|
||||
isInitialState_ = true;
|
||||
@ -272,78 +262,28 @@ void VideoPattern::ResetStatus()
|
||||
#endif
|
||||
}
|
||||
|
||||
void VideoPattern::ResetMediaPlayer(bool isResetByUser)
|
||||
{
|
||||
if (isResetByUser && playerStatus_ == PlayerStatus::PREPARING) {
|
||||
return;
|
||||
}
|
||||
playerStatus_ = PlayerStatus::PREPARING;
|
||||
ResetInitializingPlayerTask();
|
||||
initializingTask_();
|
||||
PrepareAsync();
|
||||
}
|
||||
|
||||
void VideoPattern::InitializeMediaPlayer()
|
||||
void VideoPattern::ResetMediaPlayer()
|
||||
{
|
||||
CHECK_NULL_VOID(mediaPlayer_);
|
||||
mediaPlayer_->ResetMediaPlayer();
|
||||
SetIsPrepared(false);
|
||||
if (!SetSourceForMediaPlayer()) {
|
||||
TAG_LOGW(AceLogTag::ACE_VIDEO, "Video set source for mediaPlayer failed.");
|
||||
|
||||
// It need post on ui thread.
|
||||
FireError();
|
||||
playerStatus_ = PlayerStatus::ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
RegisterMediaPlayerEvent();
|
||||
PrepareSurface();
|
||||
if (playerStatus_ == PlayerStatus::INITIALIZING) {
|
||||
playerStatus_ = PlayerStatus::INITIALIZED;
|
||||
} else if (playerStatus_ == PlayerStatus::RELEASING) {
|
||||
playerStatus_ = PlayerStatus::RELEASED;
|
||||
if (mediaPlayer_ && mediaPlayer_->PrepareAsync() != 0) {
|
||||
TAG_LOGE(AceLogTag::ACE_VIDEO, "Player prepare failed");
|
||||
}
|
||||
}
|
||||
|
||||
void VideoPattern::PrepareAsync()
|
||||
{
|
||||
CHECK_NULL_VOID(mediaPlayer_);
|
||||
if (playerStatus_ == PlayerStatus::ERROR) {
|
||||
return;
|
||||
}
|
||||
if (initializingTask_.WaitUntilComplete(100ms)) {
|
||||
if (mediaPlayer_->PrepareAsync() != 0) {
|
||||
playerStatus_ = PlayerStatus::INITIALIZED;
|
||||
TAG_LOGE(AceLogTag::ACE_VIDEO, "Player prepare failed");
|
||||
}
|
||||
return;
|
||||
}
|
||||
playerStatus_ = PlayerStatus::NONE;
|
||||
}
|
||||
|
||||
void VideoPattern::PrepareAsyncOnBg()
|
||||
{
|
||||
if (playerStatus_ == PlayerStatus::ERROR) {
|
||||
return;
|
||||
}
|
||||
ContainerScope scope(instanceId_);
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto context = host->GetContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
auto platformTask = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::BACKGROUND);
|
||||
playerStatus_ = PlayerStatus::PREPARING;
|
||||
platformTask.PostTask([weak = WeakClaim(this)] {
|
||||
auto video = weak.Upgrade();
|
||||
CHECK_NULL_VOID(video);
|
||||
auto targetPattern = video->GetTargetVideoPattern();
|
||||
CHECK_NULL_VOID(targetPattern);
|
||||
targetPattern->PrepareAsync();
|
||||
}, "ArkUIVideoPrepareAsync");
|
||||
}
|
||||
|
||||
void VideoPattern::UpdateMediaPlayerOnBg()
|
||||
{
|
||||
RegisterVisibleRatioCallback();
|
||||
PrepareMediaPlayer();
|
||||
UpdateSpeed();
|
||||
UpdateLooping();
|
||||
@ -354,15 +294,6 @@ void VideoPattern::UpdateMediaPlayerOnBg()
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoPattern::IsVideoSourceChanged()
|
||||
{
|
||||
auto videoLayoutProperty = GetLayoutProperty<VideoLayoutProperty>();
|
||||
CHECK_NULL_RETURN(videoLayoutProperty, false);
|
||||
if (!videoLayoutProperty->HasVideoSource() || videoLayoutProperty->GetVideoSource() == videoSrcInfo_) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void VideoPattern::PrepareMediaPlayer()
|
||||
{
|
||||
auto videoLayoutProperty = GetLayoutProperty<VideoLayoutProperty>();
|
||||
@ -372,12 +303,6 @@ void VideoPattern::PrepareMediaPlayer()
|
||||
TAG_LOGI(AceLogTag::ACE_VIDEO, "Video source is null or the source has not changed.");
|
||||
return;
|
||||
}
|
||||
if (playerStatus_ == PlayerStatus::PREPARING || playerStatus_ == PlayerStatus::INITIALIZING ||
|
||||
playerStatus_ == PlayerStatus::RELEASING) {
|
||||
return;
|
||||
}
|
||||
isSeekingWhenNotPrepared_ = false;
|
||||
auto shouldPreparePlayer = ShouldPrepareMediaPlayer();
|
||||
auto videoSrcInfo = videoLayoutProperty->GetVideoSource();
|
||||
videoSrcInfo_.src = videoSrcInfo->GetSrc();
|
||||
videoSrcInfo_.bundleName = videoSrcInfo->GetBundleName();
|
||||
@ -385,11 +310,13 @@ void VideoPattern::PrepareMediaPlayer()
|
||||
if (mediaPlayer_ && !mediaPlayer_->IsMediaPlayerValid()) {
|
||||
mediaPlayer_->CreateMediaPlayer();
|
||||
}
|
||||
|
||||
if (mediaPlayer_ && !mediaPlayer_->IsMediaPlayerValid()) {
|
||||
// It need post on ui thread.
|
||||
FireError();
|
||||
return;
|
||||
}
|
||||
|
||||
ResetStatus();
|
||||
ContainerScope scope(instanceId_);
|
||||
auto host = GetHost();
|
||||
@ -397,20 +324,13 @@ void VideoPattern::PrepareMediaPlayer()
|
||||
auto context = host->GetContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
auto platformTask = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::BACKGROUND);
|
||||
playerStatus_ = shouldPreparePlayer ? PlayerStatus::PREPARING : PlayerStatus::INITIALIZING;
|
||||
if (shouldPreparePlayer) {
|
||||
platformTask.PostTask([weak = WeakClaim(this)] {
|
||||
auto video = weak.Upgrade();
|
||||
CHECK_NULL_VOID(video);
|
||||
auto targetPattern = video->GetTargetVideoPattern();
|
||||
CHECK_NULL_VOID(targetPattern);
|
||||
targetPattern->ResetMediaPlayer();
|
||||
}, "ArkUIVideoResetMediaPlayer");
|
||||
}
|
||||
else {
|
||||
ResetInitializingPlayerTask();
|
||||
platformTask.PostTask(initializingTask_, "ArkUIVideoInitializingTask");
|
||||
}
|
||||
platformTask.PostTask([weak = WeakClaim(this)] {
|
||||
auto video = weak.Upgrade();
|
||||
CHECK_NULL_VOID(video);
|
||||
auto targetPattern = video->GetTargetVideoPattern();
|
||||
CHECK_NULL_VOID(targetPattern);
|
||||
targetPattern->ResetMediaPlayer();
|
||||
}, "ArkUIVideoMediaPlayerReset");
|
||||
}
|
||||
|
||||
bool VideoPattern::SetSourceForMediaPlayer()
|
||||
@ -616,7 +536,6 @@ void VideoPattern::ChangePlayerStatus(bool isPlaying, const PlaybackStatus& stat
|
||||
auto eventHub = GetEventHub<VideoEventHub>();
|
||||
CHECK_NULL_VOID(eventHub);
|
||||
eventHub->FireStopEvent(param);
|
||||
ReleaseMediaPlayer();
|
||||
}
|
||||
|
||||
if (status == PlaybackStatus::PREPARED) {
|
||||
@ -631,8 +550,7 @@ void VideoPattern::ChangePlayerStatus(bool isPlaying, const PlaybackStatus& stat
|
||||
auto uiTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI);
|
||||
int32_t milliSecondDuration = 0;
|
||||
mediaPlayer_->GetDuration(milliSecondDuration);
|
||||
auto pos = isSeekingWhenNotPrepared_ ? seekingPosWhenNotPrepared_ : 0.0;
|
||||
OnPrepared(milliSecondDuration / MILLISECONDS_TO_SECONDS, pos, true);
|
||||
OnPrepared(milliSecondDuration / MILLISECONDS_TO_SECONDS, 0, true);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -659,9 +577,6 @@ void VideoPattern::OnPlayerStatus(PlaybackStatus status)
|
||||
|
||||
void VideoPattern::OnError(const std::string& errorId)
|
||||
{
|
||||
playerStatus_ = PlayerStatus::ERROR;
|
||||
isStartByUser_ = false;
|
||||
SetIsPrepared(false);
|
||||
std::string errorcode = Localization::GetInstance()->GetErrorDescription(errorId);
|
||||
auto json = JsonUtil::Create(true);
|
||||
json->Put("error", "");
|
||||
@ -726,11 +641,27 @@ void VideoPattern::OnPrepared(uint32_t duration, uint32_t currentPos, bool needF
|
||||
isPlaying_ = mediaPlayer_->IsPlaying();
|
||||
SetIsSeeking(false);
|
||||
SetIsPrepared(true);
|
||||
playerStatus_ = PlayerStatus::PREPARED;
|
||||
UpdateControlBar(duration_, true);
|
||||
OnUpdateTime(duration_, DURATION_POS);
|
||||
OnUpdateTime(currentPos_, CURRENT_POS);
|
||||
|
||||
RefPtr<UINode> controlBar = nullptr;
|
||||
auto children = host->GetChildren();
|
||||
for (const auto& child : children) {
|
||||
if (child->GetTag() == V2::ROW_ETS_TAG) {
|
||||
controlBar = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CHECK_NULL_VOID(controlBar);
|
||||
auto sliderNode = DynamicCast<FrameNode>(controlBar->GetChildAtIndex(SLIDER_POS));
|
||||
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
|
||||
CHECK_NULL_VOID(sliderPaintProperty);
|
||||
sliderPaintProperty->UpdateMin(0.0f);
|
||||
sliderPaintProperty->UpdateMax(static_cast<float>(duration_));
|
||||
sliderNode->MarkModifyDone();
|
||||
auto playBtn = DynamicCast<FrameNode>(controlBar->GetChildAtIndex(0));
|
||||
ChangePlayButtonTag(playBtn);
|
||||
|
||||
if (needFireEvent) {
|
||||
auto json = JsonUtil::Create(true);
|
||||
json->Put("duration", static_cast<double>(duration_));
|
||||
@ -742,24 +673,22 @@ void VideoPattern::OnPrepared(uint32_t duration, uint32_t currentPos, bool needF
|
||||
UpdateLooping();
|
||||
UpdateSpeed();
|
||||
UpdateMuted();
|
||||
if (isSeekingWhenNotPrepared_) {
|
||||
SetCurrentTime(seekingPosWhenNotPrepared_, seekingModeWhenNotPrepared_);
|
||||
isSeekingWhenNotPrepared_ = false;
|
||||
}
|
||||
CheckNeedPlay();
|
||||
|
||||
checkNeedAutoPlay();
|
||||
}
|
||||
|
||||
void VideoPattern::CheckNeedPlay()
|
||||
void VideoPattern::checkNeedAutoPlay()
|
||||
{
|
||||
if (isStop_) {
|
||||
isStop_ = false;
|
||||
}
|
||||
if (!dragEndAutoPlay_ && !isStartByUser_ && !autoPlay_) {
|
||||
return;
|
||||
if (dragEndAutoPlay_) {
|
||||
dragEndAutoPlay_ = false;
|
||||
Start();
|
||||
}
|
||||
if (autoPlay_) {
|
||||
Start();
|
||||
}
|
||||
dragEndAutoPlay_ = false;
|
||||
isStartByUser_ = false;
|
||||
StartPlay();
|
||||
}
|
||||
|
||||
void VideoPattern::OnCompletion()
|
||||
@ -900,8 +829,7 @@ void VideoPattern::OnUpdateTime(uint32_t time, int pos) const
|
||||
|
||||
void VideoPattern::PrepareSurface()
|
||||
{
|
||||
CHECK_NULL_VOID(mediaPlayer_);
|
||||
if (renderSurface_->IsSurfaceValid()) {
|
||||
if (!mediaPlayer_ || renderSurface_->IsSurfaceValid()) {
|
||||
return;
|
||||
}
|
||||
if (!SystemProperties::GetExtSurfaceEnabled()) {
|
||||
@ -925,7 +853,6 @@ void VideoPattern::OnAttachToFrameNode()
|
||||
auto pipeline = host->GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
pipeline->AddWindowStateChangedCallback(host->GetId());
|
||||
RegisterVisibleRatioCallback();
|
||||
auto renderContext = host->GetRenderContext();
|
||||
CHECK_NULL_VOID(renderContext);
|
||||
|
||||
@ -1533,7 +1460,7 @@ void VideoPattern::SetSeekToImpl(
|
||||
ContainerScope scope(pattern->instanceId_);
|
||||
auto targetPattern = pattern->GetTargetVideoPattern();
|
||||
CHECK_NULL_VOID(targetPattern);
|
||||
targetPattern->SeekTo(pos, seekMode);
|
||||
targetPattern->SetCurrentTime(pos, seekMode);
|
||||
}, "ArkUIVideoSetCurrentTime");
|
||||
});
|
||||
}
|
||||
@ -1597,7 +1524,7 @@ void VideoPattern::SetResetImpl(
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto targetPattern = pattern->GetTargetVideoPattern();
|
||||
CHECK_NULL_VOID(targetPattern);
|
||||
targetPattern->ResetMediaPlayer(true);
|
||||
targetPattern->ResetMediaPlayer();
|
||||
}, "ArkUIVideoReset");
|
||||
});
|
||||
}
|
||||
@ -1625,23 +1552,6 @@ void VideoPattern::SetMethodCall()
|
||||
}
|
||||
|
||||
void VideoPattern::Start()
|
||||
{
|
||||
if (!IsPlayerInValidStatus()) {
|
||||
return;
|
||||
}
|
||||
if (playerStatus_ == PlayerStatus::PREPARING) {
|
||||
isStartByUser_ = true;
|
||||
return;
|
||||
}
|
||||
if (playerStatus_ != PlayerStatus::PREPARED) {
|
||||
isStartByUser_ = true;
|
||||
PrepareAsyncOnBg();
|
||||
return;
|
||||
}
|
||||
StartPlay();
|
||||
}
|
||||
|
||||
void VideoPattern::StartPlay()
|
||||
{
|
||||
if (!mediaPlayer_ || !mediaPlayer_->IsMediaPlayerValid()) {
|
||||
return;
|
||||
@ -1683,11 +1593,10 @@ void VideoPattern::Pause()
|
||||
|
||||
void VideoPattern::Stop()
|
||||
{
|
||||
if (!IsPlayerInValidStatus() || isSeeking_ || playerStatus_ != PlayerStatus::PREPARED) {
|
||||
if (!mediaPlayer_ || !mediaPlayer_->IsMediaPlayerValid()) {
|
||||
return;
|
||||
}
|
||||
isStartByUser_ = false;
|
||||
isSeekingWhenNotPrepared_ = false;
|
||||
|
||||
OnCurrentTimeChange(0);
|
||||
mediaPlayer_->Stop();
|
||||
isStop_ = true;
|
||||
@ -1784,24 +1693,6 @@ void VideoPattern::ChangeFullScreenButtonTag(bool isFullScreen, RefPtr<FrameNode
|
||||
fullScreenBtn->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
|
||||
}
|
||||
|
||||
void VideoPattern::SeekTo(float currentPos, OHOS::Ace::SeekMode seekMode)
|
||||
{
|
||||
CHECK_NULL_VOID(mediaPlayer_);
|
||||
if (!IsPlayerInValidStatus() || isStop_) {
|
||||
return;
|
||||
}
|
||||
if (playerStatus_ == PlayerStatus::PREPARING) {
|
||||
RecordSeekingInfoBeforePlaying(currentPos, seekMode);
|
||||
return;
|
||||
}
|
||||
if (playerStatus_ != PlayerStatus::PREPARED) {
|
||||
RecordSeekingInfoBeforePlaying(currentPos, seekMode);
|
||||
PrepareAsyncOnBg();
|
||||
return;
|
||||
}
|
||||
SetCurrentTime(currentPos, seekMode);
|
||||
}
|
||||
|
||||
void VideoPattern::SetCurrentTime(float currentPos, OHOS::Ace::SeekMode seekMode)
|
||||
{
|
||||
if (!mediaPlayer_ || !mediaPlayer_->IsMediaPlayerValid() || !isPrepared_) {
|
||||
@ -1815,10 +1706,6 @@ void VideoPattern::SetCurrentTime(float currentPos, OHOS::Ace::SeekMode seekMode
|
||||
|
||||
void VideoPattern::OnSliderChange(float posTime, int32_t mode)
|
||||
{
|
||||
CHECK_NULL_VOID(mediaPlayer_);
|
||||
if (isStop_) {
|
||||
return;
|
||||
}
|
||||
SetCurrentTime(posTime, OHOS::Ace::SeekMode::SEEK_CLOSEST);
|
||||
auto eventHub = GetEventHub<VideoEventHub>();
|
||||
CHECK_NULL_VOID(eventHub);
|
||||
@ -1989,13 +1876,6 @@ void VideoPattern::RecoverState(const RefPtr<VideoPattern>& videoPattern)
|
||||
isAnalyzerCreated_ = videoPattern->GetAnalyzerState();
|
||||
isEnableAnalyzer_ = videoPattern->isEnableAnalyzer_;
|
||||
fullScreenNodeId_.reset();
|
||||
isSeekingWhenNotPrepared_ = videoPattern->GetIsSeekingWhenNotPrepared();
|
||||
seekingPosWhenNotPrepared_ = videoPattern->GetSeekingPosWhenNotPrepared();
|
||||
seekingModeWhenNotPrepared_ = videoPattern->GetSeekingModeWhenNotPrepared();
|
||||
isSeeking_ = videoPattern->GetIsSeeking();
|
||||
playerStatus_ = videoPattern->GetPlayerStatus();
|
||||
initializingTask_ = std::move(videoPattern->GetInitializingTask());
|
||||
UpdateControlBar(duration_);
|
||||
RegisterMediaPlayerEvent();
|
||||
auto videoNode = GetHost();
|
||||
CHECK_NULL_VOID(videoNode);
|
||||
@ -2240,90 +2120,4 @@ void VideoPattern::OnWindowHide()
|
||||
#endif
|
||||
}
|
||||
|
||||
void VideoPattern::UpdateControlBar(uint32_t duration, bool isChangePlayBtn)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
RefPtr<UINode> controlBar = nullptr;
|
||||
auto children = host->GetChildren();
|
||||
for (const auto& child : children) {
|
||||
if (child->GetTag() == V2::ROW_ETS_TAG) {
|
||||
controlBar = child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
CHECK_NULL_VOID(controlBar);
|
||||
auto sliderNode = DynamicCast<FrameNode>(controlBar->GetChildAtIndex(SLIDER_POS));
|
||||
auto sliderPaintProperty = sliderNode->GetPaintProperty<SliderPaintProperty>();
|
||||
CHECK_NULL_VOID(sliderPaintProperty);
|
||||
if (!NearEqual(sliderPaintProperty->GetMaxValue(0.0), duration)) {
|
||||
sliderPaintProperty->UpdateMin(0.0f);
|
||||
sliderPaintProperty->UpdateMax(static_cast<float>(duration));
|
||||
sliderNode->MarkModifyDone();
|
||||
}
|
||||
if (isChangePlayBtn) {
|
||||
auto playBtn = DynamicCast<FrameNode>(controlBar->GetChildAtIndex(0));
|
||||
ChangePlayButtonTag(playBtn);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoPattern::RegisterVisibleRatioCallback()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto visibleAreaChangeFunc = [weak = WeakClaim(this)] (bool isVisible, double currentRatio) {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
if (isVisible && currentRatio >= 0.0) {
|
||||
auto playerStatus = pattern->GetPlayerStatus();
|
||||
if (playerStatus == PlayerStatus::INITIALIZED) {
|
||||
pattern->PrepareAsyncOnBg();
|
||||
}
|
||||
pattern->UpdateVisibility(true);
|
||||
}
|
||||
if (!isVisible && currentRatio <= 0.0) {
|
||||
pattern->UpdateVisibility(false);
|
||||
}
|
||||
};
|
||||
auto pipeline = host->GetContext();
|
||||
CHECK_NULL_VOID(pipeline);
|
||||
pipeline->AddVisibleAreaChangeNode(host, {0.0}, visibleAreaChangeFunc, false);
|
||||
}
|
||||
|
||||
void VideoPattern::RecordSeekingInfoBeforePlaying(float currentPos, OHOS::Ace::SeekMode seekMode, bool sliderChange)
|
||||
{
|
||||
isSeekingWhenNotPrepared_ = true;
|
||||
seekingPosWhenNotPrepared_ = currentPos;
|
||||
seekingModeWhenNotPrepared_ = seekMode;
|
||||
}
|
||||
|
||||
void VideoPattern::ReleaseMediaPlayer()
|
||||
{
|
||||
playerStatus_ = PlayerStatus::RELEASING;
|
||||
ContainerScope scope(instanceId_);
|
||||
auto context = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
auto platformTask = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::BACKGROUND);
|
||||
ResetInitializingPlayerTask();
|
||||
platformTask.PostTask(initializingTask_, "ArkUIVideoReleasingMediaPlayer");
|
||||
}
|
||||
|
||||
bool VideoPattern::ShouldPrepareMediaPlayer()
|
||||
{
|
||||
CHECK_NULL_RETURN(mediaPlayer_, false);
|
||||
if (playerStatus_ == PlayerStatus::PREPARED) {
|
||||
return IsVideoSourceChanged();
|
||||
}
|
||||
auto layoutProperty = GetLayoutProperty<VideoLayoutProperty>();
|
||||
if (layoutProperty && layoutProperty->HasVisibility()) {
|
||||
return IsVideoSourceChanged();
|
||||
}
|
||||
return isVisible_ && IsVideoSourceChanged();
|
||||
}
|
||||
|
||||
bool VideoPattern::IsPlayerInValidStatus()
|
||||
{
|
||||
return mediaPlayer_ && mediaPlayer_->IsMediaPlayerValid() &&
|
||||
playerStatus_ != PlayerStatus::NONE && playerStatus_ != PlayerStatus::ERROR;
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -36,16 +36,6 @@ namespace OHOS::Ace {
|
||||
class ImageAnalyzerManager;
|
||||
}
|
||||
namespace OHOS::Ace::NG {
|
||||
enum class PlayerStatus {
|
||||
NONE,
|
||||
ERROR,
|
||||
INITIALIZING,
|
||||
INITIALIZED,
|
||||
PREPARING,
|
||||
PREPARED,
|
||||
RELEASING,
|
||||
RELEASED,
|
||||
};
|
||||
class VideoPattern : public Pattern {
|
||||
DECLARE_ACE_TYPE(VideoPattern, Pattern);
|
||||
|
||||
@ -168,7 +158,7 @@ public:
|
||||
|
||||
// It is used to init mediaplayer on background.
|
||||
void UpdateMediaPlayerOnBg();
|
||||
void ResetMediaPlayer(bool isResetByUser = false);
|
||||
void ResetMediaPlayer();
|
||||
|
||||
void EnableDrag();
|
||||
void SetIsStop(bool isStop)
|
||||
@ -275,41 +265,6 @@ public:
|
||||
return isPrepared_;
|
||||
}
|
||||
|
||||
bool GetIsSeekingWhenNotPrepared() const
|
||||
{
|
||||
return isSeekingWhenNotPrepared_;
|
||||
}
|
||||
uint32_t GetSeekingPosWhenNotPrepared() const
|
||||
{
|
||||
return seekingPosWhenNotPrepared_;
|
||||
}
|
||||
SeekMode GetSeekingModeWhenNotPrepared() const
|
||||
{
|
||||
return seekingModeWhenNotPrepared_;
|
||||
}
|
||||
void UpdateVisibility(bool isVisible)
|
||||
{
|
||||
isVisible_ = isVisible;
|
||||
}
|
||||
VideoSourceInfo GetVideoSource()
|
||||
{
|
||||
return videoSrcInfo_;
|
||||
}
|
||||
void PrepareAsyncOnBg();
|
||||
PlayerStatus GetPlayerStatus()
|
||||
{
|
||||
return playerStatus_;
|
||||
}
|
||||
void SetTargetPlayerStatus(PlayerStatus playerStatus)
|
||||
{
|
||||
playerStatus_ = playerStatus;
|
||||
}
|
||||
void InitializeMediaPlayer();
|
||||
void PrepareAsync();
|
||||
CancelableCallback<void()> GetInitializingTask()
|
||||
{
|
||||
return initializingTask_;
|
||||
}
|
||||
#ifdef RENDER_EXTRACT_SUPPORTED
|
||||
void OnTextureRefresh(void* surface);
|
||||
#endif
|
||||
@ -394,7 +349,7 @@ private:
|
||||
void PrintPlayerStatus(PlaybackStatus status);
|
||||
|
||||
void UpdateFsState();
|
||||
void CheckNeedPlay();
|
||||
void checkNeedAutoPlay();
|
||||
|
||||
// Fire error manually, eg. src is not existed. It must run on ui.
|
||||
void FireError();
|
||||
@ -426,16 +381,6 @@ private:
|
||||
void UpdateAnalyzerUIConfig(const RefPtr<NG::GeometryNode>& geometryNode);
|
||||
void UpdateOverlayVisibility(VisibleType type);
|
||||
|
||||
void UpdateControlBar(uint32_t duration, bool isChangePlayBtn = false);
|
||||
void StartPlay();
|
||||
void SeekTo(float currentPos, OHOS::Ace::SeekMode seekMode);
|
||||
bool IsVideoSourceChanged();
|
||||
void RecordSeekingInfoBeforePlaying(float currentPos, OHOS::Ace::SeekMode seekMode, bool sliderChange = false);
|
||||
void RegisterVisibleRatioCallback();
|
||||
void ReleaseMediaPlayer();
|
||||
bool ShouldPrepareMediaPlayer();
|
||||
void ResetInitializingPlayerTask();
|
||||
bool IsPlayerInValidStatus();
|
||||
RefPtr<VideoControllerV2> videoControllerV2_;
|
||||
RefPtr<FrameNode> controlBar_;
|
||||
|
||||
@ -478,13 +423,6 @@ private:
|
||||
Rect contentRect_;
|
||||
std::shared_ptr<ImageAnalyzerManager> imageAnalyzerManager_;
|
||||
|
||||
bool isSeekingWhenNotPrepared_ = false;
|
||||
uint32_t seekingPosWhenNotPrepared_ = 0;
|
||||
SeekMode seekingModeWhenNotPrepared_ = SeekMode::SEEK_CLOSEST;
|
||||
bool isStartByUser_ = false;
|
||||
bool isVisible_ = false;
|
||||
PlayerStatus playerStatus_ = PlayerStatus::NONE;
|
||||
CancelableCallback<void()> initializingTask_;
|
||||
ACE_DISALLOW_COPY_AND_MOVE(VideoPattern);
|
||||
};
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -71,7 +71,8 @@ OHOS::Media::PlaybackRateMode ConvertToMediaPlaybackSpeed(float speed)
|
||||
|
||||
RosenMediaPlayer::~RosenMediaPlayer()
|
||||
{
|
||||
Release();
|
||||
CHECK_NULL_VOID(mediaPlayer_);
|
||||
mediaPlayer_->Release();
|
||||
}
|
||||
|
||||
void RosenMediaPlayer::CreateMediaPlayer()
|
||||
@ -510,13 +511,4 @@ int32_t RosenMediaPlayer::SetPlayRange(int64_t startTime, int64_t endTime)
|
||||
return mediaPlayer_->SetPlayRange(startTime, endTime);
|
||||
}
|
||||
|
||||
int32_t RosenMediaPlayer::Release()
|
||||
{
|
||||
LOGI("Media player start to release.");
|
||||
CHECK_NULL_RETURN(mediaPlayer_, -1);
|
||||
auto ret = mediaPlayer_->Release();
|
||||
mediaPlayer_.reset();
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -57,7 +57,6 @@ public:
|
||||
int32_t Stop() override;
|
||||
int32_t Seek(int32_t mSeconds, OHOS::Ace::SeekMode mode) override;
|
||||
int32_t SetPlayRange(int64_t startTime, int64_t endTime) override;
|
||||
int32_t Release() override;
|
||||
|
||||
private:
|
||||
// Interim programme
|
||||
|
@ -141,10 +141,6 @@ public:
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
virtual int32_t Release()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -992,7 +992,6 @@ HWTEST_F(VideoPropertyTestNg, VideoPatternTest022, TestSize.Level1)
|
||||
.WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockMediaPlayer>(videoPattern->mediaPlayer_)), PrepareAsync())
|
||||
.WillOnce(Return(-1));
|
||||
videoPattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
videoPattern->isStop_ = true;
|
||||
videoPattern->isInitialState_ = false;
|
||||
videoPattern->UpdateMediaPlayerOnBg();
|
||||
@ -1102,7 +1101,7 @@ HWTEST_F(VideoPropertyTestNg, VideoPatternTest025, TestSize.Level1)
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call PrepareSurface in different status.
|
||||
* @tc.expected: SetSurface function is not called.
|
||||
* @tc.expected: SetSurface function is called.
|
||||
*/
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockRenderSurface>(videoPattern->renderSurface_)), IsSurfaceValid())
|
||||
.WillOnce(Return(true))
|
||||
@ -1222,7 +1221,6 @@ HWTEST_F(VideoPropertyTestNg, VideoPatternTest028, TestSize.Level1)
|
||||
.WillOnce(Return(-1));
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockMediaPlayer>(videoPattern->mediaPlayer_)), IsMediaPlayerValid())
|
||||
.WillRepeatedly(Return(true));
|
||||
videoPattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
videoPattern->isInitialState_ = false;
|
||||
videoPattern->autoPlay_ = false;
|
||||
videoPattern->UpdateVideoProperty();
|
||||
|
@ -294,7 +294,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1)
|
||||
EXPECT_EQ(frameNode->GetTag(), V2::VIDEO_ETS_TAG);
|
||||
auto pattern = frameNode->GetPattern<VideoPattern>();
|
||||
ASSERT_TRUE(pattern);
|
||||
pattern->isPrepared_ = true;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Call UpdateMediaPlayerOnBg
|
||||
* case: IsMediaPlayerValid is always false
|
||||
@ -314,7 +314,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1)
|
||||
.Times(3)
|
||||
.WillRepeatedly(Return(true));
|
||||
pattern->UpdateMediaPlayerOnBg();
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
|
||||
/**
|
||||
* @tc.steps: step4. Call UpdateMediaPlayerOnBg
|
||||
* case: IsMediaPlayerValid is always true & has set VideoSource
|
||||
@ -329,7 +329,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1)
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
pattern->UpdateMediaPlayerOnBg();
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
|
||||
/**
|
||||
* @tc.steps: step5. Call UpdateMediaPlayerOnBg
|
||||
* case: IsMediaPlayerValid is always true & has set VideoSource & has set videoSrcInfo_.src
|
||||
@ -339,7 +339,6 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1)
|
||||
.Times(3)
|
||||
.WillRepeatedly(Return(true));
|
||||
pattern->UpdateMediaPlayerOnBg();
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
|
||||
/**
|
||||
* @tc.steps: step6. Call UpdateMediaPlayerOnBg
|
||||
@ -358,7 +357,6 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1)
|
||||
.WillOnce(Return(true));
|
||||
|
||||
pattern->UpdateMediaPlayerOnBg();
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
|
||||
/**
|
||||
* @tc.steps: step7. Call UpdateMediaPlayerOnBg several times
|
||||
@ -389,13 +387,10 @@ HWTEST_F(VideoTestNg, VideoPatternTest008, TestSize.Level1)
|
||||
.WillOnce(Return(true));
|
||||
pattern->videoSrcInfo_.src.clear();
|
||||
pattern->UpdateMediaPlayerOnBg();
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
pattern->videoSrcInfo_.src.clear();
|
||||
pattern->UpdateMediaPlayerOnBg();
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
pattern->videoSrcInfo_.src.clear();
|
||||
pattern->UpdateMediaPlayerOnBg();
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
|
||||
// CreateMediaPlayer success but PrepareMediaPlayer fail for mediaPlayer is invalid
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockMediaPlayer>(pattern->mediaPlayer_)), IsMediaPlayerValid())
|
||||
@ -612,7 +607,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest011, TestSize.Level1)
|
||||
pattern->isStop_ = true;
|
||||
pattern->autoPlay_ = true;
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockMediaPlayer>(pattern->mediaPlayer_)), IsMediaPlayerValid())
|
||||
.Times(8)
|
||||
.Times(9)
|
||||
.WillRepeatedly(Return(true));
|
||||
pattern->OnPrepared(DURATION, 0, false);
|
||||
EXPECT_EQ(pattern->duration_, DURATION);
|
||||
@ -666,7 +661,6 @@ HWTEST_F(VideoTestNg, VideoPatternTest012, TestSize.Level1)
|
||||
for (bool isStop : isStops) {
|
||||
for (int prepareReturn : prepareReturns) {
|
||||
pattern->isStop_ = isStop;
|
||||
pattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
if (isStop) {
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockMediaPlayer>(pattern->mediaPlayer_)), PrepareAsync())
|
||||
.WillOnce(Return(prepareReturn));
|
||||
@ -769,11 +763,10 @@ HWTEST_F(VideoTestNg, VideoPatternTest013, TestSize.Level1)
|
||||
* @tc.expected: step2. onSeeking/onSeeked & SetCurrentTime will be called
|
||||
*/
|
||||
std::vector<int32_t> sliderChangeModes { 0, 1, 2 };
|
||||
pattern->isPrepared_ = true;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
auto sliderChangeMode = sliderChangeModes[i];
|
||||
if (i == 1) {
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockMediaPlayer>(pattern->mediaPlayer_)), Seek(_, _)).Times(2);
|
||||
EXPECT_CALL(*(AceType::DynamicCast<MockMediaPlayer>(pattern->mediaPlayer_)), Seek(_, _)).Times(0);
|
||||
}
|
||||
if (i < 2) {
|
||||
seekingCheck.clear();
|
||||
|
@ -1362,7 +1362,7 @@ HWTEST_F(VideoTestExtraAddNg, Stop001, TestSize.Level1)
|
||||
ASSERT_NE(frameNode, nullptr);
|
||||
auto videoPattern = AceType::DynamicCast<VideoPattern>(frameNode->GetPattern());
|
||||
ASSERT_NE(videoPattern, nullptr);
|
||||
videoPattern->playerStatus_ = PlayerStatus::PREPARED;
|
||||
|
||||
auto mockMediaPlayer = AceType::MakeRefPtr<MockMediaPlayer>();
|
||||
EXPECT_CALL(*mockMediaPlayer, IsMediaPlayerValid()).WillRepeatedly(Return(true));
|
||||
videoPattern->mediaPlayer_ = mockMediaPlayer;
|
||||
@ -1478,7 +1478,6 @@ HWTEST_F(VideoTestExtraAddNg, RecoverState001, TestSize.Level1)
|
||||
/* Indirectly call the RecoverState function by calling the ExitFullScreen function */
|
||||
EXPECT_TRUE(fullScreenPattern->ExitFullScreen());
|
||||
|
||||
videoPattern->isPrepared_ = true;
|
||||
videoPattern->mediaPlayer_ = nullptr;
|
||||
|
||||
videoPattern->FullScreen();
|
||||
|
Loading…
Reference in New Issue
Block a user