issue #2103 modify AudioEngine framework and CocosDenshionTest sample

This commit is contained in:
samuele3hu 2013-06-09 10:32:23 +08:00
parent 4edd35e2b1
commit bc699c1c1e
2 changed files with 29 additions and 49 deletions

View File

@ -111,12 +111,12 @@ local function CocosDenshionTest()
ret:setTouchEnabled(true) ret:setTouchEnabled(true)
-- preload background music and effect -- preload background music and effect
SimpleAudioEngine:sharedEngine():preloadBackgroundMusic( MUSIC_FILE ) AudioEngine.preloadMusic( MUSIC_FILE )
SimpleAudioEngine:sharedEngine():preloadEffect( EFFECT_FILE ) AudioEngine.preloadEffect( EFFECT_FILE )
-- set default volume -- set default volume
SimpleAudioEngine:sharedEngine():setEffectsVolume(0.5) AudioEngine.setEffectsVolume(0.5)
SimpleAudioEngine:sharedEngine():setBackgroundMusicVolume(0.5) AudioEngine.setMusicVolume(0.5)
local function onNodeEvent(event) local function onNodeEvent(event)
if event == "enter" then if event == "enter" then

View File

@ -1,33 +1,36 @@
--Encapsulate SimpleAudioEngine to AudioEngine,Play music and sound effects. --Encapsulate SimpleAudioEngine to AudioEngine,Play music and sound effects.
AudioEngine = AudioEngine or {} local modename = "AudioEngine"
local M = {}
_G[modename] = M
package.loaded[modename] = M
local sharedEngine = SimpleAudioEngine:sharedEngine() local sharedEngine = SimpleAudioEngine:sharedEngine()
local function stopAllEffects() function M.stopAllEffects()
sharedEngine:stopAllEffects() sharedEngine:stopAllEffects()
end end
local function getMusicVolume() function M.getMusicVolume()
return sharedEngine:getBackgroundMusicVolume() return sharedEngine:getBackgroundMusicVolume()
end end
local function isMusicPlaying() function M.isMusicPlaying()
return sharedEngine:isBackgroundMusicPlaying() return sharedEngine:isBackgroundMusicPlaying()
end end
local function getEffectsVolume() function M.getEffectsVolume()
return sharedEngine:getEffectsVolume() return sharedEngine:getEffectsVolume()
end end
local function setMusicVolume(volume) function M.setMusicVolume(volume)
sharedEngine:setBackgroundMusicVolume(volume) sharedEngine:setBackgroundMusicVolume(volume)
end end
local function stopEffect(handle) function M.stopEffect(handle)
sharedEngine:stopEffect(handle) sharedEngine:stopEffect(handle)
end end
local function stopMusic(isReleaseData) function M.stopMusic(isReleaseData)
local releaseDataValue = false local releaseDataValue = false
if nil ~= isReleaseData then if nil ~= isReleaseData then
releaseDataValue = isReleaseData releaseDataValue = isReleaseData
@ -35,7 +38,7 @@ local function stopMusic(isReleaseData)
sharedEngine:stopBackgroundMusic(releaseDataValue) sharedEngine:stopBackgroundMusic(releaseDataValue)
end end
local function playMusic(filename, isLoop) function M.playMusic(filename, isLoop)
local loopValue = false local loopValue = false
if nil ~= isLoop then if nil ~= isLoop then
loopValue = isLoop loopValue = isLoop
@ -43,19 +46,19 @@ local function playMusic(filename, isLoop)
sharedEngine:playBackgroundMusic(filename, loopValue) sharedEngine:playBackgroundMusic(filename, loopValue)
end end
local function pauseAllEffects() function M.pauseAllEffects()
sharedEngine:pauseAllEffects() sharedEngine:pauseAllEffects()
end end
local function preloadMusic(filename) function M.preloadMusic(filename)
sharedEngine:preloadBackgroundMusic(filename) sharedEngine:preloadBackgroundMusic(filename)
end end
local function resumeMusic() function M.resumeMusic()
sharedEngine:resumeBackgroundMusic() sharedEngine:resumeBackgroundMusic()
end end
local function playEffect(filename, isLoop) function M.playEffect(filename, isLoop)
local loopValue = false local loopValue = false
if nil ~= isLoop then if nil ~= isLoop then
loopValue = isLoop loopValue = isLoop
@ -63,63 +66,40 @@ local function playEffect(filename, isLoop)
return sharedEngine:playEffect(filename, loopValue) return sharedEngine:playEffect(filename, loopValue)
end end
local function rewindMusic() function M.rewindMusic()
sharedEngine:rewindBackgroundMusic() sharedEngine:rewindBackgroundMusic()
end end
local function willPlayMusic() function M.willPlayMusic()
return sharedEngine:willPlayBackgroundMusic() return sharedEngine:willPlayBackgroundMusic()
end end
local function unloadEffect(filename) function M.unloadEffect(filename)
sharedEngine:unloadEffect(filename) sharedEngine:unloadEffect(filename)
end end
local function preloadEffect(filename) function M.preloadEffect(filename)
sharedEngine:preloadEffect(filename) sharedEngine:preloadEffect(filename)
end end
local function setEffectsVolume(volume) function M.setEffectsVolume(volume)
sharedEngine:setEffectsVolume(volume) sharedEngine:setEffectsVolume(volume)
end end
local function pauseEffect(handle) function M.pauseEffect(handle)
sharedEngine:pauseEffect(handle) sharedEngine:pauseEffect(handle)
end end
local function resumeAllEffects(handle) function M.resumeAllEffects(handle)
sharedEngine:resumeAllEffects() sharedEngine:resumeAllEffects()
end end
local function pauseMusic() function M.pauseMusic()
sharedEngine:pauseBackgroundMusic() sharedEngine:pauseBackgroundMusic()
end end
local function resumeEffect(handle) function M.resumeEffect(handle)
sharedEngine:resumeEffect(handle) sharedEngine:resumeEffect(handle)
end end
AudioEngine.stopAllEffects = stopAllEffects
AudioEngine.getMusicVolume = getMusicVolume
AudioEngine.isMusicPlaying = isMusicPlaying
AudioEngine.getEffectsVolume = getEffectsVolume
AudioEngine.setMusicVolume = setMusicVolume
AudioEngine.stopEffect = stopEffect
AudioEngine.stopMusic = stopMusic
AudioEngine.playMusic = playMusic
AudioEngine.pauseAllEffects = pauseAllEffects
AudioEngine.preloadMusic = preloadMusic
AudioEngine.resumeMusic = resumeMusic
AudioEngine.playEffect = playEffect
AudioEngine.rewindMusic = rewindMusic
AudioEngine.willPlayMusic = willPlayMusic
AudioEngine.unloadEffect = unloadEffect
AudioEngine.preloadEffect = preloadEffect
AudioEngine.setEffectsVolume = setEffectsVolume
AudioEngine.pauseEffect = pauseEffect
AudioEngine.resumeAllEffects = resumeAllEffects
AudioEngine.pauseMusic = pauseMusic
AudioEngine.resumeEffect = resumeEffect