views:

28

answers:

1

So I have an alert view pop up in my application and on clicking a view button a video is supposed to play but nothing happens in the simulator. I don't want to test this on a device until I get it working in the simulator. This is the code below as far as I can tell it should work. It reaches the Log statement and outputs to the console but the video does not play. Any ideas?

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        NSURL *url = [NSURL URLWithString:@"http://srowley.co.uk/endyVid.mp4"];
        MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] initWithContentURL:url] autorelease];

        //---play movie---
        [player setFullscreen:YES];
        [self.view addSubview:[player view]];
        NSLog(@"Player Should play!");
        [player play]; 
    }
}
+1  A: 

You need to set the frame on player's view.

    [[player view] setFrame: [self.view bounds]];
Robot K
Putting that in dodn't change anything :(
SamRowley
You can't create the player as an autoreleased object, or it deallocs before it gets a chance to play. Assign it to a property or ivar and release it when the user is done watching the movie.
Robot K
Also, you probably want to use didDismissWithButtonIndex: rather than clickedButtonAtIndex:. The former waits for the alert view to disappear before running, which seems like what you'd want before playing a video.
Robot K
Awesome works perfectly, thank you very much!!
SamRowley