Can't Access an audio file from System.DocumentsDirectory on a device

Hi there!

I am having a problem with playing/accessing an audio file that is placed into the system.documentsdirectory.  

I need code to access an audio recording file in system.documentsdirectory on an ** iPhone.**

I can’t seem to figure it out! I have tried:

local path = system.pathForFile( “newRecording.aif”, system.DocumentsDirectory)

audio.play(path)

However, no audio file plays on a device… :frowning:

All help is appreciated! Thanks!
 

-Max Goldberg

Now are you getting the file into the system.DocumentsDirectory?

Rob

@rob

This is the code I am using to record and save the audio file: 

[lua]

local function createRecording(event)

if (event.phase == “began”) then

local filePath = system.pathForFile( “newRecording.aif”, system.DocumentsDirectory )

r = media.newRecording( filePath )

r:startRecording()

end

end

button = display.newCircle( 100, 100, 50 )

button:addEventListener(“touch”, createRecording )[/lua]

After the audio is recorded and saved to system.documentsdirectory, I checked the sandbox in the corona simulator AND device and the audio file IS correctly saved.  

@rob

I am using Parse to upload the audio file and link it to an object. This object also contains the destination object ID of the person the file will be sent to. The file once received by the other device, will be downloaded into that user’s system.documentsdirectory.  All of this works perfectly except when I try to play the audio on the target user’s device. I am not trying to play the audio file in terms of background music.  My ultimate goal is to use the audio recording as a parse push notification sound.  

This is my code: 

[lua]parse.request( parse.Push.send )

 :data( { channels = {gamesettings.channel}, data = { alert = “MEGAPHONE!”, sound = path } } )

 :response(cb)[/lua]

For the sound parameter, it is currently set to path.  I need path to somehow access the audio recording that is save in system.documentsdirectory.  I know for a fact that it IS saving the file. 

How I can access the audio file in system.documentsdirectory for the sound parameter of the ** notification?**

Thanks for all help!

@nmichaud

@develephant

You might just be missing a step in the audio API:

local handle = audio.loadSound("newRecording.aif", system.DocumentsDirectory) audio.play(handle)

Are  you by any chance trying to upload the file before it’s created?  I see where you start the recording, but I don’t see where you end the recording. Some of these things are asynchronous and it might be a case of where you’re trying to upload before the recording is done.

In your first post, you most certainly need to call audio.loadSound() or audio.loadStream() before you call audio.play() as @StarCrunch said.

Rob

Now are you getting the file into the system.DocumentsDirectory?

Rob

@rob

This is the code I am using to record and save the audio file: 

[lua]

local function createRecording(event)

if (event.phase == “began”) then

local filePath = system.pathForFile( “newRecording.aif”, system.DocumentsDirectory )

r = media.newRecording( filePath )

r:startRecording()

end

end

button = display.newCircle( 100, 100, 50 )

button:addEventListener(“touch”, createRecording )[/lua]

After the audio is recorded and saved to system.documentsdirectory, I checked the sandbox in the corona simulator AND device and the audio file IS correctly saved.  

@rob

I am using Parse to upload the audio file and link it to an object. This object also contains the destination object ID of the person the file will be sent to. The file once received by the other device, will be downloaded into that user’s system.documentsdirectory.  All of this works perfectly except when I try to play the audio on the target user’s device. I am not trying to play the audio file in terms of background music.  My ultimate goal is to use the audio recording as a parse push notification sound.  

This is my code: 

[lua]parse.request( parse.Push.send )

 :data( { channels = {gamesettings.channel}, data = { alert = “MEGAPHONE!”, sound = path } } )

 :response(cb)[/lua]

For the sound parameter, it is currently set to path.  I need path to somehow access the audio recording that is save in system.documentsdirectory.  I know for a fact that it IS saving the file. 

How I can access the audio file in system.documentsdirectory for the sound parameter of the ** notification?**

Thanks for all help!

@nmichaud

@develephant

You might just be missing a step in the audio API:

local handle = audio.loadSound("newRecording.aif", system.DocumentsDirectory) audio.play(handle)

Are  you by any chance trying to upload the file before it’s created?  I see where you start the recording, but I don’t see where you end the recording. Some of these things are asynchronous and it might be a case of where you’re trying to upload before the recording is done.

In your first post, you most certainly need to call audio.loadSound() or audio.loadStream() before you call audio.play() as @StarCrunch said.

Rob