Created
December 19, 2012 16:59
-
-
Save egm0121/4338271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Forward references | |
local soundID | |
-- Determine the platform type | |
-- "iPhoneOS" or "Android" or "Mac OS X" | |
-- | |
local isAndroid = "Android" == system.getInfo("platformName") | |
local isSimulator = "simulator" == system.getInfo("environment") | |
-- Preload the sound file (needed for Android) | |
-- | |
if isAndroid or isSimulator then | |
-- print("MP3") | |
soundID = audio.loadSound( "beep_mp3.mp3" ) -- for Android | |
else | |
-- print("CAF") | |
--soundID = media.newEventSound( "beep_caf.caf" ) -- for IOS | |
end | |
-- Play sound | |
-- | |
local playBeep = function() | |
local mychannel, mysource = audio.play( soundID ) | |
al.Source(mysource, al.PITCH, 2.0); | |
end | |
-- Displays App title | |
title = display.newText( "Event Sound", 0, 30, "Verdana-Bold", 20 ) | |
title.x = display.contentWidth/2 -- center title | |
title:setTextColor( 255,255,0 ) | |
msg = display.newText( "Listen for sound every 1 second", 0, 0, "Verdana-Bold", 14 ) | |
msg.x = display.contentWidth/2 -- center title | |
msg.y = display.contentHeight/2 -- center title | |
msg:setTextColor( 255,255,255 ) | |
-- Set up timer to play sound every second | |
-- | |
timer.performWithDelay( 1000, playBeep, 0 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment