Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------
- MUSIC LIB CLASS (MusicLib.lua)
- --------------------------------------
- local _M = {}
- local audioChannel
- local otherAudioChannel
- local currentSong
- local curAudio
- local prevAudio = 1
- audio.crossFadeBackground = function (path, force)
- local musicPath = path
- if currentSong == musicPath and audio.getVolume{channel = audioChannel} > 0.1 and not force then return false end
- audio.fadeOut({channel=audioChannel, time=1000})
- if audioChannel==1 then audioChannel,otherAudioChannel=2,1 else audioChannel,otherAudioChannel=1,2 end
- audio.setVolume( 1, {channel = audioChannel})
- curAudio = audio.loadStream( musicPath )
- audio.play(curAudio, {channel=audioChannel, loops=-1, fadein=1000})
- prevAudio = curAudio
- currentSong = musicPath
- audio.currentBackgroundChannel = audioChannel
- end
- audio.reserveChannels(2)
- audio.currentBackgroundChannel = 1
- return _M
- -------------------
- usage in i.e main.lua
- --------------------
- local mL = require ( "MusicLib" )
- audio.crossFadeBackground("bgSplashSound.mp3") --dont work....ahhh carrrrramba!! I dont get it!!
- -- Its written in a way I don't write
- --so I get confused
- --Is this a private method for internal
- --handling in my class?
- --[[
- --------------------------------------
- Here are the original MusicLib Class I wrote earlier that works partially
- --------------------------------------
- local _M = {}
- gemSound = {[1]="blopSound2.mp3", [2]="failSound.mp3", [3]="blopBlopSound.mp3"}
- bgSound = {[1]="bgSplashSound.mp3", [2]="failSound.mp3", [3]="blopBlopSound.mp3"}
- _M.blopSound = audio.loadSound(gemSound[1])
- _M.failSound = audio.loadSound(gemSound[2])
- _M.blopBlopSound = audio.loadSound(gemSound[3])
- function _M:bgMusic(levelTrack)
- local fChannel = audio.findFreeChannel ()
- _M.backgroundMusic = audio.loadStream(bgSound[levelTrack])
- audio.play(_M.backgroundMusic, { loops=-1, channel= fChannel })
- end
- function _M:bgMusicFadeOut()
- audio.fadeOut({ time=500 } )
- audio.dispose(backgroundMusic)
- audio.dispose(blopSound)
- audio.dispose(failSound)
- audio.dispose(blopBlopSound)
- _M.backgroundMusic = nil
- _M.blopSound = nil
- _M.failSound = nil
- _M.blopBlopSound = nil
- return true
- end
- return _M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement