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