2015-03-13 36 views
1

不工作我有一個建立在演示我只是從直播網址播放視頻,如果網址不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]; 
    } 
} 

回答

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的。