Type Function Library media.* Return value none Revision 2017.3060 Keywords media, sound, event sound, audio See also audio.* media.newEventSound()
Plays an event sound (1-3 seconds). The first argument may be either an event sound ID or a filename for the event sound. This is recommended for short sounds, especially to avoid performance hiccups.
On iOS devices and the Xcode iOS Simulator, the only supported sound formats are .caf
and .aif
. These formats must be uncompressed or they will not play.
On Android devices, the only supported sound formats are .mp3
and .ogg
.
The Corona Simulator supports .caf
, .aif
, and .mp3
formats.
For Android devices, the sound should be preloaded with the media.newEventSound() API.
There is no volume control API for event sounds. It is intended for alert sounds and the volume is controlled by the device's hardware controls.
media.playEventSound( sound [, baseDir] [, completionListener] )
Userdata or String. The first argument is either an event sound ID
Constant. If specified, this argument is the directory where the sound file is located, if you specified a filename for sound
. The default is system.ResourceDirectory
. Other options include:
system.DocumentsDirectory
system.ApplicationSupportDirectory
system.TemporaryDirectory
system.CachesDirectory
Function. If specified, a listener function that will be called each time the event sound is played. Note, however, that Android does not support this functionality.
local soundID = media.newEventSound( "beep.caf" ) local playBeep = function() media.playEventSound( soundID ) end timer.performWithDelay( 7500, playBeep, 0 )