调用Notification时,AVPlayerViewController不会忽略

时间:2016-06-29 12:49:34

标签: ios iphone avplayerviewcontroller avplayeritem

我的代码:

    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");

  }

这里调用了playerItemDidReachEndavplayercontroller没有被解雇。

1 个答案:

答案 0 :(得分:0)

我认为你必须删除下面的代码行,

playerController.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;

它可能无法调用您的通知方法。只需删除代码并试一试。