sandbox directories

took code from example in forum

local path = system.pathForFile(  “”, system.CachesDirectory )

download from website :

       network.download(“http://www.(my website)/sarah.mp3”, “GET”,networkListener, params,“sarah.mp3”,system.CachesDirectory)

this works and downloads and saves file to system.CachesDirectory , I can manually goto the directory and play the file.

THEN…

this does not work

               Music = audio.loadStream(path…"/sarah.mp3" )

                audio.play(Music)

error message :

audio.loadStream() failed to create stream ‘/Users/rogerholmes/Library/Application Support/Corona Simulator/isaacsTalent-C0BC209F9D0AC7DA65823045F566D1B6/Caches/sarah.mp3’

what am I doing wrong?

  1. The way you are building that path for the load call is wrong.  Please do this:

    audio.loadStream( “sarah.mp3”, system.CachesDirectory )

It is intended that you build the path yourself in this case.  By doing it the way you did, you’ll get 

RESOURCE DIRECTORY + CACHES DIRECTORY PATH COMBINED.

All major file accessing Corona functions (newImageRect(), loadStream(), loadSound(), …) have a ‘baseDir’

argument. 

You should ONLY be building file paths yourself (by using pathForFile() when using Lua io. and lfs. functions).**

  1. Why are you using the caches folder instead of the documents folder? 

  2. Be aware, that is NOT backed up on iOS.

  3. Please always format code posts:

formatyourcode.jpg

Hi Ed,

 Music = audio.loadStream( "sarah.mp3", system.CachesDirectory )  

Yes I have tried that with the error

“/Users/rogerholmes/Library/Application Support/Corona Simulator/isaacsTalent-C0BC209F9D0AC7DA65823045F566D1B6/Caches”

WARNING: /Users/rogerholmes/Desktop/isaacsTalent/mainscreen.lua:204: audio.loadStream() failed to create stream ‘sarah.mp3’

its interesting that ;

 local fhd = io.open( path ) -- Determine if file exists if fhd then print( "File exists" ) print(path) fhd:close() -- media.playSound(path.."/113.mp3") else print( "File does not exist!" ) end

returns “File Exists”

Have you seen my updates to the post above, and what about my other questions?

PS - Can you load it with loadSound()?  It may be you simply can’t stream from the caches folder.

PPS - Sorry, but I often go back and tweak my posts.

sorry Ed, I was out of office … I just saw your updates

I have tried CachesDirectory, DocumentsDirectory and Temporary dirs…

all with same result.

"You should ONLY be building file paths yourself (by using pathForFile() when using Lua io. and lfs. functions)"**

Thanks I did not know this…

pathForFile()

I could be wrong about that (pathforFile()), but since the functions have the baseDir parameter, it make sense to me that this implies a specific usage using it and not a fully built path.

I’m very puzzled as to why you can’t play that file.

Questions/Ideas

  • Have you tried inserting a delay between the time it is downloaded and then trying to play it?  I wonder if the file is locked or something.
  • Assuming you’re trying this in the simulator, can you play the downloaded file in another program?  i.e. Go get it and test it is not corrupted.

Ed Wrote :

  • Have you tried inserting a delay between the time it is downloaded and then trying to play it?  I wonder if the file is locked or something.

Bingo that was it…  a little loop never hurt nobody  :slight_smile:

  1. The way you are building that path for the load call is wrong.  Please do this:

    audio.loadStream( “sarah.mp3”, system.CachesDirectory )

It is intended that you build the path yourself in this case.  By doing it the way you did, you’ll get 

RESOURCE DIRECTORY + CACHES DIRECTORY PATH COMBINED.

All major file accessing Corona functions (newImageRect(), loadStream(), loadSound(), …) have a ‘baseDir’

argument. 

You should ONLY be building file paths yourself (by using pathForFile() when using Lua io. and lfs. functions).**

  1. Why are you using the caches folder instead of the documents folder? 

  2. Be aware, that is NOT backed up on iOS.

  3. Please always format code posts:

formatyourcode.jpg

Hi Ed,

 Music = audio.loadStream( "sarah.mp3", system.CachesDirectory )  

Yes I have tried that with the error

“/Users/rogerholmes/Library/Application Support/Corona Simulator/isaacsTalent-C0BC209F9D0AC7DA65823045F566D1B6/Caches”

WARNING: /Users/rogerholmes/Desktop/isaacsTalent/mainscreen.lua:204: audio.loadStream() failed to create stream ‘sarah.mp3’

its interesting that ;

 local fhd = io.open( path ) -- Determine if file exists if fhd then print( "File exists" ) print(path) fhd:close() -- media.playSound(path.."/113.mp3") else print( "File does not exist!" ) end

returns “File Exists”

Have you seen my updates to the post above, and what about my other questions?

PS - Can you load it with loadSound()?  It may be you simply can’t stream from the caches folder.

PPS - Sorry, but I often go back and tweak my posts.

sorry Ed, I was out of office … I just saw your updates

I have tried CachesDirectory, DocumentsDirectory and Temporary dirs…

all with same result.

"You should ONLY be building file paths yourself (by using pathForFile() when using Lua io. and lfs. functions)"**

Thanks I did not know this…

pathForFile()

I could be wrong about that (pathforFile()), but since the functions have the baseDir parameter, it make sense to me that this implies a specific usage using it and not a fully built path.

I’m very puzzled as to why you can’t play that file.

Questions/Ideas

  • Have you tried inserting a delay between the time it is downloaded and then trying to play it?  I wonder if the file is locked or something.
  • Assuming you’re trying this in the simulator, can you play the downloaded file in another program?  i.e. Go get it and test it is not corrupted.

Ed Wrote :

  • Have you tried inserting a delay between the time it is downloaded and then trying to play it?  I wonder if the file is locked or something.

Bingo that was it…  a little loop never hurt nobody  :slight_smile: