Downloading assets?

Monkey Forums/Monkey Programming/Downloading assets?

Aman(Posted 2012) [#1]
Is there a way to download images and sound files from the internet and use them in your games and apps?

I have a number of educational apps that supports 6 languages and each language has over 30 sound files.

Anyone has an idea about how to do this?


Gerry Quinn(Posted 2012) [#2]
Your question is extremely general.

Google for things like "royalty free images", "free images", "download icons" and such like (same for sounds and music).

Of course every search will give you all sorts of things, you need to get a feel for what the sites have, which can be anything between licensing stuff for a fee, totally public domain stuff, and pirated stuff.

Downloading can involve anything between "click here to download" buttons, "save image as" option on your browser, or even Shift-PrintScr and paste into your painting program.

You'll want some sort of graphics program and maybe a sound editor too to work with them.

If you have more specific questions, ask.


bruZard(Posted 2012) [#3]
I think Aman would like to know how he can loading assets during runtime ;)


Gerry Quinn(Posted 2012) [#4]
Ah I see, I didn't look at the name - I know Aman is a prolific poster who would not be asking what I thought was the question.

Thought it was some total noob ;-)


Gerry Quinn(Posted 2012) [#5]
In Flash you can probably use LoadURL() to get stuff from the website your app is on.


Paul - Taiphoz(Posted 2012) [#6]
that would only be single instance tho, and would probably need done each run.

I'm not sure but I think downloading stuff to a mobile might prove to be very difficult, it might be better to jsut release a version for each language.


Skn3(Posted 2012) [#7]
I think it is probably easier then you think. Example for ios:
http://iphonedevelopertips.com/cocoa/download-and-create-an-image-from-a-url.html

The difficult part will be to get it to play nicely with mojo...

You could always wrap something like https://github.com/enormego/EGOImageLoading into a monkey specific framework. That was from a quick google search so I am sure there are solutions for other targets readily available...


Soap(Posted 2012) [#8]
I don't see why it wouldn't be possible with every target.


Aman(Posted 2012) [#9]
What I want to do is to download the data for the first time only.

Sorry for not being clear enough. I found out how to do it for iPhone. I am looking for away to do it on Android now.

For those interested in learning how to do this. Here is an example

-(void)downloadAsset:(NSURL *)url{
NSURLRequest *request = [NSURLRequestrequestWithURL:url];
NKAssetDownload *assetDownload = [issue addAssetWithRequest:request];
[asset downloadWithDelegate:self]; //This will start the download
}


We also have to handle the download process. There are three methods that can be implemented:
- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)
totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes{}

which will be called repeatedly as long as the file is being downloaded and is NOT required.
- (void)connectionDidResumeDownloading:(NSURLConnection *)connection totalBytesWritten:(long long)
totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes{}

which will be called when the download is resumed and is NOT required as well.
- (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL{}

which will be called when the download is finished and is REQUIRED. The file need to be moved to the appropriate folder since it can be deleted as soon as we leave this method.

Apple's Docs:
http://goo.gl/kqhKf


For Android, there is no way to add assets. All you can do is download them to internal memory or SD card. and then find away to load them into your application. I have created a file stream module long time ago. I think I will be able to use that with little modifications to load assets from the phone's memory into the app when it starts. Anyone interested in knowing the results?