SoundManager.lua
4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
cc.exports.SoundManager = {}
soundKindArr = {"loli","ladylike"};
SoundManager.isBackgroundMusic = true;
SoundManager.isEffect = true;
SoundManager.isPlayingBossEffect = false;
--local audioEngine = cc.SimpleAudioEngine:getInstance();
SoundManager.cur_playing_music_path = "";
local function init()
if cc.UserDefault:getInstance():getStringForKey("isMusic") == "" then
cc.UserDefault:getInstance():setStringForKey("isMusic",1);
end
if cc.UserDefault:getInstance():getStringForKey("isEffect") == "" then
cc.UserDefault:getInstance():setStringForKey("isEffect",1);
end
if cc.UserDefault:getInstance():getStringForKey("isMusic") == "1" then
SoundManager.isBackgroundMusic = true;
else
SoundManager.isBackgroundMusic = false;
end
if cc.UserDefault:getInstance():getStringForKey("isEffect") == "1" then
SoundManager.isEffect = true;
else
SoundManager.isEffect = false;
end
end
init();
function SoundManager.playMusic(filePath,loop)
if filePath then
SoundManager.cur_playing_music_path = filePath;
end
if SoundManager.isBackgroundMusic then
-- audioEngine:playMusic(filePath,loop);
audio.playMusic(SoundManager.cur_playing_music_path,loop);
SoundManager.setMusicVolume(1.5);
-- audioEngine:setMusicVolume(1);
end
end
function SoundManager.stopMusic()
if audio.isMusicPlaying() then
-- audioEngine:stopMusic(false);
audio.stopMusic(true)
-- audioEngine:setMusicVolume(0);
end
end
--暂停音乐
function SoundManager.pauseMusic()
audio.pauseMusic()
end
--继续音乐
function SoundManager.resumeMusic(filePath)
if filePath then
SoundManager.cur_playing_music_path = filePath;
end
if audio.isMusicPlaying() then
audio.resumeMusic()
else
SoundManager.playMusic(SoundManager.cur_playing_music_path,true)
end
end
function SoundManager.setMusicVolume(value)
--if SoundManager.isMusicPlaying() then
if audio.isMusicPlaying() then
audio.setMusicVolume(value)
end
-- audioEngine:setMusicVolume(value);
--end
end
function SoundManager.playEffect(filePath,isLoop,volume)
if isLoop==nil then
isLoop = false
end
if SoundManager.isEffect then
volume = volume or 1;
SoundManager.setSoundsVolume(volume);
return audio.playSound(filePath,isLoop)
end
end
function SoundManager.setSoundsVolume(value)
audio.setSoundsVolume(value);
end
function SoundManager.isMusicPlaying()
return audio.isMusicPlaying();
end
function SoundManager.setIsBackgroundMusic(b)
SoundManager.isBackgroundMusic = b;
if b then
cc.UserDefault:getInstance():setStringForKey("isMusic",1);
else
cc.UserDefault:getInstance():setStringForKey("isMusic",0);
end
end
function SoundManager.setIsEffect(b)
SoundManager.isEffect = b;
if b then
cc.UserDefault:getInstance():setStringForKey("isEffect",1);
else
cc.UserDefault:getInstance():setStringForKey("isEffect",0);
end
end
function SoundManager.stopEffect(handle)
audio.stopSound(handle)
end
function SoundManager.getGuandanSoundPath(name)
return "res/sound/gd/"..name;
end
function SoundManager.getGuandanVoicePath(name)
local kind = math.random(1,2);
math.randomseed(tostring(os.time()+kind):reverse():sub(1, 6));
return "res/sound/gd/"..soundKindArr[kind].."/"..name;
end
function SoundManager.getMJEffectPath(name,sex)
if sex == 1 then
return "res/sound/mj/sichuan/nan/"..name;
else
return "res/sound/mj/sichuan/nv/"..name;
end
end
function SoundManager.getMJChatSoundPath(name,sex)
if sex == 1 then
return "res/sound/mj/putonghua/nan/"..name;
else
return "res/sound/mj/putonghua/nv/"..name;
end
end
function SoundManager.getNiuniuChatSoundPath(name,sex)
local path = ""
if sex == 1 then
path = "res/sound/nn/nan/"..name;
else
path = "res/sound/nn/nv/"..name;
end
print("play nn chat voice:",path);
return path;
end
function SoundManager.getDdzEffectPath(name)
return "res/sound/ddz/"..name;
end
function SoundManager.getDdzChatPath(name,sex)
if sex == 1 then
return "res/sound/ddz/boychat/"..name;
else
return "res/sound/ddz/girlchat/"..name;
end
end
function SoundManager.getDdzPaixingPath(name,sex)
if sex == 1 then
return "res/sound/ddz/man/"..name;
else
return "res/sound/ddz/woman/"..name;
end
end
return SoundManager