Reputation: 129
how to play a video in iPhone sdk using MPMoviePlayerViewController,here i capture video through device and save that particular video in documents directory . please tell me any one....
Upvotes: 0
Views: 107
Reputation: 38259
Get Document Directory Path:
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
Then you can use any of the directory listing APIs of NSFileManager.
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&error];
Now You have all contents at Directory Path (all videos stored) in array
NSURL *videoURL = [NSURL UrlWithString:[NSString stringWithFormat:@"%@/%@",documentsDirectory,[directoryContents objectAtIndex:0]]]; //check which url u want play as video name is in nsarray i have selected one random video name.
Use MovieControllerPlayer instance to play url:
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController.view setCenter:yourView.center];
//[mpViewController release];
Hope useful.
Upvotes: 1