iphone播放视频时遇到的一个错误解决办法 An AVPlayerItem can occupy only one position in a player’...

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.

#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”.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值