xcode 使用未解析的标识符“AVPlayer”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36190067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use of unresolved identifier 'AVPlayer'
提问by Yokhen
I found the following code on the internet and copy and pasted it to test it, however it doesn't seem to be working.
我在互联网上找到了以下代码并复制并粘贴它以进行测试,但是它似乎不起作用。
import Foundation
import UIKit
import AVKit
class Video1: UIViewController {
var playerViewController = AVPlayerViewController()
var playView = AVPlayer() //Unresolved identifier 'AVPlayer'
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func viewDidAppear(animated: Bool) {
var fileURL = NSURL(fileURLWithPath: "/Users/User/Desktop/video.mp4")
playerView = AVPlayer(URL: fileURL) //Unresolved identifier 'playerView'
//Unresolved identifier 'AVPlayer'
playerViewController.player = playerView //Unresolved identifier 'playerView'
self.presentViewController(playerViewController, animated: true){
self.playerViewController.player?.play()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I've imported the respective frameworks as shown, so it should work, but as seen, it fails.
我已经导入了如图所示的相应框架,所以它应该可以工作,但正如所见,它失败了。
Having little experience programming at iOS, I find myself at a loss. I would appreciate it if someone gave me a solution to this or at least point me in the right direction.
在 iOS 上几乎没有编程经验,我发现自己不知所措。如果有人给我一个解决方案或至少指出我正确的方向,我将不胜感激。
I will be happy to provide additional information if requested.
如果需要,我很乐意提供更多信息。
回答by Chance Hudson
You need to import AVFoundation to access AVPlayer. AVKit is (mostly) used for Mac development.
您需要导入 AVFoundation 才能访问 AVPlayer。AVKit(主要)用于 Mac 开发。
import AVFoundation