Hi
please can someone help.
I am just trying to download and play an mp3 sound file from internet
but im getting an error as below in simulator
“cannot create path for resource file 113.mp3”
here is my code:
local function networkListener( event )
if ( event.isError ) then
print( “Network error!”)
elseif ( event.phase == “began” ) then
if event.bytesEstimated <= 0 then
print( “Download starting, size unknown” )
else
print( "Download starting, estimated size: " … event.bytesEstimated )
end
elseif ( event.phase == “progress” ) then
if event.bytesEstimated <= 0 then
print( "Download progress: " … event.bytesTransferred )
else
print( "Download progress: " … event.bytesTransferred … " of estimated: " … event.bytesEstimated )
end
elseif ( event.phase == “ended” ) then
print( "Download complete, total bytes transferred: " … event.bytesTransferred )
local path = system.pathForFile( “113.mp3”, system.DocumentsDirectory )
local fhd = io.open( path )
– Determine if file exists
if fhd then
print( “File exists” )
--media.playSound( ‘113.mp3’ )
media.playSound( ‘113.mp3’ )
fhd:close()
else
print( “File does not exist!” )
end
– media.playSound( ‘113.mp3’ )
end
end
local params = {}
– This tells network.request() that we want the ‘began’ and ‘progress’ events…
params.progress = “download”
– This tells network.request() that we want the output to go to a file…
params.response = {
filename = “113.mp3”,
baseDirectory = system.DocumentsDirectory
}
network.request( “http://www.qurantour.com/Alafasy/113.mp3”, “GET”, networkListener, params )