- (void)loadPlayerView
{
NSURL *
url = [NSURL URLWithString:@"https://nyoba.innoplayer.co/cdn/videos/fairplay/muxed/encrypted/prog_index.m3u8"];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:
url options:nil];
[asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:[AVPlayerItem playerItemWithAsset:asset]];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
controller.player = player;
[self presentViewController:controller animated:YES completion:nil];
}
- (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
{
NSString *keyURL = @"https://nyoba.innoplayer.co/cdn/videos/fairplay/muxed/encrypted/Key.txt";
NSURL *urlx = [NSURL URLWithString:keyURL];
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:urlx];
[urlRequest setTimeoutInterval:20];
[urlRequest setHTTPMethod:@"GET"];
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:urlRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"requestHLSKeyWithURL httpResponse ==== %ld", (long)httpResponse.statusCode);
if (data != nil && (httpResponse.statusCode == 200 || httpResponse.statusCode == 100))
{
NSLog(@"requestHLSKeyWithURL data ==== %@", data);
[[loadingRequest contentInformationRequest] setContentType:AVStreamingKeyDeliveryPersistentContentKeyType];
[[loadingRequest contentInformationRequest] setByteRangeAccessSupported:YES];
[[loadingRequest contentInformationRequest] setContentLength:[data length]];
[[loadingRequest dataRequest] respondWithData:data];
[loadingRequest finishLoading];
}
else
{
NSLog(@"requestHLSKeyWithURL ==== NOT OK");
[loadingRequest finishLoading];
}
}];
[task resume];
return YES;
}