/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef NATIVE_MEDIA_PLAYER_IMPL_H #define NATIVE_MEDIA_PLAYER_IMPL_H #include "napi/native_api.h" #include "nweb_native_media_player.h" namespace OHOS::NWeb { class NWebNativeMediaPlayerBridgeImpl : public NWebNativeMediaPlayerBridge { public: NWebNativeMediaPlayerBridgeImpl(int32_t nwebId, napi_env env, napi_value value); ~NWebNativeMediaPlayerBridgeImpl() = default; void UpdateRect(double x, double y, double width, double height) override; void Play() override; void Pause() override; void Seek(double time) override; void SetVolume(double volume) override; void SetMuted(bool isMuted) override; void SetPlaybackRate(double playbackRate) override; void Release() override; void EnterFullScreen() override; void ExitFullScreen() override; void ResumeMediaPlayer() override; void SuspendMediaPlayer(SuspendType type) override; private: int32_t nwebId_ = -1; napi_env env_ = nullptr; napi_value value_ = nullptr; }; class NapiNativeMediaPlayerHandlerImpl { public: NapiNativeMediaPlayerHandlerImpl(int32_t nwebId, std::shared_ptr handler); ~NapiNativeMediaPlayerHandlerImpl() = default; void HandleStatusChanged(PlaybackStatus status); void HandleVolumeChanged(double volume); void HandleMutedChanged(bool isMuted); void HandlePlaybackRateChanged(double playbackRate); void HandleDurationChanged(double duration); void HandleTimeUpdate(double playTime); void HandleBufferedEndTimeChanged(double bufferedEndTime); void HandleEnded(); void HandleNetworkStateChanged(NetworkState state); void HandleReadyStateChanged(ReadyState state); void HandleFullScreenChanged(bool isFullScreen); void HandleSeeking(); void HandleSeekFinished(); void HandleError(MediaError error, const std::string& message); void HandleVideoSizeChanged(double width, double height); private: int32_t nwebId_ = -1; std::shared_ptr handler_ = nullptr; }; class NWebCreateNativeMediaPlayerCallbackImpl : public NWebCreateNativeMediaPlayerCallback { public: explicit NWebCreateNativeMediaPlayerCallbackImpl(int32_t nwebId, napi_env env, napi_ref callback); ~NWebCreateNativeMediaPlayerCallbackImpl(); std::shared_ptr OnCreate( std::shared_ptr handler, std::shared_ptr mediaInfo) override; private: void ConstructRect(napi_value* value, std::shared_ptr surfaceInfo); void ConstructHandler(napi_value* value, std::shared_ptr handler); void ConstructControls(napi_value* value, const std::vector& controls); void ConstructHeaders(napi_value* value, const std::map& headers); void ConstructAttributes(napi_value* value, const std::map& attributes); void ConstructMediaInfo(napi_value* value, std::shared_ptr mediaInfo); void ConstructSourceInfos(napi_value* value, const std::vector>& sourceInfos); void ConstructSurfaceInfo(napi_value* value, std::shared_ptr surfaceInfo); private: int32_t nwebId_ = -1; napi_env env_ = nullptr; napi_ref callback_ = nullptr; }; } // namespace OHOS::NWeb #endif // NATIVE_MEDIA_PLAYER_IMPL_H