1a3e0fd82Sopenharmony_ci/*
2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License.
5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at
6a3e0fd82Sopenharmony_ci *
7a3e0fd82Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a3e0fd82Sopenharmony_ci *
9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and
13a3e0fd82Sopenharmony_ci * limitations under the License.
14a3e0fd82Sopenharmony_ci */
15a3e0fd82Sopenharmony_ci
16a3e0fd82Sopenharmony_ci/**
17a3e0fd82Sopenharmony_ci * @addtogroup UI_Components
18a3e0fd82Sopenharmony_ci * @{
19a3e0fd82Sopenharmony_ci *
20a3e0fd82Sopenharmony_ci * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
21a3e0fd82Sopenharmony_ci *
22a3e0fd82Sopenharmony_ci * @since 5.0
23a3e0fd82Sopenharmony_ci * @version 3.0
24a3e0fd82Sopenharmony_ci */
25a3e0fd82Sopenharmony_ci
26a3e0fd82Sopenharmony_ci/**
27a3e0fd82Sopenharmony_ci * @file ui_video.h
28a3e0fd82Sopenharmony_ci *
29a3e0fd82Sopenharmony_ci * @brief Declares the functions related to video playbacks.
30a3e0fd82Sopenharmony_ci *
31a3e0fd82Sopenharmony_ci * @since 5.0
32a3e0fd82Sopenharmony_ci * @version 3.0
33a3e0fd82Sopenharmony_ci */
34a3e0fd82Sopenharmony_ci
35a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_VIDEO_H
36a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_VIDEO_H
37a3e0fd82Sopenharmony_ci
38a3e0fd82Sopenharmony_ci#include "animator/animator.h"
39a3e0fd82Sopenharmony_ci#include "components/ui_label.h"
40a3e0fd82Sopenharmony_ci#include "components/ui_slider.h"
41a3e0fd82Sopenharmony_ci#include "components/ui_surface_view.h"
42a3e0fd82Sopenharmony_ci#include "components/ui_toggle_button.h"
43a3e0fd82Sopenharmony_ci#include "components/ui_view_group.h"
44a3e0fd82Sopenharmony_ci#include "player.h"
45a3e0fd82Sopenharmony_ci
46a3e0fd82Sopenharmony_ci#ifndef VERSION_LITE
47a3e0fd82Sopenharmony_cinamespace OHOS {
48a3e0fd82Sopenharmony_ciusing namespace OHOS::Media;
49a3e0fd82Sopenharmony_ci/**
50a3e0fd82Sopenharmony_ci * @brief Provides the functions related to video playbacks.
51a3e0fd82Sopenharmony_ci *
52a3e0fd82Sopenharmony_ci * @since 5.0
53a3e0fd82Sopenharmony_ci * @version 3.0
54a3e0fd82Sopenharmony_ci */
55a3e0fd82Sopenharmony_ciclass UIVideo : public UIViewGroup,
56a3e0fd82Sopenharmony_ci                public UIView::OnClickListener,
57a3e0fd82Sopenharmony_ci                public UIView::OnTouchListener,
58a3e0fd82Sopenharmony_ci                public UISlider::UISliderEventListener {
59a3e0fd82Sopenharmony_cipublic:
60a3e0fd82Sopenharmony_ci    /**
61a3e0fd82Sopenharmony_ci     * @brief A constructor used to create a <b>UIVideo</b> instance for playback.
62a3e0fd82Sopenharmony_ci     *
63a3e0fd82Sopenharmony_ci     * @since 5.0
64a3e0fd82Sopenharmony_ci     * @version 3.0
65a3e0fd82Sopenharmony_ci     */
66a3e0fd82Sopenharmony_ci    UIVideo();
67a3e0fd82Sopenharmony_ci
68a3e0fd82Sopenharmony_ci    /**
69a3e0fd82Sopenharmony_ci     * @brief A destructor used to delete the <b>UIVideo</b> instance for playback.
70a3e0fd82Sopenharmony_ci     *
71a3e0fd82Sopenharmony_ci     * @since 5.0
72a3e0fd82Sopenharmony_ci     * @version 3.0
73a3e0fd82Sopenharmony_ci     */
74a3e0fd82Sopenharmony_ci    virtual ~UIVideo();
75a3e0fd82Sopenharmony_ci
76a3e0fd82Sopenharmony_ci    /**
77a3e0fd82Sopenharmony_ci     * @brief Sets the source file to be played.
78a3e0fd82Sopenharmony_ci     *
79a3e0fd82Sopenharmony_ci     * @param source Indicates the pointer to the source file path.
80a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
81a3e0fd82Sopenharmony_ci     * @since 5.0
82a3e0fd82Sopenharmony_ci     * @version 3.0
83a3e0fd82Sopenharmony_ci     */
84a3e0fd82Sopenharmony_ci    bool SetSrc(const char* source);
85a3e0fd82Sopenharmony_ci
86a3e0fd82Sopenharmony_ci    /**
87a3e0fd82Sopenharmony_ci     * @brief Obtains the path of the source file to be played.
88a3e0fd82Sopenharmony_ci     *
89a3e0fd82Sopenharmony_ci     * @return Returns the path of the source file to be played.
90a3e0fd82Sopenharmony_ci     * @since 5.0
91a3e0fd82Sopenharmony_ci     * @version 3.0
92a3e0fd82Sopenharmony_ci     */
93a3e0fd82Sopenharmony_ci    const char* GetSrc()
94a3e0fd82Sopenharmony_ci    {
95a3e0fd82Sopenharmony_ci        return src_;
96a3e0fd82Sopenharmony_ci    }
97a3e0fd82Sopenharmony_ci
98a3e0fd82Sopenharmony_ci    /**
99a3e0fd82Sopenharmony_ci     * @brief Prepares for the playback. You must call this function after {@link SetSource}.
100a3e0fd82Sopenharmony_ci     *
101a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the preparation is successful; returns <b>false</b> otherwise.
102a3e0fd82Sopenharmony_ci     * @since 5.0
103a3e0fd82Sopenharmony_ci     * @version 3.0
104a3e0fd82Sopenharmony_ci     */
105a3e0fd82Sopenharmony_ci    bool Prepare();
106a3e0fd82Sopenharmony_ci
107a3e0fd82Sopenharmony_ci    /**
108a3e0fd82Sopenharmony_ci     * @brief Plays this video.
109a3e0fd82Sopenharmony_ci     *
110a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if this video is played; returns <b>false</b> otherwise.
111a3e0fd82Sopenharmony_ci     * @since 5.0
112a3e0fd82Sopenharmony_ci     * @version 3.0
113a3e0fd82Sopenharmony_ci     */
114a3e0fd82Sopenharmony_ci    bool Play();
115a3e0fd82Sopenharmony_ci
116a3e0fd82Sopenharmony_ci    /**
117a3e0fd82Sopenharmony_ci     * @brief Checks whether this video is playing.
118a3e0fd82Sopenharmony_ci     *
119a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if this video is playing; returns <b>false</b> otherwise.
120a3e0fd82Sopenharmony_ci     * @since 5.0
121a3e0fd82Sopenharmony_ci     * @version 3.0
122a3e0fd82Sopenharmony_ci     */
123a3e0fd82Sopenharmony_ci    bool IsPlaying();
124a3e0fd82Sopenharmony_ci
125a3e0fd82Sopenharmony_ci    /**
126a3e0fd82Sopenharmony_ci     * @brief Pauses the video being played.
127a3e0fd82Sopenharmony_ci     *
128a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the video is paused; returns <b>false</b> otherwise.
129a3e0fd82Sopenharmony_ci     * @since 5.0
130a3e0fd82Sopenharmony_ci     * @version 3.0
131a3e0fd82Sopenharmony_ci     */
132a3e0fd82Sopenharmony_ci    bool Pause();
133a3e0fd82Sopenharmony_ci
134a3e0fd82Sopenharmony_ci    /**
135a3e0fd82Sopenharmony_ci     * @brief Stops playing this video.
136a3e0fd82Sopenharmony_ci     *
137a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if this video is stopped; returns <b>false</b> otherwise.
138a3e0fd82Sopenharmony_ci     * @since 5.0
139a3e0fd82Sopenharmony_ci     * @version 3.0
140a3e0fd82Sopenharmony_ci     */
141a3e0fd82Sopenharmony_ci    bool Stop();
142a3e0fd82Sopenharmony_ci
143a3e0fd82Sopenharmony_ci    /**
144a3e0fd82Sopenharmony_ci     * @brief Changes the playback position.
145a3e0fd82Sopenharmony_ci     *
146a3e0fd82Sopenharmony_ci     * @param mSeconds Indicates the target playback position, in milliseconds.
147a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the playback position is changed; returns <b>false</b> otherwise.
148a3e0fd82Sopenharmony_ci     * @since 5.0
149a3e0fd82Sopenharmony_ci     * @version 3.0
150a3e0fd82Sopenharmony_ci     */
151a3e0fd82Sopenharmony_ci    bool Rewind(int64_t mSeconds);
152a3e0fd82Sopenharmony_ci
153a3e0fd82Sopenharmony_ci    /**
154a3e0fd82Sopenharmony_ci     * @brief Sets the playback volume.
155a3e0fd82Sopenharmony_ci     *
156a3e0fd82Sopenharmony_ci     * @param Indicates the volume of the left audio channel to set, ranging from <b>0</b> to <b>100</b>.
157a3e0fd82Sopenharmony_ci     * @param rightVolume Indicates the volume of the right audio channel to set, ranging from <b>0</b> to <b>1</b>.
158a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
159a3e0fd82Sopenharmony_ci     * @since 5.0
160a3e0fd82Sopenharmony_ci     * @version 3.0
161a3e0fd82Sopenharmony_ci     */
162a3e0fd82Sopenharmony_ci    bool SetVolume(float leftVolume, float rightVolume);
163a3e0fd82Sopenharmony_ci
164a3e0fd82Sopenharmony_ci    /**
165a3e0fd82Sopenharmony_ci     * @brief Sets whether to loop playback.
166a3e0fd82Sopenharmony_ci     *
167a3e0fd82Sopenharmony_ci     * @param loop Specifies whether to loop playback. The value <b>true</b> means that the playback loops,
168a3e0fd82Sopenharmony_ci     *             and <b>false</b> means the opposite case.
169a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the setting is successful; returns <b>false</b> otherwise.
170a3e0fd82Sopenharmony_ci     * @since 5.0
171a3e0fd82Sopenharmony_ci     * @version 3.0
172a3e0fd82Sopenharmony_ci     */
173a3e0fd82Sopenharmony_ci    bool EnableSingleLooping(bool loop);
174a3e0fd82Sopenharmony_ci
175a3e0fd82Sopenharmony_ci    /**
176a3e0fd82Sopenharmony_ci     * @brief Checks whether the playback loops.
177a3e0fd82Sopenharmony_ci     *
178a3e0fd82Sopenharmony_ci     * @return Returns <b> true</b> if the playback loops; returns <b>false</b> otherwise.
179a3e0fd82Sopenharmony_ci     * @since 5.0
180a3e0fd82Sopenharmony_ci     * @version 3.0
181a3e0fd82Sopenharmony_ci     */
182a3e0fd82Sopenharmony_ci    bool IsSingleLooping();
183a3e0fd82Sopenharmony_ci
184a3e0fd82Sopenharmony_ci    /**
185a3e0fd82Sopenharmony_ci     * @brief Obtains the current playback time.
186a3e0fd82Sopenharmony_ci     *
187a3e0fd82Sopenharmony_ci     * @param time Indicates the current playback time, in milliseconds.
188a3e0fd82Sopenharmony_ci     * @return Returns <b> true</b> if the operation is successful; returns <b>false</b> otherwise.
189a3e0fd82Sopenharmony_ci     * @since 5.0
190a3e0fd82Sopenharmony_ci     * @version 3.0
191a3e0fd82Sopenharmony_ci     */
192a3e0fd82Sopenharmony_ci    bool GetCurrentTime(int64_t& time);
193a3e0fd82Sopenharmony_ci
194a3e0fd82Sopenharmony_ci    /**
195a3e0fd82Sopenharmony_ci     * @brief Obtains the total video duration.
196a3e0fd82Sopenharmony_ci     *
197a3e0fd82Sopenharmony_ci     * @param duration Indicates the total duration, in milliseconds.
198a3e0fd82Sopenharmony_ci     * @return Returns <b> true</b> if the duration is obtained; returns <b>false</b> otherwise.
199a3e0fd82Sopenharmony_ci     * @since 5.0
200a3e0fd82Sopenharmony_ci     * @version 3.0
201a3e0fd82Sopenharmony_ci     */
202a3e0fd82Sopenharmony_ci    bool GetDuration(int64_t& duration);
203a3e0fd82Sopenharmony_ci
204a3e0fd82Sopenharmony_ci    /**
205a3e0fd82Sopenharmony_ci     * @brief Resets the player to the initial state.
206a3e0fd82Sopenharmony_ci     *
207a3e0fd82Sopenharmony_ci     * @return Returns <b>true</b> if the player is reset; returns <b>false</b> otherwise.
208a3e0fd82Sopenharmony_ci     * @since 5.0
209a3e0fd82Sopenharmony_ci     * @version 3.0
210a3e0fd82Sopenharmony_ci     */
211a3e0fd82Sopenharmony_ci    bool Reset();
212a3e0fd82Sopenharmony_ci
213a3e0fd82Sopenharmony_ci    /**
214a3e0fd82Sopenharmony_ci     * @brief Sets whether to show the playback controller.
215a3e0fd82Sopenharmony_ci     *
216a3e0fd82Sopenharmony_ci     * @param show Specifies whether to show the playback controller. The value <b>true</b> means showing
217a3e0fd82Sopenharmony_ci     *             the playback controller, and <b>false</b> means the opposite case.
218a3e0fd82Sopenharmony_ci     * @since 5.0
219a3e0fd82Sopenharmony_ci     * @version 3.0
220a3e0fd82Sopenharmony_ci     */
221a3e0fd82Sopenharmony_ci    void ShowController(bool show);
222a3e0fd82Sopenharmony_ci
223a3e0fd82Sopenharmony_ci    /**
224a3e0fd82Sopenharmony_ci     * @brief Provides callbacks for events that occur during video playback.
225a3e0fd82Sopenharmony_ci     *
226a3e0fd82Sopenharmony_ci     * @since 5.0
227a3e0fd82Sopenharmony_ci     * @version 3.0
228a3e0fd82Sopenharmony_ci     */
229a3e0fd82Sopenharmony_ci    class VideoPlayerListener {
230a3e0fd82Sopenharmony_ci    public:
231a3e0fd82Sopenharmony_ci        /**
232a3e0fd82Sopenharmony_ci         * @brief A constructor used to create a <b>VideoPlayerListener</b> instance.
233a3e0fd82Sopenharmony_ci         *
234a3e0fd82Sopenharmony_ci         * @since 5.0
235a3e0fd82Sopenharmony_ci         * @version 3.0
236a3e0fd82Sopenharmony_ci         */
237a3e0fd82Sopenharmony_ci        VideoPlayerListener() {}
238a3e0fd82Sopenharmony_ci
239a3e0fd82Sopenharmony_ci        /**
240a3e0fd82Sopenharmony_ci         * @brief A destructor used to delete the <b>VideoPlayerListener</b> instance.
241a3e0fd82Sopenharmony_ci         *
242a3e0fd82Sopenharmony_ci         * @since 5.0
243a3e0fd82Sopenharmony_ci         * @version 3.0
244a3e0fd82Sopenharmony_ci         */
245a3e0fd82Sopenharmony_ci        virtual ~VideoPlayerListener() {}
246a3e0fd82Sopenharmony_ci
247a3e0fd82Sopenharmony_ci        /**
248a3e0fd82Sopenharmony_ci         * @brief Called when the playback is complete.
249a3e0fd82Sopenharmony_ci         *
250a3e0fd82Sopenharmony_ci         * @since 5.0
251a3e0fd82Sopenharmony_ci         * @version 3.0
252a3e0fd82Sopenharmony_ci         */
253a3e0fd82Sopenharmony_ci        virtual void OnPlaybackComplete() {}
254a3e0fd82Sopenharmony_ci
255a3e0fd82Sopenharmony_ci        /**
256a3e0fd82Sopenharmony_ci         * @brief Called when a video playback error occurs.
257a3e0fd82Sopenharmony_ci         *
258a3e0fd82Sopenharmony_ci         * @param errorType Indicates the error type.
259a3e0fd82Sopenharmony_ci         * @param eerrorCode Indicates the error code.
260a3e0fd82Sopenharmony_ci         * @since 5.0
261a3e0fd82Sopenharmony_ci         * @version 3.0
262a3e0fd82Sopenharmony_ci         */
263a3e0fd82Sopenharmony_ci        virtual void OnError(int32_t errorType, int32_t errorCode) {}
264a3e0fd82Sopenharmony_ci
265a3e0fd82Sopenharmony_ci        /**
266a3e0fd82Sopenharmony_ci         * @brief Called when playback information is received.
267a3e0fd82Sopenharmony_ci         *
268a3e0fd82Sopenharmony_ci         * @param type Indicates the information type.
269a3e0fd82Sopenharmony_ci         * @param extra Indicates the information code.
270a3e0fd82Sopenharmony_ci         * @since 5.0
271a3e0fd82Sopenharmony_ci         * @version 3.0
272a3e0fd82Sopenharmony_ci         */
273a3e0fd82Sopenharmony_ci        virtual void OnInfo(int32_t type, int32_t extra) {}
274a3e0fd82Sopenharmony_ci
275a3e0fd82Sopenharmony_ci        /**
276a3e0fd82Sopenharmony_ci         * @brief Called when the video image size changes.
277a3e0fd82Sopenharmony_ci         *
278a3e0fd82Sopenharmony_ci         * @param width Indicates the video width.
279a3e0fd82Sopenharmony_ci         * @param height Indicates the video height.
280a3e0fd82Sopenharmony_ci         * @since 5.0
281a3e0fd82Sopenharmony_ci         * @version 3.0
282a3e0fd82Sopenharmony_ci         */
283a3e0fd82Sopenharmony_ci        virtual void OnVideoSizeChanged(int32_t width, int32_t height) {}
284a3e0fd82Sopenharmony_ci
285a3e0fd82Sopenharmony_ci        /**
286a3e0fd82Sopenharmony_ci         * @brief Called when this video is rewound.
287a3e0fd82Sopenharmony_ci         *
288a3e0fd82Sopenharmony_ci         * @since 5.0
289a3e0fd82Sopenharmony_ci         * @version 3.0
290a3e0fd82Sopenharmony_ci         */
291a3e0fd82Sopenharmony_ci        virtual void OnRewindToComplete() {}
292a3e0fd82Sopenharmony_ci
293a3e0fd82Sopenharmony_ci        /**
294a3e0fd82Sopenharmony_ci         * @brief Called when this video is paused.
295a3e0fd82Sopenharmony_ci         *
296a3e0fd82Sopenharmony_ci         * @since 5.0
297a3e0fd82Sopenharmony_ci         * @version 3.0
298a3e0fd82Sopenharmony_ci         */
299a3e0fd82Sopenharmony_ci        virtual void OnPlaybackPause() {}
300a3e0fd82Sopenharmony_ci
301a3e0fd82Sopenharmony_ci        /**
302a3e0fd82Sopenharmony_ci         * @brief Called when this video is played.
303a3e0fd82Sopenharmony_ci         *
304a3e0fd82Sopenharmony_ci         * @since 5.0
305a3e0fd82Sopenharmony_ci         * @version 3.0
306a3e0fd82Sopenharmony_ci         */
307a3e0fd82Sopenharmony_ci        virtual void OnPlaybackPlay() {}
308a3e0fd82Sopenharmony_ci
309a3e0fd82Sopenharmony_ci        /**
310a3e0fd82Sopenharmony_ci         * @brief Called when this video is stopped.
311a3e0fd82Sopenharmony_ci         *
312a3e0fd82Sopenharmony_ci         * @since 5.0
313a3e0fd82Sopenharmony_ci         * @version 3.0
314a3e0fd82Sopenharmony_ci         */
315a3e0fd82Sopenharmony_ci        virtual void OnPlaybackStop() {}
316a3e0fd82Sopenharmony_ci    };
317a3e0fd82Sopenharmony_ci
318a3e0fd82Sopenharmony_ci    /**
319a3e0fd82Sopenharmony_ci     * @brief Sets a listener for monitoring video playbacks.
320a3e0fd82Sopenharmony_ci     *
321a3e0fd82Sopenharmony_ci     * @param listener Indicates the pointer to the listener to set.
322a3e0fd82Sopenharmony_ci     * @since 5.0
323a3e0fd82Sopenharmony_ci     * @version 3.0
324a3e0fd82Sopenharmony_ci     */
325a3e0fd82Sopenharmony_ci    void SetVideoPlayerListener(VideoPlayerListener* listener);
326a3e0fd82Sopenharmony_ci
327a3e0fd82Sopenharmony_ciprivate:
328a3e0fd82Sopenharmony_ci    class SliderAnimatorCallback : public AnimatorCallback {
329a3e0fd82Sopenharmony_ci    public:
330a3e0fd82Sopenharmony_ci        SliderAnimatorCallback(UIVideo* video, UISlider* slider, UILabel* label)
331a3e0fd82Sopenharmony_ci        {
332a3e0fd82Sopenharmony_ci            video_ = video;
333a3e0fd82Sopenharmony_ci            slider_ = slider;
334a3e0fd82Sopenharmony_ci            timeLabel_ = label;
335a3e0fd82Sopenharmony_ci        }
336a3e0fd82Sopenharmony_ci
337a3e0fd82Sopenharmony_ci        virtual ~SliderAnimatorCallback() {}
338a3e0fd82Sopenharmony_ci        void Callback(UIView* view) override;
339a3e0fd82Sopenharmony_ci        void SetPlayButton(UIToggleButton* toggleButton)
340a3e0fd82Sopenharmony_ci        {
341a3e0fd82Sopenharmony_ci            playButton_ = toggleButton;
342a3e0fd82Sopenharmony_ci        }
343a3e0fd82Sopenharmony_ci
344a3e0fd82Sopenharmony_ci        void SetSliderAnimator(Animator* animator)
345a3e0fd82Sopenharmony_ci        {
346a3e0fd82Sopenharmony_ci            sliderAnimator_ = animator;
347a3e0fd82Sopenharmony_ci        }
348a3e0fd82Sopenharmony_ci
349a3e0fd82Sopenharmony_ci        void SetDuration(int64_t duration)
350a3e0fd82Sopenharmony_ci        {
351a3e0fd82Sopenharmony_ci            duration_ = duration;
352a3e0fd82Sopenharmony_ci        }
353a3e0fd82Sopenharmony_ci
354a3e0fd82Sopenharmony_ci        void ResetTickTime()
355a3e0fd82Sopenharmony_ci        {
356a3e0fd82Sopenharmony_ci            if (sliderAnimator_ != nullptr) {
357a3e0fd82Sopenharmony_ci                tickCount_ = sliderAnimator_->GetRunTime();
358a3e0fd82Sopenharmony_ci            }
359a3e0fd82Sopenharmony_ci        }
360a3e0fd82Sopenharmony_ci
361a3e0fd82Sopenharmony_ci        friend class UIVideo;
362a3e0fd82Sopenharmony_ci    private:
363a3e0fd82Sopenharmony_ci        uint32_t tickCount_ = 0;
364a3e0fd82Sopenharmony_ci        int64_t duration_ = 0;
365a3e0fd82Sopenharmony_ci        UIVideo* video_ = nullptr;
366a3e0fd82Sopenharmony_ci        UISlider* slider_ = nullptr;
367a3e0fd82Sopenharmony_ci        UILabel* timeLabel_ = nullptr;
368a3e0fd82Sopenharmony_ci        UIToggleButton* playButton_ = nullptr;
369a3e0fd82Sopenharmony_ci        Animator* sliderAnimator_ = nullptr;
370a3e0fd82Sopenharmony_ci    };
371a3e0fd82Sopenharmony_ci
372a3e0fd82Sopenharmony_ci    void InitVideo();
373a3e0fd82Sopenharmony_ci    void InitControllerLabel();
374a3e0fd82Sopenharmony_ci    void InitControllerButton();
375a3e0fd82Sopenharmony_ci    void InitControllerSlider();
376a3e0fd82Sopenharmony_ci    void DeleteController();
377a3e0fd82Sopenharmony_ci    void SetSurfaceInfo();
378a3e0fd82Sopenharmony_ci    void OnVideoComplete();
379a3e0fd82Sopenharmony_ci    bool GetTimerFromMSecond(int64_t currentTime, char* timer, int32_t len);
380a3e0fd82Sopenharmony_ci
381a3e0fd82Sopenharmony_ci    bool OnClick(UIView& view, const ClickEvent& event) override;
382a3e0fd82Sopenharmony_ci    bool OnPress(UIView& view, const PressEvent& event) override;
383a3e0fd82Sopenharmony_ci    void OnChange(int32_t progress) override;
384a3e0fd82Sopenharmony_ci
385a3e0fd82Sopenharmony_ci    class PlayerListener : public Media::PlayerCallback {
386a3e0fd82Sopenharmony_ci    public:
387a3e0fd82Sopenharmony_ci        PlayerListener() {}
388a3e0fd82Sopenharmony_ci        virtual ~PlayerListener() {}
389a3e0fd82Sopenharmony_ci        void OnPlaybackComplete() override
390a3e0fd82Sopenharmony_ci        {
391a3e0fd82Sopenharmony_ci            if (video_ != nullptr) {
392a3e0fd82Sopenharmony_ci                video_->OnVideoComplete();
393a3e0fd82Sopenharmony_ci            }
394a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
395a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnPlaybackComplete();
396a3e0fd82Sopenharmony_ci            }
397a3e0fd82Sopenharmony_ci        }
398a3e0fd82Sopenharmony_ci
399a3e0fd82Sopenharmony_ci        void OnError(int32_t errorType, int32_t errorCode) override
400a3e0fd82Sopenharmony_ci        {
401a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
402a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnError(errorType, errorCode);
403a3e0fd82Sopenharmony_ci            }
404a3e0fd82Sopenharmony_ci        }
405a3e0fd82Sopenharmony_ci
406a3e0fd82Sopenharmony_ci        void OnInfo(int32_t type, int32_t extra) override
407a3e0fd82Sopenharmony_ci        {
408a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
409a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnInfo(type, extra);
410a3e0fd82Sopenharmony_ci            }
411a3e0fd82Sopenharmony_ci        }
412a3e0fd82Sopenharmony_ci
413a3e0fd82Sopenharmony_ci        void OnVideoSizeChanged(int32_t width, int32_t height) override
414a3e0fd82Sopenharmony_ci        {
415a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
416a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnVideoSizeChanged(width, height);
417a3e0fd82Sopenharmony_ci            }
418a3e0fd82Sopenharmony_ci        }
419a3e0fd82Sopenharmony_ci
420a3e0fd82Sopenharmony_ci        void OnRewindToComplete() override
421a3e0fd82Sopenharmony_ci        {
422a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
423a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnRewindToComplete();
424a3e0fd82Sopenharmony_ci            }
425a3e0fd82Sopenharmony_ci        }
426a3e0fd82Sopenharmony_ci
427a3e0fd82Sopenharmony_ci        void OnPlaybackPause()
428a3e0fd82Sopenharmony_ci        {
429a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
430a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnPlaybackPause();
431a3e0fd82Sopenharmony_ci            }
432a3e0fd82Sopenharmony_ci        }
433a3e0fd82Sopenharmony_ci
434a3e0fd82Sopenharmony_ci        void OnPlaybackPlay()
435a3e0fd82Sopenharmony_ci        {
436a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
437a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnPlaybackPlay();
438a3e0fd82Sopenharmony_ci            }
439a3e0fd82Sopenharmony_ci        }
440a3e0fd82Sopenharmony_ci
441a3e0fd82Sopenharmony_ci        void OnPlaybackStop()
442a3e0fd82Sopenharmony_ci        {
443a3e0fd82Sopenharmony_ci            if (videoPlayerListener_ != nullptr) {
444a3e0fd82Sopenharmony_ci                videoPlayerListener_->OnPlaybackStop();
445a3e0fd82Sopenharmony_ci            }
446a3e0fd82Sopenharmony_ci        }
447a3e0fd82Sopenharmony_ci
448a3e0fd82Sopenharmony_ci        void SetVideoPlayer(UIVideo* video)
449a3e0fd82Sopenharmony_ci        {
450a3e0fd82Sopenharmony_ci            video_ = video;
451a3e0fd82Sopenharmony_ci        }
452a3e0fd82Sopenharmony_ci
453a3e0fd82Sopenharmony_ci        void SetVideoPlayerListerner(VideoPlayerListener* listener)
454a3e0fd82Sopenharmony_ci        {
455a3e0fd82Sopenharmony_ci            videoPlayerListener_ = listener;
456a3e0fd82Sopenharmony_ci        }
457a3e0fd82Sopenharmony_ci
458a3e0fd82Sopenharmony_ci    private:
459a3e0fd82Sopenharmony_ci        UIVideo* video_ = nullptr;
460a3e0fd82Sopenharmony_ci        VideoPlayerListener* videoPlayerListener_ = nullptr;
461a3e0fd82Sopenharmony_ci    };
462a3e0fd82Sopenharmony_ci
463a3e0fd82Sopenharmony_ci    bool completeFlag_ = false;
464a3e0fd82Sopenharmony_ci    float leftVolumeValue_ = DEFAULT_VOLUME;
465a3e0fd82Sopenharmony_ci    float rightVolumeValue_ = DEFAULT_VOLUME;
466a3e0fd82Sopenharmony_ci    int64_t duration_ = 0;
467a3e0fd82Sopenharmony_ci    const char* src_ = nullptr;
468a3e0fd82Sopenharmony_ci    std::shared_ptr<Player> videoPlayer_ = nullptr;
469a3e0fd82Sopenharmony_ci    UIViewGroup* controllerGroup_ = nullptr;
470a3e0fd82Sopenharmony_ci    UILabel* totalTimeLabel_ = nullptr;
471a3e0fd82Sopenharmony_ci    UILabel* currentTimeLabel_ = nullptr;
472a3e0fd82Sopenharmony_ci    UILabel* titleLabel_ = nullptr;
473a3e0fd82Sopenharmony_ci    UISlider* playSlider_ = nullptr;
474a3e0fd82Sopenharmony_ci    Animator* sliderAnimator_ = nullptr;
475a3e0fd82Sopenharmony_ci    SliderAnimatorCallback* sliderAnimatorCallback_ = nullptr;
476a3e0fd82Sopenharmony_ci    UIToggleButton* volumeButton_ = nullptr;
477a3e0fd82Sopenharmony_ci    UISurfaceView* surfaceView_ = nullptr;
478a3e0fd82Sopenharmony_ci    UIToggleButton* playButton_ = nullptr;
479a3e0fd82Sopenharmony_ci    UIToggleButton* pauseButton_ = nullptr;
480a3e0fd82Sopenharmony_ci    VideoPlayerListener* videoPlayerListener_ = nullptr;
481a3e0fd82Sopenharmony_ci    std::shared_ptr<PlayerListener> playerListener_ = nullptr;
482a3e0fd82Sopenharmony_ci
483a3e0fd82Sopenharmony_ci    static constexpr uint16_t DEFAULT_VIEW_WIDTH = 960;
484a3e0fd82Sopenharmony_ci    static constexpr uint16_t DEFAULT_VIEW_HEIGHT = 480;
485a3e0fd82Sopenharmony_ci    static constexpr uint16_t TOGGLE_BUTTON_WIDTH = 32;
486a3e0fd82Sopenharmony_ci    static constexpr uint16_t TOGGLE_BUTTON_HEIGHT = 32;
487a3e0fd82Sopenharmony_ci    static constexpr uint16_t TIME_LABEL_WIDTH = 300;
488a3e0fd82Sopenharmony_ci    static constexpr uint16_t TIME_LABEL_HEIGHT = 20;
489a3e0fd82Sopenharmony_ci    static constexpr uint16_t KNOB_WIDTH = 18;
490a3e0fd82Sopenharmony_ci    static constexpr uint16_t FONT_DEFAULT_SIZE = 14;
491a3e0fd82Sopenharmony_ci    static constexpr uint16_t MAX_VOLUME = 300;
492a3e0fd82Sopenharmony_ci    static constexpr uint16_t HIDE_MILLI_SECOND = 5000;
493a3e0fd82Sopenharmony_ci    static constexpr float DEFAULT_VOLUME = 0.5;
494a3e0fd82Sopenharmony_ci};
495a3e0fd82Sopenharmony_ci} // namespace OHOS
496a3e0fd82Sopenharmony_ci
497a3e0fd82Sopenharmony_ci#endif // VERSION_LITE
498a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_UI_VIDEO_H
499