AVPlayer播放音频但视频冻结

时间:2014-04-20 11:51:15

标签: ios objective-c video avplayer

我有两个UIViewControllers,每个都有一个AVPlayer,当它们被推入UINavigationController时,它们应该播放视频文件:

-(void)viewWillAppear:(BOOL)animated{

    videoView = [[UIView alloc]initWithFrame:self.view.frame];

    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mov"];
    NSURL *fileURL = [NSURL fileURLWithPath:filepath];
    self.avPlayer = [AVPlayer playerWithURL:fileURL];

    AVPlayerLayer *foregroundLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
    self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
    foregroundLayer.frame = self.view.frame;
    foregroundLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

    [videoView.layer addSublayer:foregroundLayer];

    [self.view addSubview:videoView];

    self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

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

-(void)viewDidAppear:(BOOL)animated{

    [self.avPlayer play];
}

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

    [self.navigationController popViewControllerAnimated:NO]
}

我第一次推送任何UIViewControllers播放效果都很好。但在那之后,如果我再推它们中的任何一个声音,但视频会冻结。

我尝试使用MPMoviePlayerViewController,但行为是一样的。有什么想法吗?

0 个答案:

没有答案