简体   繁体   English

iOS AVPlayer无法播放所有远程文件

[英]iOS AVPlayer not playing all remote files

I'm using SwiftyDropbox 's getTemporaryLink() to play a video in an AVPlayer . 我正在使用SwiftyDropboxgetTemporaryLink()AVPlayer播放视频。 I have six test files, and they all work as expected, except 1. 我有六个测试文件,它们全部按预期工作,除了1。

The one that doesn't work is 41 MB in size (which I would not consider a large video file), the rest are < 22 MB. 一个不起作用的文件大小为41 MB(我不会考虑较大的视频文件),其余文件大小小于22 MB。

I've read the AVFoundation and SwiftDropbox documentation many times and haven't been able to find anything on a maximum file size, though I wouldn't expect a maximum file size for streaming content. 我已经阅读了很多次AVFoundationSwiftDropbox文档,但找不到最大文件大小的任何内容,尽管我不希望流内容的最大文件大小。 I would expect it to continuously play smaller chunks downloaded to memory. 我希望它能够持续播放下载到内存中的较小块。

My questions are: 我的问题是:

  1. Is there a file size limit on playing a remote URL in an AVPlayer ? AVPlayer播放远程URL是否有文件大小限制?
  2. If not, is there a certain way I need to use AVPlayer in order to stream these larger files? 如果不是,是否有某种方法需要使用AVPlayer来流传输这些较大的文件?

I'm using the following code to start the AVPlayer : 我正在使用以下代码来启动AVPlayer

self.previewPlayer.replaceCurrentItem(with: AVPlayerItem(url: URL(fileURLWithPath: url)))
self.previewPlayer.play()

Thank-you! 谢谢!

You should observe the value of status property to know why the playerItem might have failed to play. 您应该观察status属性的值,以了解为什么playerItem可能无法播放。 Here's a small code snippet to start with: 这是一个小代码段开头:

  1. Add observer 添加观察者

     let url = URL.init(string: "your url string") let item = AVPlayerItem.init(url: url!) item.addObserver(self, forKeyPath: "status", options: .new, context: nil) 
  2. Check for the the error 检查错误

     override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if let item = object as? AVPlayerItem, keyPath == "status" { if item.status == .failed { print(item.error?.localizedDescription ?? "Unknown error") } } } 

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

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