media.playEventSound()

Type Function
Library media.*
Return value none
Revision 2017.3110
Keywords media, sound, event sound, audio
See also media.newEventSound()
media.playSound()

Because of various limitations outlined below, it is recommended that the audio library be used for playing back audio.

Overview

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 function is recommended for short sounds, especially to avoid performance hiccups.

Gotchas

Syntax

media.playEventSound( sound [, baseDir] [, completionListener] )
sound (required)

Userdata or String. The first argument is either an event sound ID (from media.newEventSound()) or a filename for the event sound.

baseDir (optional)

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
completionListener (optional)

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.

Example

local soundID = media.newEventSound( "beep.caf" )

local playBeep = function()
    media.playEventSound( soundID )
end

timer.performWithDelay( 7500, playBeep, 0 )