Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------
- -- 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
- -------------------------------------------------------
- -- ANY FILE YOU LIKE THIS FUNCTION IN:
- -------------------------------------------------------
- require ( "MusicLib" )
- audio.crossFadeBackground("yourMusicFile.mp3", 1)
- -- IF YOU WANT THIS TO WORK IN I.E. COMPOSER OR STORYBOARD, JUST PUT THE LINE IN ENTERSCENE LIKE:
- --STORYBOARD:
- function scene:enterScene( event )
- local screenGroup = self.view
- audio.crossFadeBackground("yourMusicFile.mp3", 1)
- end
- -- COMPOSER:
- function scene:show( event )
- local sceneGroup = self.view
- local phase = event.phase
- if ( phase == "will" ) then
- audio.crossFadeBackground("yourMusicFile.mp3", 1)
- elseif ( phase == "did" ) then
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement