【问题标题】:AVPlayerViewController will not dismiss when Notification called调用 Notification 时 AVPlayerViewController 不会关闭
【发布时间】:2016-06-29 12:49:34
【问题描述】:

我的代码:

    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 未被关闭。

【问题讨论】:

  • 感谢 jigar 编辑.....

标签: ios iphone avplayerviewcontroller avplayeritem


【解决方案1】:

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

playerController.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;

它可能不会调用你的 Notification 方法。只需删除代码并尝试一下。

【讨论】:

  • 能否请在此行之后添加AVPlayerItemDidPlayToEndTimeNotification 通知观察者:playerController = [[AVPlayerViewController alloc]init]; 并尝试一下?
  • 不工作普拉文。请为此提供另一种解决方案
  • 最后一试,把AVPlayerActionAtItemEndNone改成AVPlayerActionAtItemEndAdvance我还没用过这个控制器。
  • 应用程序因错误而崩溃,原因:'AVPlayerActionAtItemEndAdvance 不允许用于 AVPlayer 类的播放器'。
  • 请给出另一种解决方案或给出avplayerviewcontroller praveen的一些示例代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-01
  • 2011-03-18
  • 1970-01-01
  • 2013-10-27
  • 1970-01-01
相关资源
最近更新 更多