Kiwano Engine v1.2.x
SoundPlayer.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano-audio/Sound.h>
23
24namespace kiwano
25{
26namespace audio
27{
28KGE_DECLARE_SMART_PTR(SoundPlayer);
29
39class KGE_API SoundPlayer : public ObjectBase
40{
41public:
42 using SoundList = List<SoundPtr>;
43
45
47
51 AudioDataPtr Preload(const String& file_path);
52
55 AudioDataPtr Preload(const Resource& res, const String& ext = "");
56
61 void Play(SoundPtr sound, int loop_count = 0);
62
67 SoundPtr Play(const String& file_path, int loop_count = 0);
68
73 SoundPtr Play(const Resource& res, int loop_count = 0);
74
77 void PauseAll();
78
81 void ResumeAll();
82
85 void StopAll();
86
89 const SoundList& GetPlayingList() const;
90
93 float GetVolume() const;
94
98 void SetVolume(float volume);
99
102 void ClearCache();
103
104protected:
105 void OnEnd(Sound* sound);
106
107 float OnVolumeChanged(Sound* sound, float volume);
108
109 void SetCallback(Sound* sound);
110
111 void RemoveCallback(Sound* sound);
112
113 void ClearTrash();
114
115protected:
116 float volume_;
117 SoundList sound_list_;
118 SoundList trash_;
119 SoundCallbackPtr callback_;
120
121 UnorderedMap<size_t, AudioDataPtr> cache_;
122};
123
126inline const SoundPlayer::SoundList& SoundPlayer::GetPlayingList() const
127{
128 return sound_list_;
129}
130
131} // namespace audio
132} // namespace kiwano
基础对象
Definition: ObjectBase.h:137
资源
Definition: Resource.h:41
音频播放器
Definition: SoundPlayer.h:40
const SoundList & GetPlayingList() const
获取正在播放的音频列表
Definition: SoundPlayer.h:126
音频
Definition: Sound.h:88