NSUrlDomainError code -1002 "unsupported URL"

Viewed 2160

I am trying to use this library to enable caching my videos. And I receive this error:

Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSErrorFailingURLStringKey=4185c72c-252e-4019-8c1c-e30b4ccbe597/, NSErrorFailingURLKey=4185c72c-252e-4019-8c1c-e30b4ccbe597/, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <85069315-C50B-404F-86D8-548ED16B9103>.<1>

The code that is causing this problem is:

  VIResourceLoaderManager *resourceLoaderManager = [VIResourceLoaderManager new];
  self.resourceLoaderManager = resourceLoaderManager;
  AVPlayerItem *playerItem = [resourceLoaderManager playerItemWithURL:url];
  return [self initWithPlayerItem:playerItem frameUpdater:frameUpdater];
}

However if I remove the lines added for this library to work, then it works perfectly( without caching ) like this:

AVPlayerItem* item = [AVPlayerItem playerItemWithURL:url];
return [self initWithPlayerItem:item frameUpdater:frameUpdater];

The url in question is https://firebasestorage.googleapis.com/v0/b/app_domain/o/ed8f47cc-e9ee-43d0-848e-06edaaeaab70.mp4?alt=media&token=4185c72c-252e-4019-8c1c-e30b4ccbe597

I have changed the url a little bit for security. But it plays in browser and as I said it works well without the caching code.

3 Answers

According to error description, you have extra slash / at the end of your url:

NSErrorFailingURLStringKey=4185c72c-252e-4019-8c1c-e30b4ccbe597/ < extra slash

Url that you are requested, returninig 404 Not found!

I imported that library into the Flutter plugin you mentioned and was able to successfully load a video from a valid Firebase URL. I added some logging via mediaDownloader:didReceiveData: in the VIResourceLoadingRequestWorker class and it looks like the caching is happening properly.

Updated initWithURL:frameUpdater: method to look like this:

- (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpdater
{
    VIResourceLoaderManager* resourceLoaderManager = [[VIResourceLoaderManager alloc] init];

// Uncomment this to test with an empty cache, so the manager will re-cache
//    [resourceLoaderManager cleanCache];

    AVPlayerItem* item = [resourceLoaderManager playerItemWithURL:url];

    self = [self initWithPlayerItem:item frameUpdater:frameUpdater];

    if (self)
    {
        self.resourceLoaderManager = resourceLoaderManager;
        self.resourceLoaderManager.delegate = self;
    }

    return self;
}
  • See if by any chance, the above changes work for you, but it seems like it might be something else.
  • Try your code with a simpler test URL from somewhere and see if it is indeed something to do with the actual URL (doubtful, since I had success with the other Firebase video URL and you said yours definitely works in a browser)
  • Add a tag for Flutter to your question, so someone more familiar with that technology may see it and be able to help.
Related