Hi
I am simply trying to download an mp3 or sound file from internet to be played on android device
can somebody help me get this working,
shows error as
"cannot create path for resource file "
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’ )
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 )