1 /*
2  * Copyright (c) 2023 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 PLAYER_FRAMEWORK_ADAPTER_H
17 #define PLAYER_FRAMEWORK_ADAPTER_H
18 
19 #include "media_adapter.h"
20 #include "player.h"
21 
22 namespace OHOS::NWeb {
23 class PlayerCallbackImpl : public Media::PlayerCallback {
24 public:
25     explicit PlayerCallbackImpl(std::shared_ptr<PlayerCallbackAdapter> callback);
26 
27     ~PlayerCallbackImpl() = default;
28 
29     void OnInfo(Media::PlayerOnInfoType type, int32_t extra, const Media::Format& infoBody) override;
30 
31     void OnError(int32_t errorCode, const std::string& errorMsg) override;
32 
33 private:
34     std::shared_ptr<PlayerCallbackAdapter> callbackAdapter_ = nullptr;
35 };
36 
37 class PlayerAdapterImpl : public PlayerAdapter {
38 public:
39     PlayerAdapterImpl();
40 
41     ~PlayerAdapterImpl() override;
42 
43     int32_t SetPlayerCallback(std::shared_ptr<PlayerCallbackAdapter> callbackAdapter) override;
44 
45     int32_t SetSource(const std::string& url) override;
46 
47     int32_t SetSource(int32_t fd, int64_t offset = 0, int64_t size = 0) override;
48 
49     int32_t SetVideoSurface(std::shared_ptr<IConsumerSurfaceAdapter> cSurfaceAdapter) override;
50 
51     int32_t SetVolume(float leftVolume, float rightVolume) override;
52 
53     int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) override;
54 
55     int32_t Play() override;
56 
57     int32_t Pause() override;
58 
59     int32_t PrepareAsync() override;
60 
61     int32_t GetCurrentTime(int32_t& currentTime) override;
62 
63     int32_t GetDuration(int32_t& duration) override;
64 
65     int32_t SetPlaybackSpeed(PlaybackRateMode mode) override;
66 
67 private:
68     std::shared_ptr<Media::Player> player_ = nullptr;
69 };
70 } // namespace OHOS::NWeb
71 
72 #endif // PLAYER_FRAMEWORK_ADAPTER_H
73