我正在尝试播放来自网址的视频,但是当我运行代码时,我只能看到播放按钮被划掉。
这是代码:
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
@IBAction func playVideo(_ sender: Any) {
let videoURL = URL(string: "http://techslides.com/demos/sample-videos/small.mp4")
let player = AVPlayer(url: videoURL!)
let playerControler = AVPlayerViewController()
playerControler.player = player
present(playerControler, animated: true) {
player.play()
}
}
Xcode 9.1 斯威夫特4
知道出了什么问题吗?
答案 0 :(得分:0)
您需要修改.plist
文件,才能按给定的http
网址
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
将此代码添加到.plist
xml
,或者只是尝试加载https:
视频:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>example.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>