Game Development Reference
In-Depth Information
function getfilename(thisFile)
local thePath = system.pathForFile( thisFile, system.ResourceDirectory)
return thePath
end
--
function playNextTrack()
currentTrack = currentTrack + 1
if currentTrack > #listMP3 then currentTrack = 1 end
media.playSound(getfilename(listMP3[currentTrack]), playNextTrack)
end
--
playNextTrack()
getfilename , which returns the file path to the track,
ResourceDirectory on the mobile device. So, with the system.
function, we get the full path, prefixing the file with the passed directory. The function
/ , plus the file name.
media namespace offers an easy way to do so:
media.stopSound()
media.pauseSound()
We can also increase or decrease the volume by using the following functions:
media.getSoundVolume()
media.setSoundVolume()
The volume is expressed as a real number that has the range from 0 to 1.0, with 0 being silent and
1.0 being the loudest possible volume. Here's some code to increase or decrease the volume in
increments of 10 percent:
function increaseVolume()
local currVol = media.getSoundVolume ( )
if currVol >= 1.0 then return end -- Already at the max volume
media.setSoundVolume ( currVol+0.1 )
end
--
function decreaseVolume()
local currVol = media.getSoundVolume ( )
if currVol <= 0 then return end -- Already at the min volume
media.setSoundVolume ( currVol-0.1 )
end
 
Search WWH ::




Custom Search