Question

Ive been battling with a crash on my exercise app for the past couple of days when I try and play an instance of an MPMoviePlayerController in a UIView created in IB. The rest of the app runs fine, but if any MPMoviePlayer is instantiated, the debugger pauses the app without raising an exception. It's not just this code that causes it. Other methods of instantiating a moviePlayer from other posts or books cause the same result.

Its when I run this code that it drops out to the main:

NSURL *url = exercise.exerciseVideoURL;//path for vid

    self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];



    [self.moviePlayerController.view setFrame:self.movieHostingView.bounds];

    [self.moviePlayerController prepareToPlay];
    [self.moviePlayerController setControlStyle:MPMovieControlStyleNone];
    [self.movieHostingView addSubview:self.moviePlayerController.view];


    [[self.moviePlayerController view]
     setAutoresizingMask:(UIViewAutoresizingFlexibleWidth |
                          UIViewAutoresizingFlexibleHeight)];

    [[self.moviePlayerController view] setClipsToBounds:YES];
    [[self.moviePlayerController view] setFrame:[[self movieHostingView] bounds]];
    [self.movieHostingView addSubview:self.moviePlayerController.view];
    self.moviePlayerController.repeatMode = MPMovieRepeatModeOne;

I've tried using MPMoviePlayer instantiating code from other posts, binning off the model and just instantiate it with a direct path like in some of the other posts, but it still drops out to main().

Was it helpful?

Solution

Got it! Ive removed "All Exceptions" from the breakpoint tab and its running fine.Why would that cause it to drop out for MPMoviePlayer?! Anyhow, Thanks to everyone who helped out.

OTHER TIPS

are you reading video from disk (main bundle) or via internet? First, be always sure that your filepath is correct:

NSString *filepath = [url absoluteString];

if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{
    NSLog(@"file exists so init player");
}
else
{
    NSLog(@"try again!");
}

In my case I always add MPMoviePlayerController after its loaded. So you can do something like this:

NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"mp4"];

if ([[NSFileManager defaultManager] fileExistsAtPath:filepath])
{

    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    _moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

    [_moviePlayerController prepareToPlay];

    NSLog(@"frame = %@", NSStringFromCGRect(_moviePlayerController.backgroundView.frame));

    [_moviePlayerController.view setBackgroundColor:[UIColor yellowColor]];
    [_moviePlayerController.view setFrame:CGRectMake(0, 280, 320, 200)];


    // 

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieLoadStateDidChangeNotification:)
                                                 name:MPMoviePlayerLoadStateDidChangeNotification
                                               object:_moviePlayerController];   
}

and then some time later:

- (void)movieLoadStateDidChangeNotification:(NSNotification *)notification
{
    [self.view addSubview:_moviePlayerController.view];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top