title: Play video from url in objective c with buffering
body: <p>Hi everyone I am working on an application in which I have a url of video and I have to play a video  from that url. I have done this job from this code </p>
  
  <pre><code>- (IBAction)btnPlayVideo:(id)sender
  {
      NSString *fileName = @"Server Address/Vdieo.flv";
  
      NSURL *streamURL = [NSURL URLWithString:fileName];
  
      mPlayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:streamURL];
  
  
      [self.view addSubview:mPlayerVC.view];
  
      //play movie
  
      MPMoviePlayerController *player = [mPlayerVC moviePlayer];
  
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullscreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
  
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
  
      player.view.frame = self.view.frame;
      [player setFullscreen:YES animated:YES];
      [self.view addSubview:player.view];
      [player prepareToPlay];
      [player play];
  
  }
  </code></pre>
  
  <p>//============Other Methods====================</p>
  
  <pre><code>- (void)willEnterFullscreen:(NSNotification*)notification {
      NSLog(@"willEnterFullscreen");
  }
  
  - (void)enteredFullscreen:(NSNotification*)notification {
      NSLog(@"enteredFullscreen");
  }
  
  - (void)willExitFullscreen:(NSNotification*)notification {
      NSLog(@"willExitFullscreen");
  }
  
  - (void)exitedFullscreen:(NSNotification*)notification {
      NSLog(@"exitedFullscreen");
      [mPlayerVC.view removeFromSuperview];
      mPlayerVC = nil;
      [[NSNotificationCenter defaultCenter] removeObserver:self];
  }
  
  - (void)playbackFinished:(NSNotification*)notification {
      NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
      switch ([reason intValue]) {
          case MPMovieFinishReasonPlaybackEnded:
              NSLog(@"playbackFinished. Reason: Playback Ended");
              break;
          case MPMovieFinishReasonPlaybackError:
              NSLog(@"playbackFinished. Reason: Playback Error");
              break;
          case MPMovieFinishReasonUserExited:
              NSLog(@"playbackFinished. Reason: User Exited");
              NSLog(@"exitedFullscreen");
  
              [[NSNotificationCenter defaultCenter] removeObserver:self];
              break;
          default:
              break;
      }
  
      [mPlayerVC.view removeFromSuperview];
      mPlayerVC = nil;
  
  }
  </code></pre>
  
  <p>My problem is that when this code run video player open and start loading and it takes too much time to run a video. Can anybody guide me how to run video in fast way from internet?</p>