• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 NATIVE_MEDIA_PLAYER_IMPL_H
17 #define NATIVE_MEDIA_PLAYER_IMPL_H
18 
19 #include "napi/native_api.h"
20 #include "nweb_native_media_player.h"
21 #include "napi_native_mediaplayer_handler_impl.h"
22 
23 namespace OHOS::NWeb {
24 
25 class NWebNativeMediaPlayerBridgeImpl : public NWebNativeMediaPlayerBridge {
26 public:
27     NWebNativeMediaPlayerBridgeImpl(int32_t nwebId, napi_env env, napi_value value);
28     ~NWebNativeMediaPlayerBridgeImpl() = default;
29 
30     void UpdateRect(double x, double y, double width, double height) override;
31 
32     void Play() override;
33 
34     void Pause() override;
35 
36     void Seek(double time) override;
37 
38     void SetVolume(double volume) override;
39 
40     void SetMuted(bool isMuted) override;
41 
42     void SetPlaybackRate(double playbackRate) override;
43 
44     void Release() override;
45 
46     void EnterFullScreen() override;
47 
48     void ExitFullScreen() override;
49 
50     void ResumeMediaPlayer() override;
51 
52     void SuspendMediaPlayer(SuspendType type) override;
53 
54 private:
55     int32_t nwebId_ = -1;
56     napi_env env_ = nullptr;
57     napi_value value_ = nullptr;
58 };
59 
60 class NWebCreateNativeMediaPlayerCallbackImpl : public NWebCreateNativeMediaPlayerCallback {
61 public:
62     explicit NWebCreateNativeMediaPlayerCallbackImpl(int32_t nwebId, napi_env env, napi_ref callback);
63     ~NWebCreateNativeMediaPlayerCallbackImpl();
64 
65     std::shared_ptr<NWebNativeMediaPlayerBridge> OnCreate(
66         std::shared_ptr<NWebNativeMediaPlayerHandler> handler, std::shared_ptr<NWebMediaInfo> mediaInfo) override;
67 
68 private:
69     void ConstructRect(napi_value* value, std::shared_ptr<NWebNativeMediaPlayerSurfaceInfo> surfaceInfo);
70 
71     void ConstructHandler(napi_value* value, std::shared_ptr<NWebNativeMediaPlayerHandler> handler);
72 
73     void ConstructControls(napi_value* value, const std::vector<std::string>& controls);
74 
75     void ConstructHeaders(napi_value* value, const std::map<std::string, std::string>& headers);
76 
77     void ConstructAttributes(napi_value* value, const std::map<std::string, std::string>& attributes);
78 
79     void ConstructMediaInfo(napi_value* value, std::shared_ptr<NWebMediaInfo> mediaInfo);
80 
81     void ConstructSourceInfos(napi_value* value, const std::vector<std::shared_ptr<NWebMediaSourceInfo>>& sourceInfos);
82 
83     void ConstructSurfaceInfo(napi_value* value, std::shared_ptr<NWebNativeMediaPlayerSurfaceInfo> surfaceInfo);
84 
85 private:
86     int32_t nwebId_ = -1;
87     napi_env env_ = nullptr;
88     napi_ref callback_ = nullptr;
89 };
90 
91 } // namespace OHOS::NWeb
92 
93 #endif // NATIVE_MEDIA_PLAYER_IMPL_H
94