How to play movie with url using custom NSURLProtocol?

As you know, play the movie with the MPMoviePlayerController object using

[[MPMoviePlayerController alloc] initWithContentURL: aURL]; 

Now, I want to create a custom NSURLProtocol in which I will decrypt the source of the movie that has been encrypted with the DES algorithm. Is it possible? Thank you for giving any ideas. If you help ~

+8
url ios mpmovieplayercontroller nsurlprotocol
source share
4 answers

UPDATE: I spoke with Apple about this, and at the moment it is not possible to use MPMoviePlayerController with a subclass of NSURLProtocol!


Hey

I am not sure, but it is possible. I am currently working on something similar, but have not received it completely. I found that MPMoviePlayerController interacts with my custom subclass NSURLProtocol, but it seems to be important to consider the HTTPHeaders from NSURLRequest as they determine the range of bytes that MPMoviePlayerController needs.

If you dump them in your subclass NSURLProtocol, you will get something like this twice to start:

 2011-01-16 17:00:47.287 iPhoneApp[1177:5f03] Start loading from request: { Range = "bytes=0-1"; 

}

So my GUESS is that while you can provide the correct range and return the mp4 file that MPMoviePlayerController can play, it should be possible!

EDIT: Here's an interesting link: Resource Protection in iPhone and iPad Applications

+13
source share

The solution is to request a proxy through a local HTTP server. I accomplished this with CocoaHTTPServer .

See an example of HTTPAsyncFileResponse .

+6
source share

There is another solution with iOS 7. You can use AVAssetResourceLoaderDelegate for AVAssetResourceLoader. But this will only work with AVPlayer.

There is an Apple demonstration project called AVARLDelegateDemo, and you should find what you need. (I think linking to it is not a good idea, so just find it in the developer library on developer.apple.com). Then use any custom URL scheme (without NSURLProtocol declaration) and process this URL scheme in AVAssetResourceLoaderDelegate.

If there is huge interest, I can provide proof of concept.

+5
source share
 @property AVPlayerViewController *avPlayerVC; @property NSData *yourDataSource // initialise avPlayerVC NSURL *dummyURL = [NSURL URLWithString:@"foobar://dummy.mov"];// a non-reachable URL will force the use of the resourceLoader AVURLAsset *asset = [AVURLAsset assetWithURL:dummyURL]; [asset.resourceLoader setDelegate:self queue:dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)]; AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset]; self.avPlayerVC.player = [AVPlayer playerWithPlayerItem:item]; self.avPlayerVC.player.actionAtItemEnd = AVPlayerActionAtItemEndNone; // implement AVAssetResourceLoaderDelegate - (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest { loadingRequest.contentInformationRequest.contentType = (__bridge NSString *)kUTTypeQuickTimeMovie; loadingRequest.contentInformationRequest.contentLength = self.yourDataSource.length; loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES; NSRange range = NSMakeRange((NSUInteger)loadingRequest.dataRequest.requestedOffset, loadingRequest.dataRequest.requestedLength); [loadingRequest.dataRequest respondWithData:[self.yourDataSource subdataWithRange:range]]; [loadingRequest finishLoading]; return YES; } 

Note the use of a dummy URL to force AVPlayer use the AVAssetResourceLoaderDelegate methods instead of directly accessing the URL.

+1
source share

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


All Articles