Steve
Steve

Reputation: 55585

MPMoviePlayerController Bad Url Error

If I give MPMoviePlayerViewController a bad video URL to play, like so:

[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://badurl"]];

Is there a way to be notified that the video did not download?

I tried both of the following, but was not notified in either case:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadStateChanged) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

Upvotes: 2

Views: 1669

Answers (1)

rahul_send89
rahul_send89

Reputation: 953

first of all check if URL is reachable using Rechability.

 NSURL *myURL = [NSURL urlWithString: @"http://example.com"];
 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: myURL];
 [request setHTTPMethod: @"HEAD"];
 dispatch_async( dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_BACKGROUND, NULL), ^{
      NSURLResponse *response;
      NSError *error;
      NSData *myData = [NSURLConnection sendSynchronousRequest: request returningResponse: &response error: &error];
      BOOL reachable;

      if (myData) {
            // we are probably reachable, check the response
            reachable=YES;
      } else {
            // we are probably not reachable, check the error:
            reachable=NO;
      }

      // now call ourselves back on the main thread
      dispatch_async( dispatch_get_main_queue(), ^{
            [self setReachability: reachable];
      });
 });

its mention is this answer link

or

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];


- (void) playbackDidFinish:(NSNotification*)notification{
    NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason intValue]) {
    case MPMovieFinishReasonPlaybackEnded:
        NSLog(@"Playback Ended");         
        break;
    case MPMovieFinishReasonPlaybackError:
        NSLog(@"Playback Error"); //// this include Bad URL
        break;
    case MPMovieFinishReasonUserExited:
        NSLog(@"User Exited");
        break;
    default:
        break;
  }
}

or add a custom function for check the request timeout ..

[self performSelector:@selector(checkTimeout:) withObject:theMovie afterDelay:15];

if you are not receiving any Notification in your code
please check this answer for further reference .link

Upvotes: 4

Related Questions