0

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.

Jigar Tarsariya
  • 3,189
  • 3
  • 14
  • 38
ragu
  • 133
  • 2
  • 10

1 Answers1

0

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.

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173