title: iPhone: Trouble Playing Video in iOS 5
body: <p>In my iPhone app, I am taking video using ImagePickerview and storing it to document directory</p>
  
  <p>For iOS4 (device iPod) I can play video stored in document directory but for iOS 5 (device iPad) the same code is not working for playing video.</p>
  
  <p>so for iOS 5 is there any different way for storing and playing video from document directory </p>
  
  <p>(I also tried with library directory)</p>
  
  <pre><code>  -(IBAction)saveVideo:(id)sender
      {  
      imagepicker = [[UIImagePickerController alloc] init];
        imagepicker.delegate=self;
       if([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerSourceTypeCamera])
      {
          [imagepicker setSourceType:UIImagePickerControllerSourceTypeCamera];
          [imagepicker setMediaTypes:[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera]];
  
           [imagepicker setCameraDevice:UIImagePickerControllerCameraCaptureModeVideo];
  
          [self presentModalViewController:imagepicker animated:YES];
  
      } 
  
  
   }
  
  
  
      - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
  
  
       NSMutableString *tempPath = [[[info valueForKey:@"UIImagePickerControllerMediaURL"] absoluteString] mutableCopy];
      NSString *newPath1 = [NSString stringWithFormat:@"myVideo.mov"];
     [tempPath replaceOccurrencesOfString:@"file://localhost/private/" withString:@"/" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [tempPath length])];
     NSFileManager *manager = [NSFileManager defaultManager];
     NSError *error = nil;
    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], newPath1];
     NSString *newPath = [NSString stringWithFormat:@"%@/%@", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], newPath1];
  
  
     BOOL success = [manager copyItemAtPath:tempPath toPath:newPath error:&amp;error];
  
       if(error){         
      NSLog(@"New Path: %@", newPath);
      NSLog(@"Error: %@", error);
    }
  
     if(success)
     {
      NSLog(@"Succeed");     
     }
       [self dismissModalViewControllerAnimated:YES];
     }
  
  
      - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
     {
     [picker dismissModalViewControllerAnimated:YES];
     }
  
  
      -(IBAction)playVideo:(id)sender
      {
      NSArray *path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *documentsDirectory = [path objectAtIndex:0];
      NSString *myDBnew = [documentsDirectory stringByAppendingPathComponent:@"myVideo.mov"];
  
       NSURL *url = [[NSURL alloc] initWithString:myDBnew];
      NSLog(@"URL== %@",url);
      moviePlayer =  [[MPMoviePlayerController alloc]
                      initWithContentURL:url];
  
      //        [[NSNotificationCenter defaultCenter] addObserver:self
      //                                                 selector:@selector(moviePlayBackDidFinish:)
      //                                                     name:MPMoviePlayerPlaybackDidFinishNotification
      //                                                   object:moviePlayer];
  
      moviePlayer.controlStyle = MPMovieControlStyleDefault;
      moviePlayer.shouldAutoplay = YES;
      [self.view addSubview:moviePlayer.view];
      [moviePlayer setFullscreen:YES animated:YES];
      }
  </code></pre>
  
  <p>What could be wrong?</p>
  
  <p>Here is the code.</p>
  
  <p>If I add the video file into my project and use below code it is playing Video The only thing is it is not playing video from document directory</p>
  
  <pre><code>    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"myVideo" ofType:@"mov"]];
      moviePlayer =  [[MPMoviePlayerController alloc]
                      initWithContentURL:url];
  </code></pre>
  
  <p>Even in iTunes via flittering I can see the file:"myVideo.mov", after running the app in device means This codes recording and storing video but not able to read or play. </p>