- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 Swift 3 开发一个 iOS 应用程序,我在后台播放视频。我的代码工作完全正常,直到随机出现错误消息:
Type
AVLayerVideoGravity
aka (NSString
) has no memberresizeAspectFill
出现。我完全不明白为什么 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 版本。要查看更改,请在右上角启用显示 API 更改)。
The video gravity determines how the video content is scaled or stretched within the player layer’s bounds. The player layer supports the following video gravity values:
AVLayerVideoGravityResizeAspect
AVLayerVideoGravityResizeAspectFill
AVLayerVideoGravityResize
The default value is
AVLayerVideoGravityResizeAspect
.
您所指的枚举案例属于 Swift 4
关于ios - swift 3 错误 : Type 'AVLayerVideoGravity' has no member 'resizeAspectFill' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44620366/
我正在使用 Swift 3 开发一个 iOS 应用程序,我在后台播放视频。我的代码工作完全正常,直到随机出现错误消息: Type AVLayerVideoGravity aka (NSString)
我是一名优秀的程序员,十分优秀!