While playing a video using MPMoviePlayerViewController or MPMoviePlayerController, iOS SDK 5.2 generates an error as follows.
An AVPlayerItem can occupy only one position in a player’s queue at a time.
The exact error is as follows.
*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘An AVPlayerItem can occupy only one position in a player’s queue at a time.’
Please have a look into following code - WHICH GENERATES ERROR.
An AVPlayerItem can occupy only one position in a player’s queue at a time.
The exact error is as follows.
*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘An AVPlayerItem can occupy only one position in a player’s queue at a time.’
Please have a look into following code - WHICH GENERATES ERROR.
#pragma mark - Media player
-(void)initAndPlayMovie:(NSURL *)movieURL andViewController:(UIViewController*)vCtr {
self.mPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL]; // set source type streaming
[self.mPlayer.moviePlayer setMovieSourceType:MPMovieSourceTypeStreaming]; [self.mPlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
// fit to screen mode
[self.mPlayer.moviePlayer setScalingMode:MPMovieScalingModeAspectFit];
// full screen mode
[self.mPlayer.moviePlayer setFullscreen:YES animated:YES];
[vCtr presentMoviePlayerViewControllerAnimated:self.mPlayer];
}
Now, have a look into following code WHICH WILL WORK FINE
#pragma mark - Media player
-(void)initAndPlayMovie:(NSURL *)movieURL andViewController:(UIViewController*)vCtr {
self.mPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
// set source type streaming
[self.mPlayer.moviePlayer setMovieSourceType:MPMovieSourceTypeUnknown]; [self.mPlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
// fit to screen mode
[self.mPlayer.moviePlayer setScalingMode:MPMovieScalingModeAspectFit];
// full screen mode [self.mPlayer.moviePlayer setFullscreen:YES animated:YES];
[vCtr presentMoviePlayerViewControllerAnimated:self.mPlayer];
}
The main difference in both code is as follows.
MovieSourceType is modified to “MPMovieSourceTypeUnknown” instead of “MPMovieSourceTypeStreaming”.
If you have a streaming URL, It is recommended to use “MPMovieSourceTypeStreaming”.
While having a static movie URL, It is recommended to use “MPMovieSourceTypeUnknown”.
If you have a URL from file or video from application itself, It is recommended to use ”MPMovieSourceTypeFile”.