• 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,const std::string & bundleName,const std::string & moduleName)57 void VideoModelImpl::SetPosterSourceInfo(const std::string& posterUrl, const std::string &bundleName,
58     const std::string &moduleName)
59 {
60     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
61     CHECK_NULL_VOID(videoComponent);
62     videoComponent->SetPoster(posterUrl);
63 }
64 
SetPosterSourceByPixelMap(RefPtr<PixelMap> & pixMap)65 void VideoModelImpl::SetPosterSourceByPixelMap(RefPtr<PixelMap>& pixMap)
66 {
67     LOGW("Pixelmap is not supported.");
68 }
69 
SetMuted(bool muted)70 void VideoModelImpl::SetMuted(bool muted)
71 {
72     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
73     CHECK_NULL_VOID(videoComponent);
74     videoComponent->SetMute(muted);
75 }
76 
SetAutoPlay(bool autoPlay)77 void VideoModelImpl::SetAutoPlay(bool autoPlay)
78 {
79     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
80     CHECK_NULL_VOID(videoComponent);
81     videoComponent->SetAutoPlay(autoPlay);
82 }
83 
SetControls(bool controls)84 void VideoModelImpl::SetControls(bool controls)
85 {
86     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
87     CHECK_NULL_VOID(videoComponent);
88     videoComponent->SetNeedControls(controls);
89 }
90 
SetObjectFit(ImageFit objectFit)91 void VideoModelImpl::SetObjectFit(ImageFit objectFit)
92 {
93     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
94     CHECK_NULL_VOID(videoComponent);
95     videoComponent->SetFit(objectFit);
96 }
97 
SetLoop(bool loop)98 void VideoModelImpl::SetLoop(bool loop)
99 {
100     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
101     CHECK_NULL_VOID(videoComponent);
102     videoComponent->SetLoop(loop);
103 }
104 
SetOnStart(VideoEventFunc && onStart)105 void VideoModelImpl::SetOnStart(VideoEventFunc&& onStart)
106 {
107     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
108     CHECK_NULL_VOID(videoComponent);
109     videoComponent->SetStartEventId(
110         EventMarker([func = std::move(onStart)](const std::string& param) { func(param); }));
111 }
112 
SetOnPause(VideoEventFunc && onPause)113 void VideoModelImpl::SetOnPause(VideoEventFunc&& onPause)
114 {
115     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
116     CHECK_NULL_VOID(videoComponent);
117     videoComponent->SetPauseEventId(
118         EventMarker([func = std::move(onPause)](const std::string& param) { func(param); }));
119 }
120 
SetOnFinish(VideoEventFunc && onFinish)121 void VideoModelImpl::SetOnFinish(VideoEventFunc&& onFinish)
122 {
123     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
124     CHECK_NULL_VOID(videoComponent);
125     videoComponent->SetFinishEventId(
126         EventMarker([func = std::move(onFinish)](const std::string& param) { func(param); }));
127 }
128 
SetOnError(VideoEventFunc && onError)129 void VideoModelImpl::SetOnError(VideoEventFunc&& onError)
130 {
131     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
132     CHECK_NULL_VOID(videoComponent);
133     videoComponent->SetErrorEventId(
134         EventMarker([func = std::move(onError)](const std::string& param) { func(param); }));
135 }
136 
SetOnPrepared(VideoEventFunc && onPrepared)137 void VideoModelImpl::SetOnPrepared(VideoEventFunc&& onPrepared)
138 {
139     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
140     CHECK_NULL_VOID(videoComponent);
141     videoComponent->SetPreparedEventId(
142         EventMarker([func = std::move(onPrepared)](const std::string& param) { func(param); }));
143 }
144 
SetOnSeeking(VideoEventFunc && onSeeking)145 void VideoModelImpl::SetOnSeeking(VideoEventFunc&& onSeeking)
146 {
147     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
148     CHECK_NULL_VOID(videoComponent);
149     videoComponent->SetSeekingEventId(
150         EventMarker([func = std::move(onSeeking)](const std::string& param) { func(param); }));
151 }
152 
SetOnSeeked(VideoEventFunc && onSeeked)153 void VideoModelImpl::SetOnSeeked(VideoEventFunc&& onSeeked)
154 {
155     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
156     CHECK_NULL_VOID(videoComponent);
157     videoComponent->SetSeekedEventId(
158         EventMarker([func = std::move(onSeeked)](const std::string& param) { func(param); }));
159 }
160 
SetOnUpdate(VideoEventFunc && onUpdate)161 void VideoModelImpl::SetOnUpdate(VideoEventFunc&& onUpdate)
162 {
163     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
164     CHECK_NULL_VOID(videoComponent);
165     videoComponent->SetTimeUpdateEventId(
166         EventMarker([func = std::move(onUpdate)](const std::string& param) { func(param); }));
167 }
168 
SetOnFullScreenChange(VideoEventFunc && onFullScreenChange)169 void VideoModelImpl::SetOnFullScreenChange(VideoEventFunc&& onFullScreenChange)
170 {
171     auto videoComponent = AceType::DynamicCast<VideoComponentV2>(ViewStackProcessor::GetInstance()->GetMainComponent());
172     CHECK_NULL_VOID(videoComponent);
173     videoComponent->SetFullscreenChangeEventId(
174         EventMarker([func = std::move(onFullScreenChange)](const std::string& param) { func(param); }));
175 }
176 } // namespace OHOS::Ace::Framework
177