Reputation: 4079
i got a project that someone else write.
the project saves video file in this path,file://localhost/var/mobile/Applications/CAC8F2CB-1C7D-4805-BF1A-42B63B258E95/Documents/output.mp4
i want to play the file with MPMoviePlayerController, how can i access the file?
Upvotes: 0
Views: 129
Reputation: 3043
If you store the above URL somewhere
NSString *fullURL = @"/var/mobile/Applications/CAC8F2CB-1C7D-4805-BF1A-42B63B258E95/Documents/output.mp4"
NSURL *movieURL = [NSURL fileURLWithPath: isDirectory:YES]; //If YES not works use NO
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
Hope that helps
Upvotes: 1
Reputation: 6587
Try this :-
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"output.mp4"];
Here in fullPath
you will have path you mentioned above.
For more detail on how to play video, refer this tutorial
Hope this helps you..
Upvotes: 1
Reputation: 3487
Firslty load the path and file URL:
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *localFilePath = [photoDirectoryPath stringByAppendingPathComponent:@"output.mp4"];
Then load up MPMoviePlayerController with the URL
- (void)initMoviePlayer
{
didExit = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:mMoviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
NSLog(@"initMoviePlayer: %@ ",[self getMovieURL]);
mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self getMovieURL]];
mMoviePlayer.shouldAutoplay = YES;
mMoviePlayer.view.hidden = YES;
[mMoviePlayer setControlStyle:MPMovieControlStyleNone];
mMoviePlayer.view.frame = [self.view bounds];
mMoviePlayer.scalingMode = MPMovieScalingModeNone;
[[self view] addSubview:[mMoviePlayer view]];
[mMoviePlayer play];
}
- (void) moviePreloadDidFinish:(NSNotification*)notification {
// start playing the movie
mMoviePlayer.view.hidden = NO;
animateTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(playMovie:)
userInfo:nil
repeats:NO];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
}
Upvotes: 1
Reputation: 9040
Try this code mate,
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
NSString *videoFilePath = [documentDirectory stringByAppendingPathComponent:@"output.mp4"];
NSURL *videoURL = [NSURL URLWithString:videoFilePath];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
Upvotes: 1