Antonios
Antonios

Reputation: 221

Adobe Flex AIR download videos in Android device

I want to download a set of video files to a default folder path in an Android device and then have access to the path and files. The FileReference class does not support this features. Is there another way? Thank you.

Upvotes: 2

Views: 538

Answers (1)

vjuliano
vjuliano

Reputation: 1503

I dont use file reference at all. I use a Loader to download the file. I then create a new File object with the path where I want to save the file, and use a FileSteam to write the data from the loader to the file.

var req:URLRequest = new URLRequest(url);
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, handler);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(req);

function handler(e:Event):void{
    var file:File = new File(path);
    var stream:FileSteam();
    steam.open(file, FileMode.WRITE);
    steam.writeBytes(loader.data);
    steam.close();
}

something like this should accomplish what you are looking for. I wrote this code from memory so it may not be exactly correct but should be good enough to get you going. Make sure you put this in a try/catch since file and filesteam both throw exceptions

Upvotes: 1

Related Questions