• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 OHOS_SHARING_AUDIO_PLAY_CONTROLLER_H
17 #define OHOS_SHARING_AUDIO_PLAY_CONTROLLER_H
18 
19 #include <thread>
20 #include "buffer_dispatcher.h"
21 #include "common/event_comm.h"
22 #include "mediaplayer/include/audio_player.h"
23 
24 
25 namespace OHOS {
26 namespace Sharing {
27 
28 class AudioPlayController {
29 public:
30     explicit AudioPlayController(uint32_t mediaChannelId);
31     ~AudioPlayController();
32 
33     void Release();
34     void SetVolume(float volume);
35     void Stop(BufferDispatcher::Ptr &dispatcher);
36     bool Init(AudioTrack &audioTrack);
37     bool Start(BufferDispatcher::Ptr &dispatcher);
38 
39 protected:
40     void StopAudioThread();
41     void AudioPlayThread();
42     void StartAudioThread();
43 
44 private:
45     uint32_t mediachannelId_ = 0;
46     std::atomic_bool isAudioRunning_ = false;
47     std::shared_ptr<AudioPlayer> audioPlayer_ = nullptr;
48     std::shared_ptr<std::thread> audioPlayThread_ = nullptr;
49     std::shared_ptr<BufferReceiver> bufferReceiver_ = nullptr;
50 };
51 
52 } // namespace Sharing
53 } // namespace OHOS
54 #endif