的MPMoviePlayerController通知在iOS6的
问题描述:
不工作我有一个建立在演示我只是从直播网址播放视频,如果网址不MPMoviePlayerPlaybackDidFinishReasonUserInfoKey。这件事的工作完全在ios7和更大的正常工作,然后火的MPMoviePlayerController通知MPMoviePlayerPlaybackDidFinishNotification但是当我在ios6中使用相同的东西时,它不起作用。 我的一小段代码片段是继的MPMoviePlayerController通知在iOS6的
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];
}
}
答
对很多事情 - [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的。