首页 文章

AVPlayerController - 按钮不能在全屏幕上工作

提问于
浏览
1

我试图了解AVPlayer和AVPlayerController的工作原理 . 我在播放器中嵌入了我的播放器,因此我的播放器有两种模式:小屏和全屏 . 当它很小时播放/播放按钮和全屏按钮工作得很好 . 但是一旦全屏显示,以下按钮无效:播放,暂停,完成,最小化 .

这是我的代码:

let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
    let avPlayer:AVPLayer = AVPlayer(url: videoURL! as URL)
    let playerController = AVPlayerViewController()
    playerController.player = avPlayer
    playerController.view.backgroundColor = UIColor.racingGreenColor();
    playerController.view.translatesAutoresizingMaskIntoConstraints = false;
    playerController.showsPlaybackControls = true;
    self.middleView.addSubview(playerController.view)
    //avPlayer.play()

    self.middleView.addConstraint(NSLayoutConstraint(item: playerController.view, attribute: .width, relatedBy: .equal, toItem: self.middleView, attribute: .width, multiplier: 1, constant: 0));
    self.middleView.addConstraint(NSLayoutConstraint(item: playerController.view, attribute: .height, relatedBy: .equal, toItem: self.middleView, attribute: .height, multiplier: 1, constant: 0));
    self.middleView.addConstraint(NSLayoutConstraint(item: playerController.view, attribute: .centerX, relatedBy: .equal, toItem: self.middleView, attribute: .centerX, multiplier: 1, constant: 0));
    self.middleView.addConstraint(NSLayoutConstraint(item: playerController.view, attribute: .centerY, relatedBy: .equal, toItem: self.middleView, attribute: .centerY, multiplier: 1, constant: 0));

有谁可以帮助我吗 ?是否有我感兴趣的4种方法的代表?

3 回答

  • 0
    self.addChildController(playerController);
    

    我已将它添加到您的主视图控制器上,它可以实现“完成”和“最小化” .

  • 0

    它适用于我作为self.present(playerController,animated:true,completion:nil)

    由于它是一个控制器,我们应该将它用作控制器而不是子视图 .

  • 1

    您可以将AVPlayer添加为图层,并添加自己的自定义按钮

    player = [[[AVPlayer alloc] init ...

    playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
    CGSize size = self.view.bounds.size;
    float x = size.width/2.0-187.0;
    float y = size.height/2.0 - 125.0;
    
    playerLayer.frame = CGRectMake(x, y, 474, 320);
    [playerLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [self.view.layer addSublayer:playerLayer];
    [player play];
    

相关问题