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!

9
  • Have you tried a different url? Commented Aug 3, 2018 at 3:29
  • Yes. Local files worked, and http://clips.vorwaerts-gmbh.de/VfE_html5.mp4 remote video worked.
    – cohenadair
    Commented Aug 3, 2018 at 12:52
  • Use let url = URL.init(string: urlStr) instead of URL(fileURLWithPath: url) for remote content. Commented Aug 3, 2018 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
    Commented Aug 3, 2018 at 13:12
  • 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. Commented Aug 3, 2018 at 13:31

1 Answer 1

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")
            }
        }
    }
    
5
  • 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
    Commented Aug 3, 2018 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
    Commented Aug 3, 2018 at 15:05
  • Try one thing, download that file and play it from the application bundle. Commented Aug 3, 2018 at 15:07
  • Then the issue is with this file probably. Does it play in any other player? Commented Aug 3, 2018 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
    Commented Aug 3, 2018 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.