【问题标题】:AVPlayer not loading video from url of subdomainsAVPlayer 没有从子域的 url 加载视频
【发布时间】:2018-10-09 11:24:07
【问题描述】:

我正在使用 AVPlayer 从服务器加载视频网址。它适用于根中的视频,但不适用于子域中的视频。

我的 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 端。因为这个 URL 也没有在 safari 网络浏览器上加载。

任何帮助将不胜感激。

谢谢, 法会

【问题讨论】:

  • 您使用的是 http URL,是否为您的应用启用了任意加载?

标签: ios swift avplayer avplayerviewcontroller


【解决方案1】:

我认为您的服务器上的第二个 URL 存在问题。我浏览了Safari's web content documentation 并按照您的两个网址的步骤进行操作。

第一个按预期工作(下载了 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 的原因。希望这会有所帮助。

【讨论】:

    【解决方案2】:

    对我来说,您的代码似乎按预期工作。

    在项目was to Allow Arbitrary Loads中我唯一需要改变的地方

    当我检查日志并收到一条错误消息表明这一点。

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 2020-05-19
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 2018-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多