ZFPlayer iOS16 系统横屏全屏问题处理

Posted 追夢秋陽

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZFPlayer iOS16 系统横屏全屏问题处理相关的知识,希望对你有一定的参考价值。

ios16 以后 通过原始横屏的方法已经不好使了,需要在此基础上添加 setNeedsUpdateOfSupportedInterfaceOrientations 发的调用,具体API 描述如下:

回到主题,在使用ZFPlayer 视频库全屏播放是iOS16系统下的处理参考如下:

//进入全屏播放事件
self.player.orientationWillChange = [weak self] (player,isFullScreen) in
            guard let self = self else  return 
            
            if isFullScreen 
                var _title = self.model?.title ?? ""
                if self.model?.authorize == 0 
                    _title += "(试看\\(Int(Setting.shareInstance.K_APP_TRY_WATCH_INTERVAL/60))分钟)".replacingOccurrences(of: "\\r", with: "")
                
                
                if self.isVertical 
                    self.controlView.portraitControlView.showTitle(_title, fullScreenMode: .portrait)
                
                else
                    self.isAutorotate = true
                    self.faceOrientation = .landscapeRight
                   
                    if #available(iOS 16.0, *) 
                        //横屏
                        self.setNeedsUpdateOfSupportedInterfaceOrientations()

                        self.player.addPlayerView(toContainerView: UIApplication.shared.windows.first!)
                        
                     else 
                        // Fallback on earlier versions
                        self.player.containerView = UIApplication.shared.windows.first!
                    
                    self.controlView.landScapeControlView.showTitle(_title, fullScreenMode: .landscape)
                
            



//MARK: - 设备方向处理
extension StudyCourseDetailsViewController 
    
    override var shouldAutorotate: Bool 
        get 
            return self.isAutorotate
        
    
    
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask 
        get 
            return self.faceOrientation
        
    
    

退出全屏的方法,无需调整,具体参考如下:

//退出全屏被点击(全屏返回按钮被点击)
self.playerControlView.backBtnClickCallback = [weak self] in
            guard let self = self else  return 
            
            if self.isVertical == false 
                self.isAutorotate = false
                self.faceOrientation = .portrait
                
                self.player.rotate(to: .portrait, animated: true) 
                    print("已返回小屏")
                
                
                self.player.containerView = self.videoPlayerView
            
            
      self.player.enterFullScreen(false, animated: true)

更多关于iOS16 兼容性处理,参考:XCode14 & iOS16 适配问题汇总 

以上是关于ZFPlayer iOS16 系统横屏全屏问题处理的主要内容,如果未能解决你的问题,请参考以下文章

h5 video切换到横屏全屏

手机看视频不是全部能全屏,怎么处理?

iOS - 视频播放处理全屏/横屏时候遇见的坑

vue全屏插件screenfull的使用

手机app的视频都不能全屏播放了,怎么解决?

跳出小程序 video组件 卡顿黑屏全屏等坑