• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bridge/declarative_frontend/jsview/models/video_model_impl.h"
17 
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 #include "core/components/video/video_component_v2.h"
20 
21 namespace OHOS::Ace::Framework {
22 
Create(const RefPtr<VideoControllerV2> & videoController)23 void VideoModelImpl::Create(const RefPtr<VideoControllerV2>& videoController)
24 {
25     auto* stack = ViewStackProcessor::GetInstance();
26     auto videoComponent = AceType::MakeRefPtr<OHOS::Ace::VideoComponentV2>();
27     videoComponent->SetSaveComponentEvent([videoComponent](std::unordered_map<std::string, RefPtr<Component>> map) {
28         videoComponent->SetGestureComponentMap(std::move(map));
29     });
30     if (AceApplicationInfo::GetInstance().IsRightToLeft()) {
31         videoComponent->SetTextDirection(TextDirection::RTL);
32     }
33 
34     ViewStackProcessor::GetInstance()->ClaimElementId(videoComponent);
35     ViewStackProcessor::GetInstance()->Push(videoComponent);
36 
37     if (videoController) {
38         videoComponent->SetVideoControllerV2(videoController);
39     }
40     stack->GetFlexItemComponent();
41 }
42 
SetSrc(const std::string & src)43 void VideoModelImpl::SetSrc(const std::string& src)
44 {
45     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
46     CHECK_NULL_VOID(videoComponent);
47     videoComponent->SetSrc(src);
48 }
49 
SetProgressRate(double progressRate)50 void VideoModelImpl::SetProgressRate(double progressRate)
51 {
52     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
53     CHECK_NULL_VOID(videoComponent);
54     videoComponent->SetSpeed(static_cast<float>(progressRate));
55 }
56 
SetPosterSourceInfo(const std::string & posterUrl)57 void VideoModelImpl::SetPosterSourceInfo(const std::string& posterUrl)
58 {
59     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
60     CHECK_NULL_VOID(videoComponent);
61     videoComponent->SetPoster(posterUrl);
62 }
63 
SetPosterSourceByPixelMap(RefPtr<PixelMap> & pixMap)64 void VideoModelImpl::SetPosterSourceByPixelMap(RefPtr<PixelMap>& pixMap)
65 {
66     LOGW("Pixelmap is not supported.");
67 }
68 
SetMuted(bool muted)69 void VideoModelImpl::SetMuted(bool muted)
70 {
71     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
72     CHECK_NULL_VOID(videoComponent);
73     videoComponent->SetMute(muted);
74 }
75 
SetAutoPlay(bool autoPlay)76 void VideoModelImpl::SetAutoPlay(bool autoPlay)
77 {
78     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
79     CHECK_NULL_VOID(videoComponent);
80     videoComponent->SetAutoPlay(autoPlay);
81 }
82 
SetControls(bool controls)83 void VideoModelImpl::SetControls(bool controls)
84 {
85     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
86     CHECK_NULL_VOID(videoComponent);
87     videoComponent->SetNeedControls(controls);
88 }
89 
SetObjectFit(ImageFit objectFit)90 void VideoModelImpl::SetObjectFit(ImageFit objectFit)
91 {
92     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
93     CHECK_NULL_VOID(videoComponent);
94     videoComponent->SetFit(objectFit);
95 }
96 
SetLoop(bool loop)97 void VideoModelImpl::SetLoop(bool loop)
98 {
99     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
100     CHECK_NULL_VOID(videoComponent);
101     videoComponent->SetLoop(loop);
102 }
103 
SetOnStart(VideoEventFunc && onStart)104 void VideoModelImpl::SetOnStart(VideoEventFunc&& onStart)
105 {
106     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
107     CHECK_NULL_VOID(videoComponent);
108     videoComponent->SetStartEventId(
109         EventMarker([func = std::move(onStart)](const std::string& param) { func(param); }));
110 }
111 
SetOnPause(VideoEventFunc && onPause)112 void VideoModelImpl::SetOnPause(VideoEventFunc&& onPause)
113 {
114     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
115     CHECK_NULL_VOID(videoComponent);
116     videoComponent->SetPauseEventId(
117         EventMarker([func = std::move(onPause)](const std::string& param) { func(param); }));
118 }
119 
SetOnFinish(VideoEventFunc && onFinish)120 void VideoModelImpl::SetOnFinish(VideoEventFunc&& onFinish)
121 {
122     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
123     CHECK_NULL_VOID(videoComponent);
124     videoComponent->SetFinishEventId(
125         EventMarker([func = std::move(onFinish)](const std::string& param) { func(param); }));
126 }
127 
SetOnError(VideoEventFunc && onError)128 void VideoModelImpl::SetOnError(VideoEventFunc&& onError)
129 {
130     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
131     CHECK_NULL_VOID(videoComponent);
132     videoComponent->SetErrorEventId(
133         EventMarker([func = std::move(onError)](const std::string& param) { func(param); }));
134 }
135 
SetOnPrepared(VideoEventFunc && onPrepared)136 void VideoModelImpl::SetOnPrepared(VideoEventFunc&& onPrepared)
137 {
138     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
139     CHECK_NULL_VOID(videoComponent);
140     videoComponent->SetPreparedEventId(
141         EventMarker([func = std::move(onPrepared)](const std::string& param) { func(param); }));
142 }
143 
SetOnSeeking(VideoEventFunc && onSeeking)144 void VideoModelImpl::SetOnSeeking(VideoEventFunc&& onSeeking)
145 {
146     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
147     CHECK_NULL_VOID(videoComponent);
148     videoComponent->SetSeekingEventId(
149         EventMarker([func = std::move(onSeeking)](const std::string& param) { func(param); }));
150 }
151 
SetOnSeeked(VideoEventFunc && onSeeked)152 void VideoModelImpl::SetOnSeeked(VideoEventFunc&& onSeeked)
153 {
154     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
155     CHECK_NULL_VOID(videoComponent);
156     videoComponent->SetSeekedEventId(
157         EventMarker([func = std::move(onSeeked)](const std::string& param) { func(param); }));
158 }
159 
SetOnUpdate(VideoEventFunc && onUpdate)160 void VideoModelImpl::SetOnUpdate(VideoEventFunc&& onUpdate)
161 {
162     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
163     CHECK_NULL_VOID(videoComponent);
164     videoComponent->SetTimeUpdateEventId(
165         EventMarker([func = std::move(onUpdate)](const std::string& param) { func(param); }));
166 }
167 
SetOnFullScreenChange(VideoEventFunc && onFullScreenChange)168 void VideoModelImpl::SetOnFullScreenChange(VideoEventFunc&& onFullScreenChange)
169 {
170     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
171     CHECK_NULL_VOID(videoComponent);
172     videoComponent->SetFullscreenChangeEventId(
173         EventMarker([func = std::move(onFullScreenChange)](const std::string& param) { func(param); }));
174 }
175 
176 } // namespace OHOS::Ace::Framework
177