I have an MPMoviePlayerController
in my iOS app that streams a video from Amazon S3. The video plays fine, but it seems that on a device (I tested with iOS 6, not sure about others), the audio doesn't play. The audio works fine on the emulator, just not on the device.
Anyone have any ideas what's wrong? Here's my code:
// Construct the video's URL
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://s3.amazonaws.com/<mybucket>/%d.m4v",videoFileNumber]];
vidPlayer = [[MPMoviePlayerController alloc] initWithContentURL: url];
// Set up the video player
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:vidPlayer];
vidPlayer.scalingMode = MPMovieScalingModeAspectFill;
vidPlayer.controlStyle = MPMovieControlStyleDefault;
vidPlayer.shouldAutoplay = YES;
[self.view addSubview:vidPlayer.view];
[vidPlayer setFullscreen:YES animated:YES];
Thank you!
You forgot to say prepareToPlay
. This call is absolutely essential. I'm not saying it will definitely solve the problem, but it very well might, and you absolutely must call it on modern iOS systems.
Also: to find out what's going wrong, exactly, you must register for notifications. MPMoviePlayerPlaybackDidFinishNotification
is good, but I would strongly urge you to regiter for at least MPMoviePlayerLoadStateDidChangeNotification
as well.
In addition, I would have to suggest that since the audio is not playing but the video is playing, you might want to concern yourself with the format of the audio contained within this movie. The device has some surprising hidden limitations on what audio formats it can play: overly compressed audio, for example, can give it trouble.