我正在使用Swift 3开发iOS应用程序,并在后台播放视频。我的代码工作正常,直到随机出现错误消息:



出现。我根本不明白为什么resizeAspectFill不再被认可。有什么我想念的吗?我已经尝试清理我的项目,但这并不能解决任何问题。任何帮助将不胜感激 :)
下面是代码:

import Foundation
import AVFoundation
import UIKit

class HomeViewController: UIViewController {
// MARK: Properties
var avPlayer: AVPlayer!
var avPlayerLayer: AVPlayerLayer!
var paused: Bool = false

var enterButton: UIButton! = UIButton()

override func viewDidLoad() {
    super.viewDidLoad()
    self.title = "Welcome"

    let theURL = Bundle.main.url(forResource:"hannah", withExtension: "mp4")

    avPlayer = AVPlayer(url: theURL!)
    avPlayerLayer = AVPlayerLayer(player: avPlayer)
    avPlayerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill

    avPlayer.volume = 0
    avPlayer.actionAtItemEnd = .none

    avPlayerLayer.frame = view.layer.bounds
    view.backgroundColor = .clear
    view.layer.insertSublayer(avPlayerLayer, at: 0)

    NotificationCenter.default.addObserver(self,
                                           selector: #selector(playerItemDidReachEnd(notification:)),
                                           name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
                                           object: avPlayer.currentItem)

最佳答案

documentation of AVPlayerLayer(不幸的是,该链接重定向到Swift 4版本。要查看更改,请启用右上角的Show API更改)。



您所引用的枚举类型属于Swift 4

关于ios - 迅速3错误: Type 'AVLayerVideoGravity' has no member 'resizeAspectFill' ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44620366/

10-10 21:05