增加onPause回调

Signed-off-by: jiangqiushi <jiangqiushi@huawei.com>
This commit is contained in:
jiangqiushi 2024-05-12 16:34:13 +08:00
parent 57ef94e6ca
commit 43e5647f55
8 changed files with 58 additions and 2 deletions

View File

@ -48,6 +48,19 @@ public:
}
}
void SetOnPause(MovingPhotoEventFunc&& onPause)
{
onPause_ = std ::move(onPause);
}
void FirePauseEvent()
{
if (onPause_) {
auto onPause = onPause_;
onPause();
}
}
void SetOnStop(MovingPhotoEventFunc&& onStop)
{
onStop_ = std ::move(onStop);
@ -90,6 +103,7 @@ public:
private:
MovingPhotoEventFunc onStart_;
MovingPhotoEventFunc onStop_;
MovingPhotoEventFunc onPause_;
MovingPhotoEventFunc onFinish_;
MovingPhotoEventFunc onError_;
};

View File

@ -114,6 +114,15 @@ void MovingPhotoModelNG::SetOnStop(MovingPhotoEventFunc&& onStop)
eventHub->SetOnStop(std::move(onStop));
}
void MovingPhotoModelNG::SetOnPause(MovingPhotoEventFunc&& onPause)
{
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
CHECK_NULL_VOID(frameNode);
auto eventHub = frameNode->GetEventHub<MovingPhotoEventHub>();
CHECK_NULL_VOID(eventHub);
eventHub->SetOnPause(std::move(onPause));
}
void MovingPhotoModelNG::SetOnFinish(MovingPhotoEventFunc&& onFinish)
{
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();

View File

@ -34,6 +34,7 @@ public:
void SetObjectFit(ImageFit objectFit);
void SetOnStart(MovingPhotoEventFunc&& onStart);
void SetOnStop(MovingPhotoEventFunc&& onStop);
void SetOnPause(MovingPhotoEventFunc&& onPause);
void SetOnFinish(MovingPhotoEventFunc&& onFinish);
void SetOnError(MovingPhotoEventFunc&& onError);

View File

@ -159,6 +159,24 @@ napi_value JsOnStop(napi_env env, napi_callback_info info)
return ExtNapiUtils::CreateNull(env);
}
napi_value JsOnPause(napi_env env, napi_callback_info info)
{
size_t argc = MAX_ARG_NUM;
napi_value thisVal = nullptr;
napi_value argv[MAX_ARG_NUM] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVal, nullptr));
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments");
if (!ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_function)) {
return ExtNapiUtils::CreateNull(env);
}
auto asyncEvent = std::make_shared<NapiAsyncEvent>(env, argv[0]);
auto onPause = [asyncEvent]() {
asyncEvent->Call(0, nullptr);
};
NG::MovingPhotoModelNG::GetInstance()->SetOnPause(std::move(onPause));
return ExtNapiUtils::CreateNull(env);
}
napi_value JsOnFinish(napi_env env, napi_callback_info info)
{
size_t argc = MAX_ARG_NUM;
@ -203,6 +221,7 @@ napi_value InitView(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("objectFit", JsObjectFit),
DECLARE_NAPI_FUNCTION("onStart", JsOnStart),
DECLARE_NAPI_FUNCTION("onStop", JsOnStop),
DECLARE_NAPI_FUNCTION("onPause", JsOnPause),
DECLARE_NAPI_FUNCTION("onFinish", JsOnFinish),
DECLARE_NAPI_FUNCTION("onError", JsOnError),
};

View File

@ -25,6 +25,7 @@ napi_value JsMuted(napi_env env, napi_callback_info info);
napi_value JsObjectFit(napi_env env, napi_callback_info info);
napi_value JsOnStart(napi_env env, napi_callback_info info);
napi_value JsOnStop(napi_env env, napi_callback_info info);
napi_value JsOnPause(napi_env env, napi_callback_info info);
napi_value JsOnFinish(napi_env env, napi_callback_info info);
napi_value JsOnError(napi_env env, napi_callback_info info);
napi_value StartPlayback(napi_env env, napi_callback_info info);

View File

@ -53,8 +53,6 @@ void MovingPhotoPattern::OnModifyDone()
pipelineContext->AddOnAreaChangeNode(host->GetId());
}
InitEvent();
isPlayByController_ = false;
}
void MovingPhotoPattern::OnAttachToFrameNode()
@ -403,6 +401,13 @@ void MovingPhotoPattern::FireMediaPlayerStop()
eventHub->FireStopEvent();
}
void MovingPhotoPattern::FireMediaPlayerPause()
{
auto eventHub = GetEventHub<MovingPhotoEventHub>();
CHECK_NULL_VOID(eventHub);
eventHub->FirePauseEvent();
}
void MovingPhotoPattern::FireMediaPlayerFinish()
{
auto eventHub = GetEventHub<MovingPhotoEventHub>();
@ -572,6 +577,7 @@ void MovingPhotoPattern::OnMediaPlayerStatusChanged(PlaybackStatus status)
break;
case PlaybackStatus::PAUSED:
TAG_LOGI(AceLogTag::ACE_MOVING_PHOTO, "Player current status is PAUSED.");
FireMediaPlayerPause();
break;
case PlaybackStatus::STOPPED:
TAG_LOGI(AceLogTag::ACE_MOVING_PHOTO, "Player current status is STOPPED.");
@ -615,6 +621,7 @@ void MovingPhotoPattern::OnMediaPlayerPrepared()
void MovingPhotoPattern::OnMediaPlayerStoped()
{
isPlayByController_ = false;
FireMediaPlayerStop();
}

View File

@ -113,6 +113,7 @@ private:
void OnPlayPositionChanged(uint32_t pos) {};
void FireMediaPlayerStart();
void FireMediaPlayerStop();
void FireMediaPlayerPause();
void FireMediaPlayerFinish();
void FireMediaPlayerError();
void OnResolutionChange();

View File

@ -36,6 +36,10 @@ class MovingPhotoView extends JSViewAbstract {
__MovingPhotoView__.onStop(value);
}
static onPause(value) {
__MovingPhotoView__.onPause(value);
}
static onFinish(value) {
__MovingPhotoView__.onFinish(value);
}