iPhone: Trouble Playing Video in iOS 5

In My iPhone App I am taking video using ImagePickerview and storing it to document directory

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.

so for iOS 5 is there any different way for storing and playing video from document directory

(I also tried with library directory)

    imagepicker = [[UIImagePickerController alloc] init];
     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:&error];

    NSLog(@"New Path: %@", newPath);
    NSLog(@"Error: %@", error);

     [self dismissModalViewControllerAnimated:YES];

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
   [picker dismissModalViewControllerAnimated:YES];

    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]

    //        [[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];

What could be wrong?

here is the code

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

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"myVideo" ofType:@"mov"]];
    moviePlayer =  [[MPMoviePlayerController alloc]

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.

Please Help and Suggest.



Here in my code the problem was the way i am creating url

   NSURL *url = [[NSURL alloc] initWithString:myDBnew];

which doesn't work for ios5 so i replaced in code by

  NSURL *url = [[NSURL alloc] initFileURLWithPath:<#(NSString *)#> isDirectory:<#(BOOL)#>];

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.