I have a simple HTTP server running that pretty much just serves an MP3 file in chunks of equal size. I’m writing an iOS app (for testing purposes), that basically takes a URL and streams the file through MPMovieController. Here’s my sample code:
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] init];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
mp.contentURL = [NSURL URLWithString:@"http://127.0.0.1:8080"];
[mp play];
It works. BUT: on my http server I see multiple connections (first one breaks right away, second one streams to the end usually, although sometimes there is 3rd connection).
I know it’s not the server issue, since when I do this:
NSData *myData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://127.0.0.1:8080"]];
…then there’s only 1 connection that finishes reading and disconnects.
The question is: Why does MPMoviePlayerController need to establish and break those connections before finishing reading the file, why doesn’t it just keep waiting for more data to be written on the socket? I haven’t been able to find any relevant docs that would explain this 🙁
P.S. If you are curious why I need this, here’s a short explanation: I’m trying to emulate real life network scenarios where bytes are received by the MPMovieController in chunks with small delays of random length in between
You need to modify your server and add support for
HTTP 206 Partial Contentrequests/responses. iOS requests movie data over HTTP this way.