我已经构建了一个演示,其中我只是从实时网址播放视频,如果网址无法正常工作,那么MPMoviePlayerController会使用 MPMoviePlayerPlaybackDidFinishReasonUserInfoKey 激活通知 MPMoviePlayerPlaybackDidFinishNotification 。这件事情完美无缺在ios7和更高版本中但是当我在ios6中使用相同的东西时,它无法正常工作。 我的代码snipet正在关注
NSLog(@"URL::%@",url.absoluteString);
UIInterfaceOrientation interface = [UIApplication sharedApplication].statusBarOrientation;
videoPlayer = [[MPMoviePlayerController alloc] init];
[videoPlayer setContentURL:url];
[videoPlayer setMovieSourceType:MPMovieSourceTypeStreaming];
[videoPlayer setControlStyle:MPMovieControlStyleNone];
[videoPlayer setScalingMode:MPMovieScalingModeNone];
[videoPlayer.view setFrame:CGRectMake(0.0, viewTopbar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - (viewTopbar.frame.size.height+[self getBannerHeight:interface]))];
[self.view addSubview:self.videoPlayer.view];
[self.videoPlayer play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:videoPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinishWithReson:)
name:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey
object:videoPlayer];
#pragma mark
#pragma mark - movie player delegate methods
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackError) {
//error
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:localize(@"strTitle") message:localize(@"strMsg") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
-(void) moviePlayBackDidFinishWithReson:(NSNotification *)notification
{
int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue];
if (reason == MPMovieFinishReasonPlaybackError) {
//error
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:localize(@"strTitle") message:localize(@"strMsg") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}
答案 0 :(得分:0)
在R& D之后很多事情我找不到委托方法的任何解决方案所以对于这个问题我实现了一件事我开始一个计时器并检查当前的电影播放器的头部,如果它是更重要的那么0.它意味着视频正在加载并成功播放。
我的代码段正在关注。
在初始化MPMoviePlayerController
时编写此代码if (iOS6 && APPDELEGATE.isNetAvailable)
{
[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(checkVideo) userInfo:nil repeats:NO];
}
并在视图控制器中编写此方法
-(void)checkVideo
{
NSLog(@"%f",videoPlayer.currentPlaybackTime);
if (videoPlayer.currentPlaybackTime == 0.0)
{
//error
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:localize(@"strTitle") message:localize(@"strMsg") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[videoPlayer stop];
}
}
请仅将此解决方案用于ios6。