Using NSURLProtocol to implement play while downloading for AVPlayer on iOS -


i'm trying play mp4 video on server , i'd cache video disk simultaneously.

i know can use 2 requests this, 1 download 1 created avplayer play video, waste network bandwidth.

so need use 1 outer request download data , capture nsurlrequest avplayer in mynsurlprotocol , manually create nshttpurlresponse them.

this how workflow looks like:

avplayer <-->  mynsurlprotocol <--> mp4 on network. 

by using charles can see avplayer takes 2 steps play video on internet. 1st step download first 2 bytes in order know whole video file size. following requests download different parts of file concurrently.

so mynsurlprotocol downloading whole mp4 file outer request , when there's enough data, create responses sent avplayer (also data).

this how creates , sends response.. 2-bytes request.

nsmutabledictionary* headers = ... // config headers this:  {     "accept-ranges" = bytes;     "cache-control" = public;     "content-length" = 2;     "content-range" = "bytes 0-1/6581417";     "content-type" = "video/3gpp";     date = "thu, 18 apr 2013 08:34:35 gmt";     expires = "wed, 12 feb 2014 08:34:35 gmt";     "last-modified" = "tue, 16 apr 2013 09:03:35 gmt";     "connection" = close;     server = "gvs 1.0";     "x-content-type-options" = nosniff; }   nshttpurlresponse* response = [[nshttpurlresponse alloc] initwithurl: self.request.url statuscode:206 httpversion:@"http/1.1" headerfields:headers];  [self.client urlprotocol:self didreceiveresponse:response  cachestoragepolicy:nsurlcachestorageallowed]; 

the problem avplayer doesn't send following requests fetch actual data, hm... clue?

ok, found this: how play movie url using custom nsurlprotocol?

it seems custom nsurlprotocol can not work avplayer. give up.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -