我正在使用AVPlayer从服务器加载视频URL。它适用于根目录而非子域中的视频。
我的AVPlayer代码如下: 播放器使用以下URL:
@IBAction func btnPlayClicked(_ sender: Any) {
//let videoURL = URL.init(string: "http://musically.virgoexchange.com/storage/upload/videos/2018/10/1538719219video.mp4")
let videoURL = URL(string: "http://somo.virgoexchange.com/demo.mp4")
self.playVideo(videoURL: videoURL!)
}
播放器无法使用以下网址:
@IBAction func btnPlayFinalClicked(_ sender: Any) {
let videoURL = URL(string: "http://somo.virgoexchange.com/user/gallery/video/1535522305_img_0006.mp4")
self.playVideo(videoURL: videoURL!)
}
func playVideo(videoURL:URL) {
let player = AVPlayer(url: videoURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
我无法确定此问题是来自服务器端还是iOS端。由于该网址也不会在safari网络浏览器中加载。
任何帮助将不胜感激。
谢谢, Puja Rathod
答案 0 :(得分:0)
我认为您的服务器上的第二个URL有问题。我经历了Safari's web content documentation,并遵循了两个URL的步骤。
第一个按预期方式工作(下载了100KB)
curl --range 0-99 http://somo.virgoexchange.com/demo.mp4 -o /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 100 100 100 0 0 8 0 0:00:12 0:00:11 0:00:01 23
第二个无效:
curl --range 0-99 http://somo.virgoexchange.com/user/gallery/video/1535522305_img_0006.mp4 -o /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 778k 0 100 0 0 198 0 1:07:06 --:--:-- 1:07:06 198
curl: (18) transfer closed with 797201 bytes remaining to read
希望这就是Safari无法加载第二个URL的原因,而AVPlayer也是如此。希望这会有所帮助。
答案 1 :(得分:0)