AVPlayerViewController Video在iOS 11、12上运行,但在iOS 13和iPhone 11上不运行

汽车人的B-Tron

我收到一个奇怪的错误,我的背景视频可以在iOS 13 iPhone 8iPhone 8 +iPhone 11模拟器(和设备)上正常播放,但不能在iOS 13 iPhone 11 ProiPhone 11 Pro Max模拟器上播放

VideoSplashViewController在单独的着陆页视图控制器中引用了以下内容。

VideoSplashViewController

import UIKit
import MediaPlayer
import AVKit

public enum ScalingMode {
  case resize
  case resizeAspect
  case resizeAspectFill
}

open class VideoSplashViewController: UIViewController {

  fileprivate let moviePlayer = AVPlayerViewController()
  fileprivate var moviePlayerSoundLevel: Float = 1.0
  open var contentURL: URL? {
    didSet {
      setMoviePlayer(contentURL!)
    }
  }

  open var videoFrame: CGRect = CGRect()
  open var startTime: CGFloat = 0.0
  open var duration: CGFloat = 0.0
  open var backgroundColor: UIColor = UIColor.white {
    didSet {
      view.backgroundColor = backgroundColor
    }
  }
  open var sound: Bool = true {
    didSet {
      if sound {
        moviePlayerSoundLevel = 1.0
      }else{
        moviePlayerSoundLevel = 0.0
      }
    }
  }
  open var alpha: CGFloat = CGFloat() {
    didSet {
      moviePlayer.view.alpha = alpha
    }
  }
  open var alwaysRepeat: Bool = true {
    didSet {
      if alwaysRepeat {
        NotificationCenter.default.addObserver(self,
          selector: #selector(VideoSplashViewController.playerItemDidReachEnd),
          name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
          object: moviePlayer.player?.currentItem)
      }
    }
  }
  open var fillMode: ScalingMode = .resizeAspectFill {
    didSet {
      switch fillMode {
      case .resize:
        moviePlayer.videoGravity = AVLayerVideoGravity(rawValue: AVLayerVideoGravity.resize.rawValue)
      case .resizeAspect:
        moviePlayer.videoGravity = AVLayerVideoGravity(rawValue: AVLayerVideoGravity.resizeAspect.rawValue)
      case .resizeAspectFill:
        moviePlayer.videoGravity = AVLayerVideoGravity(rawValue: AVLayerVideoGravity.resizeAspectFill.rawValue)
      }
    }
  }

  override open func viewDidAppear(_ animated: Bool) {

  }

    var coverView = UIView()

    override open func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)


        view.backgroundColor = UIColor.white

        moviePlayer.view.frame = videoFrame
        moviePlayer.view.backgroundColor = UIColor.white

        moviePlayer.showsPlaybackControls = false
        view.addSubview(moviePlayer.view)
        view.sendSubviewToBack(moviePlayer.view)

        coverView.frame = CGRect.init(x: 0, y: 0, width: 500, height: 500)
        coverView.backgroundColor = UIColor.white
        coverView.layer.zPosition = 11;
        coverView.isUserInteractionEnabled = false
        moviePlayer.view.addSubview(coverView)

        UIView.animate(withDuration: 2) {
            self.coverView.backgroundColor = UIColor(hue: 0.5194, saturation: 0.4, brightness: 0.94, alpha: 0.1)
            }

        _ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default, options: .mixWithOthers)

    }

  override open func viewWillDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    NotificationCenter.default.removeObserver(self)
    moviePlayer.view.backgroundColor = UIColor.white
  }

  fileprivate func setMoviePlayer(_ url: URL){
    let videoCutter = VideoCutter()
    videoCutter.cropVideoWithUrl(videoUrl: url, startTime: startTime, duration: duration) { (videoPath, error) -> Void in
      if let path = videoPath as URL? {
        DispatchQueue.global().async {
          DispatchQueue.main.async {
            self.moviePlayer.player = AVPlayer(url: path)
            self.moviePlayer.player?.play()
            self.moviePlayer.player?.volume = self.moviePlayerSoundLevel
            //added to mute
            self.moviePlayer.player?.isMuted = true
          }
        }
      }
    }
  }

  override open func viewDidLoad() {
    super.viewDidLoad()
    moviePlayer.view.backgroundColor = UIColor.white
  }

  override open func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }

  @objc func playerItemDidReachEnd() {
    moviePlayer.player?.seek(to: CMTime.zero)
    moviePlayer.player?.play()
  }
}

这是在我的主要目标网页视图上调用的代码。

在单独的VideoSplashViewController中调用的代码继承了VC

    func setupVideoBackground() {
        let url = URL(fileURLWithPath: Bundle.main.path(forResource: "timelapse_clouds_compress", ofType: "mp4")!)

        // setup layout
        videoFrame = self.view.frame
        fillMode = .resizeAspectFill
        alwaysRepeat = true
        sound = true
        startTime = 2.0
        alpha = 0.8

        contentURL = url
        view.isUserInteractionEnabled = true
    }

我的一部分人怀疑这是模拟器问题,因为我看不到XCode中的任何警报或错误,并且该视频在真实的iPhone 8+ iOS 13上可以正常工作。将尝试尽快在真实的iPhone 11 Pro Max上进行测试,但会有所帮助!

汽车人的B-Tron

该视频在实际的iPhone 11 Pro和iPhone 11 Pro Max设备上运行良好。这是一个模拟器错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

iOS:iPhone 11 Pro上的火炬级别

Fairplay停止在iOS 12.4和13上运行

在面向iOS 11的Xcode 9上构建应用程序,但在iPhone X上具有兼容模式

更新到IOS 11后在IOS模拟器上运行错误-Ionic 3

在iOS 11上滑动时AVPlayerViewController黑屏

UINavigationBar后退按钮未在iPhone X iOS 11上显示

如何在iPhone上使用iOS 11拖放功能

背景音无法在模拟器上的iOS10,iOS11中运行

SecPKCS12Import在iOS 11和iOS 10上返回的结果不同

AVPlayerViewController UITapGestureRecognizer在iOS 11中不起作用

Alamofire上传完成区块在iOS 9和IOS 11上正常运行,但在iOS 10上错误

Xcode 10.3无法在iOS 13 iPhone X上运行-此iPhone X运行的是iOS 13.0(17A577),此版本的Xcode可能不支持

隐藏iOS移动Safari 13(iPhone X和11)中全屏Web应用程序的状态/位置栏

ML.Net在Xamarin.Android上运行,但在Xamarin.iOS上不运行:System.Reflection.Emit

为什么在使用UWP时,TapGesture Grid识别器响应速度较慢,但在Android和iOS上运行良好?

该应用程序在iOS 13+ iPhone的屏幕底部显示空白,但在iOS 12 iPhone上很好

在iOS 13设备上运行应用程序时,Xcode 11.3引发异常,但在模拟器上不运行

IOS App在iTunes版本上崩溃,但在本地模拟器和真实设备测试中运行良好

iOS Swift在iPad和iPhone上运行时,相同的代码会导致不同的日期格式

为什么UIWebView的AVPlayerViewController不在主线程上运行?

iOS - 在 AVPlayerViewController 之上添加控件

我的 iOS 应用程序仅在 iPhone 上崩溃,但在 iPad 上运行

Ionic 无法使用 ServiceStack 客户端在 Safari 和 iOS 11 上运行

Xcode 10.3 无法在 iOS 13 iPhone 6s 上运行 - 此 iPhone 6s 运行的是 iOS 13.1,此版本的 Xcode 10.3 可能不支持

在 xcode 11 上运行应用程序后,iPhone 10 和 11 没有足够的高度

如何在 iOS AVPlayerViewController 上禁用搜索?

什么可能导致 epub、mobi 和 zip 文件无法在运行 ios 13 的 iPhone 上下载?

创建可在桌面和 Android 上运行的 React 应用程序,但在 IOS 上为空白

SwiftUI:TabView 和 NavigationView 在 iPhone 上运行良好,但在 iPad 上不运行?