How to record and play back audio using media.newRecording

I’ve created 3 squares. I want the first square to record and save the recording. Second square to stop the recording. Third square to get the recording and play it back.

I’m able to get a response when I use the app on my computer, but the results aren’t very clear(I don’t have a mic). When I test on my phone I don’t get any response.

How to make this app work?

 

function startRecording ()
print( “startRec tap” )
recordPath = system.pathForFile( “recordings.wav”, system.DocumentsDirectory )
recording = media.newRecording( recordPath )
recording:startTuner( )
recording:startRecording( )

proof1 = display.newText( “proof1”, 80, 300,nil , 20 )
end

function stopRecording( )
print( “stopRec tap” )
proof2 = display.newText( “proof2”, 280, 300,nil , 20 )
recording:stopRecording( )
recording:stopTuner( )
end

function playRecording ()
print( “Play back recording” )
findRecording = audio.loadSound( “recordings.wav” , system.DocumentsDirectory )
audio.play( findRecording)
proof3 = display.newText( “proof3”, 400, 300,nil , 20 )
end

 

 

 

*UPDATE: I’ve loaded an .wav file with actual sound into the system.DocumentsDirectory. Results: It works in corona simulator(hear sound), but it doesn’t work on my phone (no sound). ***I believe the problem is that my phone can’t access the files in system.DocumentsDirectory.

 

Following is my code that I’ve edited to test, and sample.wav is audio that has actual sound.

 

function playRecording ()

print( “Play back recording” )
findRecording = audio.loadSound( “sample.wav” , system.DocumentsDirectory )
audio.play( findRecording)
proof3 = display.newText( “proof3”, 400, 300,nil , 20 )
end

Thank you for your time

Anyone…?

Sorry I just read your whole post and I don’t have an answer.  Thought I did.  Deleted my post.

Hi @znick46,

Which device (phone) are you testing on?

Brent

Hi Brent,

I’m testing on LG G2

Thanks

Hi @znick46,

Did you include the proper Android permissions as noted in the documentation?

http://docs.coronalabs.com/api/library/media/newRecording.html

Brent

Yes, I have:

  android =

    {

        usesPermissions =

        {

            “android.permission.RECORD_AUDIO”,

        },

    },

    

I see the notification when I install it on my phone too.

Hi @znick46,

Have you tested our sample project for this functionality? It’s located in your local application directory here:

CoronaSDK > SampleCode > Media > SimpleAudioRecorder

Please test this, inspect the code, and report back the results.

Thanks,

Brent

Status update: Tested the sample code for SimpleAudioRecorder on my LG G2 mobile phone, and the app works perfect. I can record, and hear sound.

Currently trying to figure out how to make mine work :stuck_out_tongue:

I’ve created a new project, and in the main.lua file only inserted the code:

    loadAudio = audio.loadSound( “loopy.mp3” , system.DocumentsDirectory )

    audio.play( loadAudio  ) 

In the Corona Simulator I hear music, but on my phone I can’t hear anything. I think my phone can detect the loopy.mp3, because when I toggle buttons on my phone to adjust volume, it adjust media volume(I’ve had the G2 for a while so it’s something I’ve picked up from using it).

I’m so confused of what the problem is. I must be missing something critical.

Anyone…?

Sorry I just read your whole post and I don’t have an answer.  Thought I did.  Deleted my post.

Hi @znick46,

Which device (phone) are you testing on?

Brent

Hi Brent,

I’m testing on LG G2

Thanks

Hi @znick46,

Did you include the proper Android permissions as noted in the documentation?

http://docs.coronalabs.com/api/library/media/newRecording.html

Brent

Yes, I have:

  android =

    {

        usesPermissions =

        {

            “android.permission.RECORD_AUDIO”,

        },

    },

    

I see the notification when I install it on my phone too.

Hi @znick46,

Have you tested our sample project for this functionality? It’s located in your local application directory here:

CoronaSDK > SampleCode > Media > SimpleAudioRecorder

Please test this, inspect the code, and report back the results.

Thanks,

Brent

Status update: Tested the sample code for SimpleAudioRecorder on my LG G2 mobile phone, and the app works perfect. I can record, and hear sound.

Currently trying to figure out how to make mine work :stuck_out_tongue:

I’ve created a new project, and in the main.lua file only inserted the code:

    loadAudio = audio.loadSound( “loopy.mp3” , system.DocumentsDirectory )

    audio.play( loadAudio  ) 

In the Corona Simulator I hear music, but on my phone I can’t hear anything. I think my phone can detect the loopy.mp3, because when I toggle buttons on my phone to adjust volume, it adjust media volume(I’ve had the G2 for a while so it’s something I’ve picked up from using it).

I’m so confused of what the problem is. I must be missing something critical.