iOS视频无法播放(播放按钮划掉)

时间:2017-12-06 22:06:06

标签: ios swift

我正在尝试播放来自网址的视频,但是当我运行代码时,我只能看到播放按钮被划掉。

这是代码:

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

知道出了什么问题吗?

1 个答案:

答案 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>