2016-06-29 41 views
0

我的代碼通知:

NSURL *videoURL = [NSURL URLWithString:strVideo]; 

    playerController = [[AVPlayerViewController alloc]init]; 

    playerController.player = [AVPlayer playerWithURL:videoURL]; 


    playerController.view.frame = self.view.frame; 

    playerController.player.currentItem.forwardPlaybackEndTime = CMTimeMake(timeDuration, 1); 

    [playerController.player play]; 


    playerController.player.actionAtItemEnd = AVPlayerActionAtItemEndNone; 


    [self presentViewController:playerController animated:YES completion:nil]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playerItemDidReachEnd:) 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:[playerController.player currentItem]]; 


- (void)playerItemDidReachEnd:(NSNotification *)notification 
{ 

    [playerController dismissViewControllerAnimated:YES completion:nil]; 


    NSLog(@"IT REACHED THE END"); 

    } 

這裏playerItemDidReachEnd的調用,但avplayercontroller不能排除。AVPlayerViewController不會解僱時調用

+0

謝謝jigar的編輯..... – ragu

回答

0

我認爲你必須刪除下面的代碼行,

playerController.player.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

它可能不會打電話給你的通知方法。只需刪除代碼並嘗試一下。

+0

不能解僱praveen .... – ragu

+0

請問,在這行後面添加'AVPlayerItemDidPlayToEndTimeNotification'通知觀察者:'playerController = [[AVPlayerViewController alloc] init];'試試它? – Praveenkumar

+0

不工作Praveen。請爲此提供另一個解決方案 – ragu