Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Playing a video from NSUserDefaults

lukeirvinlukeirvin Posts: 388Registered Users @ @
I have the path saved to NSUserDefaults, but when I attempt to pull it out and show the video in a movie player I just get a black screen with loading at the top.

Here's what I have tried:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

self.videoFilePath = (__bridge NSString *)([[info objectForKey:UIImagePickerControllerMediaURL] path]);

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
[[NSUserDefaults standardUserDefaults] setObject:self.videoFilePath forKey:@video];
[[NSUserDefaults standardUserDefaults] synchronize];
}

[self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)playButtonPressed:(id)sender {
NSObject *videoObj = [[NSUserDefaults standardUserDefaults] stringForKey:@video];

if (videoObj != nil) {
NSString *pathString = [NSString stringWithFormat:@%@", videoObj];
NSURL *streamURL = [NSURL fileURLWithPath:pathString];

self.moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:streamURL];

self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
self.moviePlayer.shouldAutoplay = YES;

[self.moviePlayer prepareToPlay];

[self.view addSubview:self.moviePlayer.view];

[self.moviePlayer setFullscreen:YES animated:YES];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.moviePlayer];

[self.moviePlayer play];

} else {
// UIAlertView is here
}
}


What am I missing or overlooking?

Replies

Sign In or Register to comment.