[英]AvPlayer not playing video in Xcode 7
I've been trying to get this to work but can't seem to find the solution. 我一直在尝试使其工作,但似乎找不到解决方案。 I want a video to start playing on viewDidLoad.
我希望视频开始在viewDidLoad上播放。 I can get the AVPlayerViewController to show up but no video plays.
我可以显示AVPlayerViewController,但是没有视频播放。 Any suggestions would be greatly appreciated.
任何建议将不胜感激。
import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
var videoPlayer = AVPlayerViewController()
let videoPath = NSURL(string: "https://youtu.be/dWYNNQdD6rY")
override func viewDidLoad() {
super.viewDidLoad()
let player = AVPlayer(URL: videoPath!)
let playerController = AVPlayerViewController()
playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I believe you need to feed the AVPlayer a URL to either an m3u8 file or directly to a movie. 我相信您需要向AVPlayer提供URL到m3u8文件或直接到电影。 Some example m3u8 files can be found on Stack Overflow and other websites.
一些示例m3u8文件可以在Stack Overflow和其他网站上找到。 Change your video path to be something like this:
将您的视频路径更改为以下形式:
let videoPath = NSURL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.