How to use a web socket video stream with AVFoundation?

I have a resource sending a video stream via websockets (I have no control over the forwarding method). I can read from the socket using SocketRocket without any problems, but AVPlayerilk needs it NSURL, not a stream of NSDatabytes.

Here are some solutions I tried:

  • Custom NSURLProtocolto route bytes from socket to NSURLProtocolClient. It turns out, however, that AVPlayerthey are MPMoviePlayerViewControllernot used NSURLConnection.

  • This similar question tried to write bytes to disk and add them with bad results.

  • Use CocoaHTTPServer to stream proxy stream. The APIs here (unless I am missing something) are not conducive to writing an arbitrary amount of data into the response.

How can I trick AVPlayer into playing my video stream?

+4
source share
1 answer

AVAssetResourceLoaderDelegate. AVAsset URL-, myapp://path/that/means/something/to/myapp, [[AVAsset resourceLoader] setDelegate:myObj queue:myQueue], NSData - . AVAssetResourceLoadingDataRequest replyWithData:.

+3

Source: https://habr.com/ru/post/1532850/


All Articles