简体   繁体   English

xcode 8 || AVPlayer正在显示视频,但未播放

[英]xcode 8 || AVPlayer is showing video however it's not playing

I have this simple code to play an online video. 我有这个简单的代码可以播放在线视频。 After doing the HTTP permission option, it did start to show the video and I can scroll through it, however, it doesn't play at any point. 在执行HTTP权限选项后,它确实开始显示视频,并且我可以滚动浏览它,但是它在任何时候都无法播放。 Here is the code. 这是代码。 I would appreciate if someone could help me with this. 如果有人可以帮助我,我将不胜感激。

regards, A Beginner Coder 问候,初学者编码器

import UIKit
import AVKit
import AVFoundation

class ViewController: UIViewController {

var playerViewController = AVPlayerViewController()
var playerView = AVPlayer()



override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.


}
override func viewDidAppear(_ animated: Bool) {
    let movieUrl: NSURL? = NSURL(string: "http://clips.vorwaerts-gmbh.de/VfE_html5.mp4")
    playerView = AVPlayer(url: movieUrl as! URL)
    playerViewController.player = playerView

    self.present(playerViewController, animated: true){
        self.playerViewController.player?.play()
    }

}

}

When I ran your code in a sample project the debugger prints: 当我在示例项目中运行代码时,调试器将打印:

"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." “由于不安全,应用程序传输安全性阻止了明文HTTP(http://)资源加载。可以通过应用程序的Info.plist文件配置临时异常。”

The two options I found were: 我发现的两个选项是:

1) Change the scheme to https:// in your URL 1)在您的网址中将方案更改为https://

or 要么

2) Adjust the App Transport Security settings in your Info.plist 2)在您的Info.plist中调整App Transport Security设置

I successfully played the video using both options with your code. 我在您的代码中同时使用了这两个选项,成功播放了视频。

It turns out that the only thing i had done was, the last line had 原来,我唯一要做的是,最后一行

"self.playerViewController.player?.play()" ----->>> "?" “ self.playerViewController.player?.play()” ----- >>>“?” and when i changed it to --------->>> "!" 当我将其更改为--------- >>>“!”

IT MAGICALLY STARTED WORKING.... 神奇地开始工作...

i have seen the meme on the internet where they talk about coders not knowing why the code works and why it doesn't... same happpened to me i guess. 我在互联网上见过模因,他们在谈论编码员,但不知道编码为什么起作用,为什么不起作用……我想同样也是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM