From c768b98ceacc13ddfa87f5e8c25d86c70e60a8ad Mon Sep 17 00:00:00 2001 From: Jessica Wu Date: Thu, 11 May 2017 17:48:09 -0400 Subject: [PATCH] implemented NSURLConnection delegate method to handle the case when failed to make the connection. --- PersistentStreamPlayer.m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/PersistentStreamPlayer.m b/PersistentStreamPlayer.m index 2f9b1aa..3abd0db 100644 --- a/PersistentStreamPlayer.m +++ b/PersistentStreamPlayer.m @@ -211,6 +211,27 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection } } +- (void)connection:(NSURLConnection *)connection + didFailWithError:(NSError *)error{ + + for (AVAssetResourceLoadingRequest *loadingRequest in self.pendingRequests) { + NSURLComponents * component = [[NSURLComponents alloc] initWithURL:loadingRequest.request.URL resolvingAgainstBaseURL:NO]; + component.scheme = self.originalURLScheme ?: @"http"; + + if ([component.URL.absoluteString isEqualToString: connection.currentRequest.URL.absoluteString] ) { + [loadingRequest finishLoadingWithError:error]; + [self.pendingRequests removeObject:loadingRequest]; + } + } + + if ([self.pendingRequests count] == 0) { + if ([self.delegate respondsToSelector:@selector(persistentStreamPlayerDidFailToLoadAsset:)]) { + [self.delegate persistentStreamPlayerDidFailToLoadAsset:self]; + } + } + +} + - (float)volume { return self.player.volume;