media.newRecording()

Type Function
Library media.*
Return value Recording
Revision 2017.3060
Keywords media, recording, audio
See also object:startRecording
object:stopRecording
media.playSound()

Overview

Create an object for audio recording (Recording).

Gotchas

General

This API is not supported on Windows Phone or tvOS.

Android

  • On Android, to enable audio recording on devices, you must set the permission level in the build.settings file:
settings =
{
    android =
    {
        usesPermissions =
        {
            "android.permission.RECORD_AUDIO",
        },
    },
}
  • On Android, the default format for recorded files is .wav. To record to the .3gp format, simply append .3gp to the end of the path. Note that .3gp files can only be played by the media.playSound() function.

iOS

On iOS, to enable audio recording on devices, you must include the following keys/descriptions in the plist table of build.settings. When the system prompts the user to allow access, the associated description is displayed as part of the alert. Note that these descriptions can be customized to your preference and they can even be localized (guide).

settings =
{
    iphone =
    {
        plist =
        {
            NSMicrophoneUsageDescription = "This app would like to access the microphone.",
        },
    },
}

Syntax

media.newRecording( [path] )
path (optional)

String. The path of the file in which to record audio data. If no file is specified, the output goes nowhere.

Supported Formats

The following platforms can only record to the following audio formats:

Platform Supported Audio Formats
iOS .aif
Android .wav (default), .3gp (not supported by the "Nabi 2" tablet)
macOS .aif
Windows .wav

Example

local filePath = system.pathForFile( "newRecording.aif", system.DocumentsDirectory )
r = media.newRecording( filePath )
r:startRecording()