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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_EVENT_HUB_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_EVENT_HUB_H 18 19 #include <functional> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components_ng/event/event_hub.h" 23 #include "core/components_ng/event/gesture_event_hub.h" 24 25 namespace OHOS::Ace::NG { 26 27 using EventCallback = std::function<void(const std::string&)>; 28 29 class VideoEventHub : public EventHub { 30 DECLARE_ACE_TYPE(VideoEventHub, EventHub) 31 32 public: 33 VideoEventHub() = default; 34 ~VideoEventHub() override = default; 35 SetOnStart(EventCallback && onStart)36 void SetOnStart(EventCallback&& onStart) 37 { 38 onStart_ = std ::move(onStart); 39 } FireStartEvent(const std::string & param)40 void FireStartEvent(const std::string& param) 41 { 42 if (onStart_) { 43 onStart_(param); 44 } 45 } 46 SetOnPause(EventCallback && onPause)47 void SetOnPause(EventCallback&& onPause) 48 { 49 onPause_ = std ::move(onPause); 50 } FirePauseEvent(const std::string & param)51 void FirePauseEvent(const std::string& param) 52 { 53 if (onPause_) { 54 onPause_(param); 55 } 56 } 57 SetOnFinish(EventCallback && onFinish)58 void SetOnFinish(EventCallback&& onFinish) 59 { 60 onFinish_ = std ::move(onFinish); 61 } FireFinishEvent(const std::string & param)62 void FireFinishEvent(const std::string& param) 63 { 64 if (onFinish_) { 65 onFinish_(param); 66 } 67 } 68 SetOnError(EventCallback && onError)69 void SetOnError(EventCallback&& onError) 70 { 71 onError_ = std ::move(onError); 72 } FireErrorEvent(const std::string & param)73 void FireErrorEvent(const std::string& param) 74 { 75 if (onError_) { 76 onError_(param); 77 } 78 } 79 SetOnPrepared(EventCallback && onPrepared)80 void SetOnPrepared(EventCallback&& onPrepared) 81 { 82 onPrepared_ = std ::move(onPrepared); 83 } FirePreparedEvent(const std::string & param)84 void FirePreparedEvent(const std::string& param) 85 { 86 if (onPrepared_) { 87 onPrepared_(param); 88 } 89 } 90 SetOnSeeking(EventCallback && onSeeking)91 void SetOnSeeking(EventCallback&& onSeeking) 92 { 93 onSeeking_ = std ::move(onSeeking); 94 } FireSeekingEvent(const std::string & param)95 void FireSeekingEvent(const std::string& param) 96 { 97 if (onSeeking_) { 98 onSeeking_(param); 99 } 100 } 101 SetOnSeeked(EventCallback && onSeeked)102 void SetOnSeeked(EventCallback&& onSeeked) 103 { 104 onSeeked_ = std ::move(onSeeked); 105 } FireSeekedEvent(const std::string & param)106 void FireSeekedEvent(const std::string& param) 107 { 108 if (onSeeked_) { 109 onSeeked_(param); 110 } 111 } 112 SetOnUpdate(EventCallback && onUpdate)113 void SetOnUpdate(EventCallback&& onUpdate) 114 { 115 onUpdate_ = std ::move(onUpdate); 116 } FireUpdateEvent(const std::string & param)117 void FireUpdateEvent(const std::string& param) 118 { 119 if (onUpdate_) { 120 onUpdate_(param); 121 } 122 } 123 SetOnFullScreenChange(EventCallback && onFullScreenChange)124 void SetOnFullScreenChange(EventCallback&& onFullScreenChange) 125 { 126 onFullScreenChange_ = std ::move(onFullScreenChange); 127 } FireFullScreenChangeEvent(const std::string & param)128 void FireFullScreenChangeEvent(const std::string& param) 129 { 130 if (onFullScreenChange_) { 131 onFullScreenChange_(param); 132 } 133 } 134 135 private: 136 EventCallback onStart_; 137 EventCallback onPause_; 138 EventCallback onFinish_; 139 EventCallback onError_; 140 EventCallback onPrepared_; 141 EventCallback onSeeking_; 142 EventCallback onSeeked_; 143 EventCallback onUpdate_; 144 EventCallback onFullScreenChange_; 145 }; 146 147 } // namespace OHOS::Ace::NG 148 149 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_EVENT_HUB_H 150