2013-06-08 14:06:19 +08:00
|
|
|
--Encapsulate SimpleAudioEngine to AudioEngine,Play music and sound effects.
|
2013-06-09 10:32:23 +08:00
|
|
|
local M = {}
|
2013-08-15 15:51:22 +08:00
|
|
|
local audioEngineInstance = cc.SimpleAudioEngine:getInstance()
|
2013-06-08 11:23:21 +08:00
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.stopAllEffects()
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:stopAllEffects()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.getMusicVolume()
|
2013-08-15 15:51:22 +08:00
|
|
|
return audioEngineInstance:getMusicVolume()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.isMusicPlaying()
|
2013-08-15 15:51:22 +08:00
|
|
|
return audioEngineInstance:isMusicPlaying()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.getEffectsVolume()
|
2013-07-26 13:43:28 +08:00
|
|
|
return audioEngineInstance:getEffectsVolume()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.setMusicVolume(volume)
|
2013-08-15 15:51:22 +08:00
|
|
|
audioEngineInstance:setMusicVolume(volume)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.stopEffect(handle)
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:stopEffect(handle)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.stopMusic(isReleaseData)
|
2013-06-08 11:23:21 +08:00
|
|
|
local releaseDataValue = false
|
|
|
|
if nil ~= isReleaseData then
|
|
|
|
releaseDataValue = isReleaseData
|
|
|
|
end
|
2013-08-15 15:51:22 +08:00
|
|
|
audioEngineInstance:stopMusic(releaseDataValue)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.playMusic(filename, isLoop)
|
2013-06-08 11:23:21 +08:00
|
|
|
local loopValue = false
|
|
|
|
if nil ~= isLoop then
|
|
|
|
loopValue = isLoop
|
|
|
|
end
|
2013-08-15 15:51:22 +08:00
|
|
|
audioEngineInstance:playMusic(filename, loopValue)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.pauseAllEffects()
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:pauseAllEffects()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.preloadMusic(filename)
|
2013-08-15 15:51:22 +08:00
|
|
|
audioEngineInstance:preloadMusic(filename)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.resumeMusic()
|
2013-08-15 15:51:22 +08:00
|
|
|
audioEngineInstance:resumeMusic()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.playEffect(filename, isLoop)
|
2013-06-08 11:23:21 +08:00
|
|
|
local loopValue = false
|
|
|
|
if nil ~= isLoop then
|
|
|
|
loopValue = isLoop
|
|
|
|
end
|
2013-07-26 13:43:28 +08:00
|
|
|
return audioEngineInstance:playEffect(filename, loopValue)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.rewindMusic()
|
2013-08-15 15:51:22 +08:00
|
|
|
audioEngineInstance:rewindMusic()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.willPlayMusic()
|
2013-08-15 15:51:22 +08:00
|
|
|
return audioEngineInstance:willPlayMusic()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.unloadEffect(filename)
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:unloadEffect(filename)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.preloadEffect(filename)
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:preloadEffect(filename)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.setEffectsVolume(volume)
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:setEffectsVolume(volume)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.pauseEffect(handle)
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:pauseEffect(handle)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.resumeAllEffects(handle)
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:resumeAllEffects()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.pauseMusic()
|
2013-08-15 15:51:22 +08:00
|
|
|
audioEngineInstance:pauseMusic()
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 10:32:23 +08:00
|
|
|
function M.resumeEffect(handle)
|
2013-07-26 13:43:28 +08:00
|
|
|
audioEngineInstance:resumeEffect(handle)
|
2013-06-08 11:23:21 +08:00
|
|
|
end
|
|
|
|
|
2013-06-09 11:38:18 +08:00
|
|
|
local modename = "AudioEngine"
|
|
|
|
local proxy = {}
|
|
|
|
local mt = {
|
|
|
|
__index = M,
|
|
|
|
__newindex = function (t ,k ,v)
|
|
|
|
print("attemp to update a read-only table")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
setmetatable(proxy,mt)
|
|
|
|
_G[modename] = proxy
|
|
|
|
package.loaded[modename] = proxy
|
|
|
|
|
2013-06-08 11:23:21 +08:00
|
|
|
|