1 /*
2 * Copyright (c) 2025 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 "napi_native_mediaplayer_handler_impl.h"
17 #include "nweb_log.h"
18
19 namespace OHOS::NWeb {
20
NapiNativeMediaPlayerHandlerImpl(int32_t nwebId,std::shared_ptr<NWebNativeMediaPlayerHandler> handler)21 NapiNativeMediaPlayerHandlerImpl::NapiNativeMediaPlayerHandlerImpl(
22 int32_t nwebId, std::shared_ptr<NWebNativeMediaPlayerHandler> handler)
23 : nwebId_(nwebId), handler_(handler)
24 {}
25
HandleStatusChanged(PlaybackStatus status)26 void NapiNativeMediaPlayerHandlerImpl::HandleStatusChanged(PlaybackStatus status)
27 {
28 WVLOG_D("begin to handle status changed,nweb id is %{public}d", nwebId_);
29
30 if (handler_) {
31 handler_->HandleStatusChanged(status);
32 }
33 }
34
HandleVolumeChanged(double volume)35 void NapiNativeMediaPlayerHandlerImpl::HandleVolumeChanged(double volume)
36 {
37 WVLOG_D("begin to handle volume changed,nweb id is %{public}d", nwebId_);
38
39 if (handler_) {
40 handler_->HandleVolumeChanged(volume);
41 }
42 }
43
HandleMutedChanged(bool isMuted)44 void NapiNativeMediaPlayerHandlerImpl::HandleMutedChanged(bool isMuted)
45 {
46 WVLOG_D("begin to handle muted changed,nweb id is %{public}d", nwebId_);
47
48 if (handler_) {
49 handler_->HandleMutedChanged(isMuted);
50 }
51 }
52
HandlePlaybackRateChanged(double playbackRate)53 void NapiNativeMediaPlayerHandlerImpl::HandlePlaybackRateChanged(double playbackRate)
54 {
55 WVLOG_D("begin to handle playback rate changed,nweb id is %{public}d", nwebId_);
56
57 if (handler_) {
58 handler_->HandlePlaybackRateChanged(playbackRate);
59 }
60 }
61
HandleDurationChanged(double duration)62 void NapiNativeMediaPlayerHandlerImpl::HandleDurationChanged(double duration)
63 {
64 WVLOG_D("begin to handle duration changed,nweb id is %{public}d", nwebId_);
65
66 if (handler_) {
67 handler_->HandleDurationChanged(duration);
68 }
69 }
70
HandleTimeUpdate(double playTime)71 void NapiNativeMediaPlayerHandlerImpl::HandleTimeUpdate(double playTime)
72 {
73 if (handler_) {
74 handler_->HandleTimeUpdate(playTime);
75 }
76 }
77
HandleBufferedEndTimeChanged(double bufferedEndTime)78 void NapiNativeMediaPlayerHandlerImpl::HandleBufferedEndTimeChanged(double bufferedEndTime)
79 {
80 WVLOG_D("begin to handle buffered end time changed,nweb id is %{public}d", nwebId_);
81
82 if (handler_) {
83 handler_->HandleBufferedEndTimeChanged(bufferedEndTime);
84 }
85 }
86
HandleEnded()87 void NapiNativeMediaPlayerHandlerImpl::HandleEnded()
88 {
89 WVLOG_D("begin to handle end,nweb id is %{public}d", nwebId_);
90
91 if (handler_) {
92 handler_->HandleEnded();
93 }
94 }
95
HandleNetworkStateChanged(NetworkState state)96 void NapiNativeMediaPlayerHandlerImpl::HandleNetworkStateChanged(NetworkState state)
97 {
98 WVLOG_D("begin to handle network state changed,nweb id is %{public}d", nwebId_);
99
100 if (handler_) {
101 handler_->HandleNetworkStateChanged(state);
102 }
103 }
104
HandleReadyStateChanged(ReadyState state)105 void NapiNativeMediaPlayerHandlerImpl::HandleReadyStateChanged(ReadyState state)
106 {
107 WVLOG_D("begin to handle ready state changed,nweb id is %{public}d", nwebId_);
108
109 if (handler_) {
110 handler_->HandleReadyStateChanged(state);
111 }
112 }
113
HandleFullScreenChanged(bool isFullScreen)114 void NapiNativeMediaPlayerHandlerImpl::HandleFullScreenChanged(bool isFullScreen)
115 {
116 WVLOG_D("begin to handle full screen changed,nweb id is %{public}d", nwebId_);
117
118 if (handler_) {
119 handler_->HandleFullScreenChanged(isFullScreen);
120 }
121 }
122
HandleSeeking()123 void NapiNativeMediaPlayerHandlerImpl::HandleSeeking()
124 {
125 WVLOG_D("begin to handle seeking,nweb id is %{public}d", nwebId_);
126
127 if (handler_) {
128 handler_->HandleSeeking();
129 }
130 }
131
HandleSeekFinished()132 void NapiNativeMediaPlayerHandlerImpl::HandleSeekFinished()
133 {
134 WVLOG_D("begin to handle seek finished,nweb id is %{public}d", nwebId_);
135
136 if (handler_) {
137 handler_->HandleSeekFinished();
138 }
139 }
140
HandleError(MediaError error,const std::string & message)141 void NapiNativeMediaPlayerHandlerImpl::HandleError(MediaError error, const std::string& message)
142 {
143 WVLOG_D("begin to handle error,nweb id is %{public}d", nwebId_);
144
145 if (handler_) {
146 handler_->HandleError(error, message);
147 }
148 }
149
HandleVideoSizeChanged(double width,double height)150 void NapiNativeMediaPlayerHandlerImpl::HandleVideoSizeChanged(double width, double height)
151 {
152 WVLOG_D("begin to handle video size changed,nweb id is %{public}d", nwebId_);
153
154 if (handler_) {
155 handler_->HandleVideoSizeChanged(width, height);
156 }
157 }
158
159 } // namespace OHOS::NWeb
160