2

カスタム スキームを使用してサーバーからデータを取得しようとしています。なんとか生データを取得できましたが、デリゲートの実装に何か問題があるようです。

//data is never nil
[loadingRequest.dataRequest respondWithData:data];

AVPlayer に応答しないようです。このコードで私が間違っていることを誰でも見つけることができますか? 前もって感謝します。

これがコードです

NSURLComponents *comp = [[NSURLComponents alloc] initWithURL:[NSURL URLWithString: /*https*/item.contentUrl] resolvingAgainstBaseURL:NO];
comp.scheme = @"custom";
AVURLAsset      *asset          = [[AVURLAsset alloc] initWithURL:comp.URL options:nil];
AVAssetResourceLoader *loader   = asset.resourceLoader;
[loader setDelegate:self queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
AVPlayerItem    *playerItem     = [AVPlayerItem playerItemWithAsset:asset];

self.backupPlayer = [AVPlayer playerWithPlayerItem:playerItem];

これは、デリゲート メソッドの現在の実装です。

- (BOOL) resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest
{


    loadingRequest.contentInformationRequest.contentType = @"audio/mpeg";
    loadingRequest.contentInformationRequest.contentLength = 200000;
    loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES;

    self.loadingRequest = loadingRequest;

    NSURLComponents *comp = [NSURLComponents componentsWithURL:loadingRequest.request.URL resolvingAgainstBaseURL:NO];
    comp.scheme = @"https";
    NSMutableURLRequest *rq = [loadingRequest.request mutableCopy];
    [rq setURL:comp.URL];
    NSLog(@"\nHeaders:\n%@", [rq allHTTPHeaderFields]);
    if (self.session == nil)
    {
        NSURLSessionConfiguration *config = [NSURLSessionConfiguration     defaultSessionConfiguration];
        self.session = [NSURLSession sessionWithConfiguration:config delegate:self     delegateQueue:[NSOperationQueue mainQueue]];
    }
    [[self.session dataTaskWithRequest:rq completionHandler:

  ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error)
      {
         if (error != nil)
         {
              NSLog(@"Error, %@", error);
          }
          else
          {
              NSLog(@"Response: %@",response);
              if (data != nil)
              {
                  [self.loadingRequest.dataRequest respondWithData:data];
                  [self.loadingRequest finishLoading];
              }

          }

      }]
     resume];


    return YES;
}
4

0 に答える 0