I try to stream mp4-files from a http server to my iPhone with this code:
- (IBAction)streamMovie:(id)sender
{
NSURL *url = [NSURL URLWithString:trailerPath];
if ([self.movieController respondsToSelector:@selector(setAllowsAirPlay:)])
[self.movieController.moviePlayer setAllowsAirPlay:YES];
[self.movieController.moviePlayer setContentURL:url];
[self presentMoviePlayerViewControllerAnimated:self.movieController];
[self.movieController.moviePlayer play];
}
This works fine on the simulator, but it doesn’t work at all on my iPhone device (3GS with iOS 5.1). The movie player only pops up and then disappears immediately. If I try again this log entry appears:
An instance 0x1c5a20 of class AVPlayerItem was deallocated while key value observers
were still registered with it. Observation info was leaked, and may even become
mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to
stop here in the debugger. Here's the current observation info:
What am I doing wrong and why does this work on the simulator?
I finally found out that there was no problem with the device, but with the http server. It sent the wrong MIME type (text/html instead of video/mp4) and so the device could not interprete it correctly. So I just had to add the MIME type to the server and now it works like a charm