download large video files to iPhone - iphone

I want to download a large video file to Iphone in my app. I used NSURLConnection and saving the file to disk once it completly downloads the video.
As my video is large, it is crashing in middle.
Is there anyway like directly saving the file to disk without keeping it in memory.
Thanks,

NSURLConnection calls a method you can write called
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
which receives the data in smaller chunks. You can save that data to a file as you receive it.
Here is Apple's doc on NSURLConnection, which gives more details.
Also note that you risk app-store rejection if you're retrieving a large amount of data via Edge or 3G, although using wireless is safe: app rejected reason.

Your app crashes because you can't have this much data into your system's memory.
I recently wrote a little and very easy library to do that. It uses NSURLConnection and won't cause your app to crash because the data is directly written to a file while downloading. Also, you can download multiple files at once and many other things...
You can have it here!

Related

Can MpMoviePlayer get it's data from an NSInputStream

I have an iPad app which has a network connection from another iPad. On the client iPad, I want to be able to take data from a NSInputStream (which comes from the server iPad), and play it in MpMoviePlayer as it downloads from the server iPad.
I know that I can download the entire video, save it to a file, and open it in media player, but I want to be able to start playing before the full file has been downloaded.
I have NOT tried saving a chunk of it to the file and playing it, then adding to the file as it becomes available in the stream, because a) the file is likely to get locked, and b) the movieplayer is likely to open the file and read it into an internal cache, so adding to the file later won't (I don't think) play the new content. I'm willing to try it down the road, if nobody has any brilliant ideas, but I give it a very low likelihood of working - I'd guess a 10% chance of success.
If MpMoviePlayer had an initWithData method, I would simply give it a NSMutableData, and add to the data as it became available to the stream, but I don't see a method like that. Does anyone have any ideas for how I can do this?

iPhone: Efficiently downloading images from a URL into iPhone App

In my iPhone app , I need to display the images from server.
I need to download it and save it from URLs.
There are roughly 20 images which I need to download.
What could be a way out where in performance doesnt decrease?
I have tried previously using NSData to convert the images into NSData and saving it to my app but it takes lots of time.
What could be a more easier and efficient way out?
I recommend using ASIHTTPRequest to download the images asynchronously, and display them when they're ready. By using the asynchronous interface of that class, your app can be responsive and continue to operate normally while, in the background, you wait for the data to be loaded.
ASIHTTPRequest is open source and free to use: http://allseeing-i.com/ASIHTTPRequest/
The code the Facebook app uses to download and display images has been open-sourced as part of the three20 library.
If you want to write your own networking code ASIHTTPRequest is a very useful library that includes features such as downloading directly to a file and queue management.

getting data from server and store in the iPhone

i want to develop an iPhone app where the app downloads data (say audio clips) from a specified server and stores it locally on the device.
then the app should use the data stored in the device rather than stream it from the server.
could anybody give me the guidelines as to how this can be done? tutorials and samples also appreciated. Thanks :)
The easiest way to play files from the internet is to use -[AVAudioPlayer initWithContentsOfURL:error:]. If you want to make sure that the whole file is downloaded, I think your best bet would be to download the file using NSURLConnection (see the URL Loading Guide) and then using -[AVAudioPlayer initWithData:error:].
Look into ASIHTTPRequest, you will find it much easier to fetch large chunks of binary over the web asynchronously than if you try to code everything yourself.

I'm implement http live streaming video from my webserver to iPhone. Will I get rejected for bandwidth?

Apache webserver setup
added:
AddType application/x-mpegURL .m3u8
AddType video/MP2T .ts
to "httpd.conf" file.
Movie file preparation
I have 3 movie files (9mb - 25mb each).
Used QuickTime to convert movies into iPhone format.
Used mediafilesegmenter to convert .m4v into 10-second segments of .ts files, with an accompanying .m3u8 file.
Placed these in a folder on webserver.
iPhone App implementation
Created UIWebView whose URL points to http://71.190.235.29/~yujean/stream.html
Simulator accesses the site and streams the movie-files just fine.
Question
Will I still get rejected by apple for bandwidth issues over the 3G and/or Edge network?
Do I need to somehow check which network the end-user is on first? And then provide a different movie accordingly? If so, how do I do that ...?
Thank you in advance,
Eugene
We were rejected when we first submitted our mp3 streamer to the app store for excessive bandwidth use. Then we hobbled the app to limit its downloads to 4.5 meg in 5 min, which was accepted by Apple.
You can review that thread for more info on the issue.
To answer your second bullet-point first, the SDK does that all for you. Determining what quality to stream is not the concern of the developer.
To answer your first bullet-point, I haven't submitted my Live Streaming app so I don't know for sure, but I believe you will be rejected if you don't have a 64k stream. To be sure, check out Requirements for Apps, which is as definitive a list of requirements that you could probably get.

Not getting full download with NSURLConnection GET in iPhone app

Situation
I'm using NSURLConnection to download an mp3 file to the documents directory on my app. On the simulator I get the full mp3 file downloaded with no probs. On the device, however, I can only seem to get 1 second of audio for each mp3. I am connecting to a free WiFi point when performing this download from the device, in contrast with my T1 land-line connection that is used by the simulator.
Problem
Users of my app may encounter only partial downloads of mp3 files.
Question
Does this sound like a problem with the free WiFi hotspot rather than the actual app or NSURLConnection class? How should I go about troubleshooting this?
P.S. - I used to use [NSData dataWithContentsOfURL:URL] to download the mp3 file. It was very slow but at least I always got the ENTIRE mp3 file.
Thanks
Are you handling multiple callbacks of -connection: didReceiveData:? That will get called multiple times, and you should concatenate each data chunk into one giant NSMutableData.