Question about media.playSound

I have found the media.playSound function, but I do have a question about one thing.

I am using the voice recording and currently have the below code

media.playSound( “playerSound.aif”, system.DocumentsDirectory )

“playerSound.aif” is the file that saves what the player records and I have gotten this to work perfectly

I was reading the documentation, I see that it has the ability to add an on complete function, but I can seem to figure out how the code should go.

media.playSound( soundfile [, baseDir] [, onComplete] )

Im not quite sure what the [] are for or how to use them. As you can see in my above code, I am able to define the base directory without using the brackets, yet when I try to edit my code to the following

media.playSound( “playerSound.aif”, system.DocumentsDirectory, onComplete = calledFunction )

It does not seem to work, if I try and add in the brackets, to something like this

media.playSound( “playerSound.aif” [, system.DocumentsDirectory] [, onComplete = calledFunction] )

I end up getting and error saying that “]” is expected.

Any tips on how im supposed to include the onComplete portion and how I am supposed to format it.

Hi @EthanDunlap,

In syntax shown in documentation, it’s somewhat “standard” that brackets indicate an optional parameter/argument… but you’re not supposed to include the actual brackets.

So if you see this syntax:

[lua]

media.playSound( soundfile [, baseDir] [, onComplete] )

[/lua]

… only the first parameter (soundfile) is required. As for the “onComplete” param, it’s supposed to just be a reference to the listener function, not specified as a Lua key-value pair. So, yours might look like this:

[lua]

media.playSound( “playerSound.aif”, system.DocumentsDirectory, calledFunction )

[/lua]

Hope this helps,

Brent

Hi @EthanDunlap,

In syntax shown in documentation, it’s somewhat “standard” that brackets indicate an optional parameter/argument… but you’re not supposed to include the actual brackets.

So if you see this syntax:

[lua]

media.playSound( soundfile [, baseDir] [, onComplete] )

[/lua]

… only the first parameter (soundfile) is required. As for the “onComplete” param, it’s supposed to just be a reference to the listener function, not specified as a Lua key-value pair. So, yours might look like this:

[lua]

media.playSound( “playerSound.aif”, system.DocumentsDirectory, calledFunction )

[/lua]

Hope this helps,

Brent