【动态照片】支持多种播放形式优化

Signed-off-by: qinlida <qinlida1@h-partners.com>
This commit is contained in:
qinlida 2024-08-10 10:31:28 +08:00
parent 3354eb69ef
commit 737f180f27
5 changed files with 29 additions and 25 deletions

View File

@ -68,14 +68,14 @@ napi_value ExtNapiUtils::CreateInt32(napi_env env, int32_t code)
int32_t ExtNapiUtils::GetCInt32(napi_env env, napi_value value)
{
int32_t num;
int32_t num = 0;
napi_get_value_int32(env, value, &num);
return num;
}
int64_t ExtNapiUtils::GetCInt64(napi_env env, napi_value value)
{
int64_t num;
int64_t num = 0;
napi_get_value_int64(env, value, &num);
return num;
}

View File

@ -37,7 +37,7 @@ public:
void SetOnComplete(MovingPhotoEventFunc&& onComplete)
{
onComplete_ = std ::move(onComplete);
onComplete_ = std::move(onComplete);
}
MovingPhotoEventFunc GetOnComplete()

View File

@ -35,11 +35,11 @@ extern const char* _binary_multimedia_movingphotoview_abc_end;
namespace OHOS::Ace {
namespace {
static constexpr const size_t MAX_ARG_NUM = 10;
static constexpr const int32_t ARG_NUM_1 = 1;
static constexpr const int32_t ARG_NUM_2 = 2;
static constexpr const int32_t PARAM_INDEX_ZERO = 0;
static constexpr const int32_t PARAM_INDEX_ONE = 1;
static constexpr size_t MAX_ARG_NUM = 10;
static constexpr int32_t ARG_NUM_ONE = 1;
static constexpr int32_t ARG_NUM_TWO = 2;
static constexpr int32_t PARAM_INDEX_ZERO = 0;
static constexpr int32_t PARAM_INDEX_ONE = 1;
} // namespace
std::unique_ptr<NG::MovingPhotoModelNG> NG::MovingPhotoModelNG::instance_ = nullptr;
@ -61,7 +61,7 @@ napi_value JsCreate(napi_env env, napi_callback_info info)
size_t argc = MAX_ARG_NUM;
napi_value argv[MAX_ARG_NUM] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
NAPI_ASSERT(env, argc >= ARG_NUM_1, "Wrong number of arguments");
NAPI_ASSERT(env, argc >= ARG_NUM_ONE, "Wrong number of arguments");
if (!ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_object)) {
return ExtNapiUtils::CreateNull(env);
@ -99,7 +99,7 @@ napi_value JsMuted(napi_env env, napi_callback_info info)
size_t argc = MAX_ARG_NUM;
napi_value argv[MAX_ARG_NUM] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
NAPI_ASSERT(env, argc >= ARG_NUM_1, "Wrong number of arguments");
NAPI_ASSERT(env, argc >= ARG_NUM_ONE, "Wrong number of arguments");
bool muted = false;
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_boolean)) {
@ -115,7 +115,7 @@ napi_value JsObjectFit(napi_env env, napi_callback_info info)
size_t argc = MAX_ARG_NUM;
napi_value argv[MAX_ARG_NUM] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
NAPI_ASSERT(env, argc >= ARG_NUM_1, "Wrong number of arguments");
NAPI_ASSERT(env, argc >= ARG_NUM_ONE, "Wrong number of arguments");
auto objectFit = ImageFit::COVER;
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[0], napi_number)) {
@ -325,7 +325,7 @@ napi_value JsAutoPlayPeriod(napi_env env, napi_callback_info info)
size_t argc = MAX_ARG_NUM;
napi_value argv[MAX_ARG_NUM] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
NAPI_ASSERT(env, argc >= ARG_NUM_2, "Wrong number of arguments");
NAPI_ASSERT(env, argc >= ARG_NUM_TWO, "Wrong number of arguments");
int64_t startTime = 0;
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[PARAM_INDEX_ZERO], napi_number)) {
@ -345,7 +345,7 @@ napi_value JsAutoPlay(napi_env env, napi_callback_info info)
size_t argc = MAX_ARG_NUM;
napi_value argv[MAX_ARG_NUM] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
NAPI_ASSERT(env, argc >= ARG_NUM_1, "Wrong number of arguments");
NAPI_ASSERT(env, argc >= ARG_NUM_ONE, "Wrong number of arguments");
bool isAutoPlay = false;
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[PARAM_INDEX_ZERO], napi_boolean)) {
@ -361,7 +361,7 @@ napi_value JsRepeatPlay(napi_env env, napi_callback_info info)
size_t argc = MAX_ARG_NUM;
napi_value argv[MAX_ARG_NUM] = { nullptr };
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr));
NAPI_ASSERT(env, argc >= ARG_NUM_1, "Wrong number of arguments");
NAPI_ASSERT(env, argc >= ARG_NUM_ONE, "Wrong number of arguments");
bool isRepeatPlay = false;
if (ExtNapiUtils::CheckTypeForNapiValue(env, argv[PARAM_INDEX_ZERO], napi_boolean)) {

View File

@ -733,7 +733,7 @@ void MovingPhotoPattern::OnMediaPlayerStatusChanged(PlaybackStatus status)
void MovingPhotoPattern::OnMediaPlayerInitialized()
{
TAG_LOGI(AceLogTag::ACE_MOVING_PHOTO, "MediaPlayer OnMediaPlayerInitialized.");
if (!isSetAutoPlayPeriod_ && autoAndRepeatLevel_ != PlaybackMode::AUTO) {
if (!isSetAutoPlayPeriod_ && autoAndRepeatLevel_ == PlaybackMode::AUTO) {
isSetAutoPlayPeriod_ = true;
SetAutoPlayPeriod(autoPlayPeriodStartTime_, autoPlayPeriodEndTime_);
}
@ -799,7 +799,7 @@ void MovingPhotoPattern::HideImageNode()
void MovingPhotoPattern::VisiblePlayback()
{
TAG_LOGI(AceLogTag::ACE_MOVING_PHOTO, "movingphoto VisiblePlayback.");
if (isVisible_) {
if (!isVisible_) {
return;
}
if (historyAutoAndRepeatLevel_ != PlaybackMode::NONE &&
@ -1017,17 +1017,21 @@ void MovingPhotoPattern::RepeatPlay(bool isRepeatPlay)
void MovingPhotoPattern::AutoPlayPeriod(int64_t startTime, int64_t endTime)
{
if (startTime > VIDEO_PLAYTIME_START_POSITION && startTime < endTime
&& endTime < VIDEO_PLAYTIME_END_POSITION) {
TAG_LOGW(AceLogTag::ACE_MOVING_PHOTO, "MediaPlayer set Period error.");
return;
if (startTime >= VIDEO_PLAYTIME_START_POSITION && startTime < endTime
&& endTime <= VIDEO_PLAYTIME_END_POSITION) {
TAG_LOGW(AceLogTag::ACE_MOVING_PHOTO, "MediaPlayer set Period.");
autoPlayPeriodStartTime_ = startTime;
autoPlayPeriodEndTime_ = endTime;
}
autoPlayPeriodStartTime_ = startTime;
autoPlayPeriodEndTime_ = endTime;
}
void MovingPhotoPattern::SetAutoPlayPeriod(int64_t startTime, int64_t endTime)
{
if (startTime < VIDEO_PLAYTIME_START_POSITION || startTime >= endTime
|| endTime > VIDEO_PLAYTIME_END_POSITION) {
TAG_LOGW(AceLogTag::ACE_MOVING_PHOTO, "MediaPlayer SetAutoPlayPeriod error.");
return;
}
if (!mediaPlayer_ || !mediaPlayer_->IsMediaPlayerValid()) {
TAG_LOGW(AceLogTag::ACE_MOVING_PHOTO, "MediaPlayer is null or invalid.");
return;

View File

@ -85,15 +85,15 @@ class MovingPhotoView extends JSViewAbstract {
}
static autoPlayPeriod(startTime, endTime) {
__Common__.remoteMessage(startTime, endTime);
__MovingPhotoView__.autoPlayPeriod(startTime, endTime);
}
static autoPlay(value) {
__Common__.autoPlay(value);
__MovingPhotoView__.autoPlay(value);
}
static repeatPlay(value) {
__Common__.loop(value);
__MovingPhotoView__.repeatPlay(value);
}
}