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

  • UIUsUIUs Posts: 169Moderators Admin
    edited April 2015
    lukeirvin wrote: »
    What am I missing or overlooking?

    What are you missing or overlooking?

    Code Tags.

    Please use them to make you code readable.

    You've been here long enough to understand why.
  • BrianSlickBrianSlick Treadmill Desk Ninja Posts: 10,690Tutorial Authors, Registered Users @ @ @ @ @ @ @ @
    Log what is going into and out of user defaults. See what you are dealing with.
    self.videoFilePath = (__bridge NSString *)([[info objectForKey:UIImagePickerControllerMediaURL] path]);
    

    There is no reason for the bridge here.
    NSObject *videoObj = [[NSUserDefaults standardUserDefaults] stringForKey:@"video"];
    

    You are pulling out a STRING, so therefore you should already know this is a string, so this should not be an NSObject.
    NSString *pathString = [NSString stringWithFormat:@"%@", videoObj];
    

    Ok, people! Seriously, stop formatting strings as strings
    Professional iOS App Development. Available for hire.
    BriTer Ideas LLC - WWW | Facebook | Twitter | LinkedIn

    BTIKit | SlickShopper 2 | Leave a PayPal donation
Sign In or Register to comment.