0

I'm using SwiftyDropbox's getTemporaryLink() to play a video in an AVPlayer. I have six test files, and they all work as expected, except 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.

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. 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?
  2. If not, is there a certain way I need to use AVPlayer in order to stream these larger files?

I'm using the following code to start the AVPlayer:

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

Thank-you!

cohenadair
  • 2,072
  • 1
  • 22
  • 38
  • Have you tried a different url? – Adeel Miraj Aug 03 '18 at 03:29
  • Yes. Local files worked, and `http://clips.vorwaerts-gmbh.de/VfE_html5.mp4` remote video worked. – cohenadair Aug 03 '18 at 12:52
  • Use `let url = URL.init(string: urlStr)` instead of `URL(fileURLWithPath: url)` for remote content. – Adeel Miraj Aug 03 '18 at 12:56
  • Thanks, @Adeel. Doing some reading, it appears that `URL(fileURLWithPath:)` is meant for use with the file system; however, it does work with remote paths as well. Whether this is intended, I do not know. I have also found that every other video file in the same Dropbox folder works as expected. The one that doesn't work is larger (41 MB). I'm now wondering if `AVPlayer` has a file size limit. – cohenadair Aug 03 '18 at 13:12
  • In light of that new discovery, I have rewritten the question. – cohenadair Aug 03 '18 at 13:25
  • 1
    There's no limitation on file size I'm sure. One of my applications streams movie files whose sizes are in excess of 1GB. To know what's exactly happening, you should do key value observation on `AVPlayerItem`. Specifically observe the value of `status` property. – Adeel Miraj Aug 03 '18 at 13:31
  • Observing the status says it's "Ready to play", but is never actually played in the player. – cohenadair Aug 03 '18 at 14:40
  • can you share the entire code? – Adeel Miraj Aug 03 '18 at 14:42
  • [Cross-linking for reference: https://www.dropboxforum.com/t5/API-Support-Feedback/iOS-getTemporaryLink-cannot-be-used-for-streaming/m-p/288674#M17675 ] – Greg Aug 03 '18 at 15:21

1 Answers1

0

You should observe the value of status property to know why the playerItem might have failed to play. 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")
            }
        }
    }
    
Adeel Miraj
  • 2,472
  • 3
  • 22
  • 32
  • It doesn't fail. The status becomes `.readyToPlay`, but it doesn't actually start playing. Again, this only happens for one of my test videos. – cohenadair Aug 03 '18 at 14:42
  • The test videos are `.mp4` and `.mov` files. The one that's not working is `.mov`, but another `.mov` is working. – cohenadair Aug 03 '18 at 15:05
  • Try one thing, download that file and play it from the application bundle. – Adeel Miraj Aug 03 '18 at 15:07
  • Then the issue is with this file probably. Does it play in any other player? – Adeel Miraj Aug 03 '18 at 15:16
  • Yeah, it plays in the browser and QuickTime no problem. It actually has an "MSG" watermark on it. I'm wondering if it has a copyright on it that prevents AVPlayer from playing it? – cohenadair Aug 03 '18 at 15:35