NSURLConnection blocking AVPlayer video playback
NSURLConnection blocking AVPlayer video playback
- Subject: NSURLConnection blocking AVPlayer video playback
- From: Martin Redington <email@hidden>
- Date: Thu, 02 Jul 2015 14:51:01 +0100
I've been playing with AVAssetResourceLoaderDelegate recently. I have
a manager class that vends AVPlayerItem's, and then intercepts the
requests for blocks of the video data, and serves them from cached
data, or downloads them using NSURLConnection, and passes them back to
the player, and saves them to the filesystem.
All of this works really nicely.
However, I have run into one issue that I don't quite understand.
Let's say there's a 20MB mp4 file, of which I have 18MB cached on the
filesystem.
When I get the AVAssetResourceLoaderDelegate callback, I reply with
the first 18MB of data. I then get a callback requesting the last 2MB,
and open an NSURLConnection.
I have an observer on the AVPlayer, that tells me when its ready to
play. In this scenario, even though I've handed back 18MB of data, the
AVPlayer is never ready to play until just after my new
NSURLConnection sends the didReceiveResponse callback.
If I degrade my network with Network Link Conditioner, to say Edge,
the time to receive the didReceiveResponse callback increases, and the
AVPlayer's change to ready to play tracks it almost exactly.
As far as threading goes, I have the AVPlayerItem's configured to use
the main queue, and the NSURLConnection's configured to the the main
queue's operation queue. This actually works really well in practice -
all of the callbacks to the AVAssetResourceLoaderDelegate and
NSURLConnection's are processed very very quickly, and the main thread
is not blocked in any way, especially between the connection start and
the didReceiveResponse callback.
I played around with giving the AVPlayerItem's and NSURLConnection's
their own queues, but this didn't seem to make any difference. For
some reason, the connection seems to block the player from playing,
even though its been handed a massive block of the initial data.
Can anyone give me a clue as to what might be going on here?
cheers,
m.
--
http://www.mildmanneredindustries.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden