1 /*
2  * Copyright (c) 2022-2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_MEDIA_PLAYER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_MEDIA_PLAYER_H
18 
19 #include <cstdint>
20 
21 #include "base/memory/ace_type.h"
22 #include "base/utils/noncopyable.h"
23 #include "core/components/video/video_utils.h"
24 #include "core/components_ng/render/render_surface.h"
25 
26 namespace OHOS::Ace::NG {
27 using PositionUpdatedEvent = std::function<void(uint32_t)>;
28 using SeekDoneEvent = std::function<void(uint32_t)>;
29 using StateChangedEvent = std::function<void(PlaybackStatus)>;
30 using CommonEvent = std::function<void()>;
31 using TextureRefreshEnVent = std::function<void(uint32_t, uint64_t)>;
32 // MediaPlayer is used to show and play meida
33 class ACE_FORCE_EXPORT MediaPlayer : public virtual AceType {
34     DECLARE_ACE_TYPE(NG::MediaPlayer, AceType)
35 
36 public:
37     MediaPlayer() = default;
38     ~MediaPlayer() override = default;
39 
40     static RefPtr<MediaPlayer> Create();
41 
CreateMediaPlayer()42     virtual void CreateMediaPlayer() {}
43 
ResetMediaPlayer()44     virtual void ResetMediaPlayer() {}
45 
IsMediaPlayerValid()46     virtual bool IsMediaPlayerValid()
47     {
48         return false;
49     }
50 
SetVolume(float leftVolume,float rightVolume)51     virtual void SetVolume(float leftVolume, float rightVolume) {}
52 
SetMediaMuted(int32_t type,bool isMuted)53     virtual void SetMediaMuted(int32_t type, bool isMuted) {}
54 
55     virtual bool SetSource(const std::string& /*src*/, const std::string& bundleName = "",
56         const std::string& moduleName = "")
57     {
58         return false;
59     }
60 
SetSourceByFd(int32_t fd)61     virtual bool SetSourceByFd(int32_t fd)
62     {
63         return false;
64     }
65 
SetRenderSurface(const RefPtr<RenderSurface> & renderSurface)66     virtual void SetRenderSurface(const RefPtr<RenderSurface>& renderSurface) {}
67 
RegisterMediaPlayerEvent(PositionUpdatedEvent && positionUpdatedEvent,StateChangedEvent && stateChangedEvent,CommonEvent && errorEvent,CommonEvent && resolutionChangeEvent,CommonEvent && startRenderFrameEvent)68     virtual void RegisterMediaPlayerEvent(PositionUpdatedEvent&& positionUpdatedEvent,
69         StateChangedEvent&& stateChangedEvent, CommonEvent&& errorEvent, CommonEvent&& resolutionChangeEvent,
70         CommonEvent&& startRenderFrameEvent)
71     {}
72 
RegisterMediaPlayerSeekDoneEvent(SeekDoneEvent && seekDoneEvent)73     virtual void RegisterMediaPlayerSeekDoneEvent(SeekDoneEvent&& seekDoneEvent) {}
74 
RegisterTextureEvent(TextureRefreshEnVent && textureRefreshEvent)75     virtual void RegisterTextureEvent(TextureRefreshEnVent&& textureRefreshEvent) {}
76 
GetDuration(int32_t &)77     virtual int32_t GetDuration(int32_t& /*duration*/)
78     {
79         return -1;
80     }
81 
GetVideoWidth()82     virtual int32_t GetVideoWidth()
83     {
84         return -1;
85     }
86 
GetVideoHeight()87     virtual int32_t GetVideoHeight()
88     {
89         return -1;
90     }
91 
SetLooping(bool)92     virtual int32_t SetLooping(bool /*loop*/)
93     {
94         return -1;
95     }
96 
SetPlaybackSpeed(float)97     virtual int32_t SetPlaybackSpeed(float /*speed*/)
98     {
99         return -1;
100     }
101 
SetSurface()102     virtual int32_t SetSurface()
103     {
104         return -1;
105     }
106 
PrepareAsync()107     virtual int32_t PrepareAsync()
108     {
109         return -1;
110     }
111 
IsPlaying()112     virtual bool IsPlaying()
113     {
114         return false;
115     }
116 
Play()117     virtual int32_t Play()
118     {
119         return -1;
120     }
121 
Pause()122     virtual int32_t Pause()
123     {
124         return -1;
125     }
126 
Stop()127     virtual int32_t Stop()
128     {
129         return -1;
130     }
131 
Seek(int32_t,SeekMode)132     virtual int32_t Seek(int32_t /*mSeconds*/, SeekMode /*mode*/)
133     {
134         return -1;
135     }
FullScreenChange(bool isFullScreen)136     virtual int32_t FullScreenChange(bool isFullScreen)
137     {
138         return -1;
139     }
SetPlayRange(int64_t,int64_t)140     virtual int32_t SetPlayRange(int64_t /*startTime*/, int64_t /*endTime*/)
141     {
142         return -1;
143     }
144 
SetParameter(const std::string & key,int64_t value)145     virtual int32_t SetParameter(const std::string& key, int64_t value)
146     {
147         return -1;
148     }
149 
150 protected:
151 
152     ACE_DISALLOW_COPY_AND_MOVE(MediaPlayer);
153 };
154 } // namespace OHOS::Ace::NG
155 
156 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_MEDIA_PLAYER_H
157