简体   繁体   中英

AVPlayerViewController will not dismiss when Notification called

My Code:

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

  }

here the playerItemDidReachEnd is called but avplayercontroller not dismiss.

I think you have to remove below line of code,

playerController.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;

It may not call your Notification method. Just remove the code and give a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM