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)
-- preload background music and effect
SimpleAudioEngine:sharedEngine():preloadBackgroundMusic( MUSIC_FILE )
SimpleAudioEngine:sharedEngine():preloadEffect( EFFECT_FILE )
AudioEngine.preloadMusic( MUSIC_FILE )
AudioEngine.preloadEffect( EFFECT_FILE )
-- set default volume
SimpleAudioEngine:sharedEngine():setEffectsVolume(0.5)
SimpleAudioEngine:sharedEngine():setBackgroundMusicVolume(0.5)
AudioEngine.setEffectsVolume(0.5)
AudioEngine.setMusicVolume(0.5)
local function onNodeEvent(event)
if event == "enter" then

View File

@ -1,33 +1,36 @@
--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 function stopAllEffects()
function M.stopAllEffects()
sharedEngine:stopAllEffects()
end
local function getMusicVolume()
function M.getMusicVolume()
return sharedEngine:getBackgroundMusicVolume()
end
local function isMusicPlaying()
function M.isMusicPlaying()
return sharedEngine:isBackgroundMusicPlaying()
end
local function getEffectsVolume()
function M.getEffectsVolume()
return sharedEngine:getEffectsVolume()
end
local function setMusicVolume(volume)
function M.setMusicVolume(volume)
sharedEngine:setBackgroundMusicVolume(volume)
end
local function stopEffect(handle)
function M.stopEffect(handle)
sharedEngine:stopEffect(handle)
end
local function stopMusic(isReleaseData)
function M.stopMusic(isReleaseData)
local releaseDataValue = false
if nil ~= isReleaseData then
releaseDataValue = isReleaseData
@ -35,7 +38,7 @@ local function stopMusic(isReleaseData)
sharedEngine:stopBackgroundMusic(releaseDataValue)
end
local function playMusic(filename, isLoop)
function M.playMusic(filename, isLoop)
local loopValue = false
if nil ~= isLoop then
loopValue = isLoop
@ -43,19 +46,19 @@ local function playMusic(filename, isLoop)
sharedEngine:playBackgroundMusic(filename, loopValue)
end
local function pauseAllEffects()
function M.pauseAllEffects()
sharedEngine:pauseAllEffects()
end
local function preloadMusic(filename)
function M.preloadMusic(filename)
sharedEngine:preloadBackgroundMusic(filename)
end
local function resumeMusic()
function M.resumeMusic()
sharedEngine:resumeBackgroundMusic()
end
local function playEffect(filename, isLoop)
function M.playEffect(filename, isLoop)
local loopValue = false
if nil ~= isLoop then
loopValue = isLoop
@ -63,63 +66,40 @@ local function playEffect(filename, isLoop)
return sharedEngine:playEffect(filename, loopValue)
end
local function rewindMusic()
function M.rewindMusic()
sharedEngine:rewindBackgroundMusic()
end
local function willPlayMusic()
function M.willPlayMusic()
return sharedEngine:willPlayBackgroundMusic()
end
local function unloadEffect(filename)
function M.unloadEffect(filename)
sharedEngine:unloadEffect(filename)
end
local function preloadEffect(filename)
function M.preloadEffect(filename)
sharedEngine:preloadEffect(filename)
end
local function setEffectsVolume(volume)
function M.setEffectsVolume(volume)
sharedEngine:setEffectsVolume(volume)
end
local function pauseEffect(handle)
function M.pauseEffect(handle)
sharedEngine:pauseEffect(handle)
end
local function resumeAllEffects(handle)
function M.resumeAllEffects(handle)
sharedEngine:resumeAllEffects()
end
local function pauseMusic()
function M.pauseMusic()
sharedEngine:pauseBackgroundMusic()
end
local function resumeEffect(handle)
function M.resumeEffect(handle)
sharedEngine:resumeEffect(handle)
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