0

I have been trying to set the frame of the MPMoviePlayerController. But the app is crashing at the line player.view.frame = CGRectMake (0,0,480,320); in iOS 3.1.3 but works fine on iOS 3.2 or greater. What might be the problem?

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"aVideo.mp4" ofType:@""]];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

    // Register to receive a notification when the movie has finished playing.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayer];

    moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
        // Use the new 3.2 style API
        moviePlayer.repeatMode = YES;
         moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
        moviePlayer.shouldAutoplay = YES;
        [self.view addSubview:moviePlayer.view];
    } 
    else {
         Use the old 2.0 style API
       moviePlayer.view.frame = CGRectMake (0,0,480,320);
        [self.view addSubview: [moviePlayer view]];
        moviePlayer.movieControlMode = MPMovieControlStyleDefault;
        [moviePlayer play];

    }
}
Nithin
  • 6,435
  • 5
  • 43
  • 56

3 Answers3

2

The MPMoviePlayerController reference clearly states the view property is available from iOS3.2 onwards.

view

The view containing the movie content and controls. (read-only)

@property (nonatomic, readonly) UIView *view

Discussion

This property contains the view used for presenting the video content. This view incorporates all the background, content, and controls needed to display movies. You can incorporate this view into your own view hierarchies or present it by itself using a view controller.

To embed the view into your own view hierarchies, add it as a subview to one of your existing views. A good place to do this is in the loadView or viewDidLoad method of the custom view controller that presents your view hierarchy. You are free to change the view’s frame rectangle to accommodate the space available in your view hierarchy. The movie player uses the value in the scalingMode property to scale the movie content to match the frame you specify.

If you want to present the view by itself—that is, without embedding it in an existing view hierarchy—you can use an instance of the MPMoviePlayerViewController class to manage the presentation of the view. That class works directly with the movie player controller to present the view by itself.

You can add subviews to the view in this property. You might do this in cases where you want to display custom playback controls or add other custom content that is relevant to your application.

Availability

  • Available in iOS 3.2 and later.

And for iOS 3.1

Behavior in iOS 3.1 and Earlier

In iOS 3.1 and earlier, this class implemented a full-screen movie player only. After creating the movie player and initializing it with a single movie file, you called the play method to present the movie. (The definition of the play method has since moved out of this class and into the MPMediaPlayback protocol.) The movie player object itself handled the actual presentation of the movie content.

visakh7
  • 26,380
  • 8
  • 55
  • 69
1

What sort of crash is it? Is an exception thrown?

James Bedford
  • 28,702
  • 8
  • 57
  • 64
  • Yeah.. SIGABRT NSObject does not recognise selector after the line that I set the frame. – Nithin Jan 24 '11 at 10:06
  • Can post the code you're using above? And also the selector? Thanks. – James Bedford Jan 24 '11 at 10:13
  • Why are you adding the player view to two different views in the // 3.2 style API (you're not for the 2.0)? Can you let us know what playerView is? Thanks. – James Bedford Jan 24 '11 at 10:25
  • P.s. You also say the app is crashing at the line "player.view.frame = CGRectMake (0,0,480,320);" but I don't see this in your example. :S – James Bedford Jan 24 '11 at 10:29
  • I have been trying out different ways to avoid the crash. I have updated the code. – Nithin Jan 24 '11 at 11:38
  • This is an immediate problem I notice: moviePlayer.view.setFrame = CGRectMake (0,0,480,320); There is no property "setFrame", there is a property "frame" (if this doesn't make sense I'd advise reading the Property Programming Guide by Apple). – James Bedford Jan 24 '11 at 13:12
  • If the above wasn't clear enough. I mean, try: moviePlayer.view.frame = CGRectMake (0,0,480,320); – James Bedford Jan 24 '11 at 13:23
  • Also, please ensure the size of moviePlayer.view.frame is the same size as self.view (see if this solves the issue). – James Bedford Jan 24 '11 at 13:27
  • Ok. Can you add the exception thread trace that's printed on the crash? Thanks. – James Bedford Jan 25 '11 at 08:35
1

view property available in iOS 3.2 and later for MPMoviePlayerController.

e40pud
  • 336
  • 2
  • 18