https://blog.csdn.net/wwj_748/article/details/38588563
Cocos2d-x 3.2 Lua Sample cocosdenshiontest (audio test)
This blog describes the audio tests of the LUA example in Cocos2d-x 3.2, Cocos2d-x uses Simpleaudioengine to control audio, such as playback, pausing, stopping, and so on. In the LUA code, the Audioengine is used, the implementation can refer to the Audioengine.lua file, but the simpleaudioengin is encapsulated.
Sample code:
[JavaScript] View plain copy--[[ cocosdenshiontest.lua cocos2d-x Audio Support ]]--& nbsp; require "Audioengine" local effect_file = "Effect1.wav" local music_file = nil -- get target platform local TARGETPLATFORM = CC. Application:getinstance (): Gettargetplatform () -- iphone or ipad if (cc. Platform_os_iphone == targetplatform) or (CC. Platform_os_ipad == targetplatform) then MUSIC_FILE = " BACKGROUND.CAF " -- CAF format else MUSIC_FILE = " Background.mp3 " -- mp3 format end local line_space = 40 local function cocosdenshiontest () local RET = CC. Layer:create () local m_pItmeMenu = nil local m_tbeginpos =  CC.P (0, 0) local m_nSoundId = 0 -- Test Menu Items local testItems = { "Play background music", "Stop background music", "Pause background music", " Resume background music ", " Rewind background music ", "is background music playing", "Play effect", "play effect repeatly", "Stop effect", "Unload effect", &Nbsp; "Add background music volume", Sub background music volume ", " Add effects volume ", "Sub effects volume", Pause effect ", " Resume effect ", " Pause all effects ", " Resume all effects ", "Stop all effects" } -- Menu callback Method local function menucallback (Tag, pmenuitem) local nidx = pmenuitem:getlocalzorder () - 10000 -- play background music if nidx == 0 then audioengine.playmusic (MUSIC_FILE, true) -- Play Music