Problem with playing downloaded media files

Hey everyone

I’m having some annoying problems, that I can’t seem to find a solution for.

I’m trying to download a video file from an Amazon AWS storage server, and then saving it into an android device. Im getting binary code (i guess) in return, and after the complete download has been made, I’ll then try to save it.

The original fileformat have codex ‘H.264, AAC’, a kind ‘MPEG-4’ format and have an extension of ‘.mp4’.

It works well when I try to play it in the simulator, but dont work when I try to load it on a device.

Simular files is downloaded with the app itself, and they work fine, so I guess it has something to do with the way I save the downloaded files, and to be honest, I don’t know that much about encoding in general.

local objectName = objPath..objName local path = "http://" .. self.host .. "/" .. objectName local httpRequest = { method = 'GET', url = path, headers = getHeaders(nil, nil), body = {}, proxy = PROXY, } addAuthorizationHeader(httpRequest.method, self.bucketName, objectName, httpRequest.headers) local filepath = system.pathForFile(objName, system.DocumentsDirectory) local function networkListener( event ) listener(event, filepath) if ( event.isError ) then print( "Network error - download failed" ) elseif ( event.phase == "began" ) then print( "Progress Phase: began", event.bytesEstimated ) elseif(event.phase == "progress") then --print (event.bytesTransferred, event.response, event.isError) elseif ( event.phase == "ended" ) then local file, err = io.open(filepath, "wb") if file then file:write(event.response) io.close(file) return true else print("Save error on open: ", err) end end end local params = { progress = true, headers = httpRequest.headers, } network.download( path, "GET", networkListener, params, objectName, system.DocumentsDirectory )

The ‘goodnight_1’ files is allready located on the device, and it works fine, but the rest doesn’t.

local function getVideoPath(name) local path, root if name == 'goodnight\_1' then path = dir.videos..GROUP.."/"..name..".mp4" root = system.ResourceDirectory else path = \_myData[GROUP].nameToAlias[name] root = system.DocumentsDirectory end return path, root end function getVideoFrame(e) if(not activeVideo and e.group == GROUP) then local path, root = getVideoPath(e.targetName) print('test', system.pathForFile( path, root ) ) activeVideo = media.playVideo( path, root, true, closeVideoFrame ) end end

When I loop through the possible files, to check if they are on device, I get the result I suspect. 

for i,v in ipairs(\_myData['goodnight'].icons) do local path, root if i == 1 then path = dir.videos.."goodnight/"..v..".mp4" root = system.ResourceDirectory else path = \_myData['goodnight'].nameToAlias[v] root = system.DocumentsDirectory end print(v,path) local dir = system.pathForFile( path, root ) local fh, reason = io.open( dir, "r" ) if fh then self.btns[v].indi:setFillColor( 0,1,0 ) io.close( fh ) else self.btns[v].indi:setFillColor( 1,0,0 ) end end

Any idea? Because I’m completely stock on this one!

Okay, I’ve not tried with at simpler demo project where it doesn’t work either. Hmm… I’ve tried both 2,5,10,20 and 50 mb files. It must have something to do with the method im using.

Can you possibly make a small sample with your problem that we can build and see whats and how its not working?

Thank!

NOTE – I’m on windows.

Ill try to build a sample without the complicated access functions I have to Amazon :). Be back in 10 min

Okay, Ill try send the files to you in a small demo project. I have to attack a rather large amount of ekstra files, since Amazon can be a bitch to login to.

Okay, I’ve not tried with at simpler demo project where it doesn’t work either. Hmm… I’ve tried both 2,5,10,20 and 50 mb files. It must have something to do with the method im using.

Can you possibly make a small sample with your problem that we can build and see whats and how its not working?

Thank!

NOTE – I’m on windows.

Ill try to build a sample without the complicated access functions I have to Amazon :). Be back in 10 min

Okay, Ill try send the files to you in a small demo project. I have to attack a rather large amount of ekstra files, since Amazon can be a bitch to login to.