views:

107

answers:

2

My app plays a video in fullscreen mode when the app is started. Everything is working flawlessly from 3.0 to 4.1.

However, if I compile the same code for a universal app, it will work on the iPad, but will not work on the iPhone (simulator) anymore.

Has anyone solved this problem?

Here's the code:

if ([self respondsToSelector:@selector(presentMoviePlayerViewControllerAnimated:)]) {
  videoPath = [[NSBundle mainBundle] pathForResource:@"portrait" ofType:@"mov"];
  videoURL = [NSURL fileURLWithPath:videoPath];

  MPMoviePlayerController *aMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
  self.moviePlayerController = aMoviePlayerController;
  [aMoviePlayerController release];  

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
  [moviePlayerController.view setFrame:self.view.bounds];
  [self.view addSubview:moviePlayerController.view];

  moviePlayerController.controlStyle = MPMovieControlStyleNone;
 } else {
  //OS < 3.2
  videoPath = [[NSBundle mainBundle] pathForResource:@"landscape" ofType:@"mov"];
  videoURL = [NSURL fileURLWithPath:videoPath];

  MPMoviePlayerController *aMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
  self.moviePlayerController = aMoviePlayerController;
  [aMoviePlayerController release];

  moviePlayerController.movieControlMode = MPMovieControlModeHidden;
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerContentPreloadDidFinishNotification object:nil];
 }

And here's the error:

-[MPMoviePlayerControllerOld view]: unrecognized selector sent to instance

0x7924470

Even if I try to prevent this like so...

if ([moviePlayerController respondsToSelector:@selector(view)]) {
   [moviePlayerController.view setFrame:self.view.bounds];
  }

...the error is still thrown.

A: 

I have no explanation for the error, yet. But this seems to work (need to test on older devices):

if ([self respondsToSelector:@selector(presentMoviePlayerViewControllerAnimated:)]) {
        videoPath = [[NSBundle mainBundle] pathForResource:@"portrait" ofType:@"mov"];
        videoURL = [NSURL fileURLWithPath:videoPath];

        /* NEW */
        MPMoviePlayerViewController *aMoviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
        aMoviePlayerViewController.moviePlayer.view.frame = self.view.bounds;
        aMoviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
        [aMoviePlayerViewController.moviePlayer play];
        [self.view addSubview:aMoviePlayerViewController.view];
        self.moviePlayerController = aMoviePlayerViewController;


    } else {
        //OS < 3.2
        videoPath = [[NSBundle mainBundle] pathForResource:@"landscape" ofType:@"mov"];
        videoURL = [NSURL fileURLWithPath:videoPath];

        MPMoviePlayerController *aMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
        self.moviePlayerController = aMoviePlayerController;

        aMoviePlayerController.movieControlMode = MPMovieControlModeHidden;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startVideo:) name:MPMoviePlayerContentPreloadDidFinishNotification object:nil];

        [aMoviePlayerController release];
    }

If only I could remember why I did it the other way in the first place ;)

Joseph Tura
A: 

I got the same error few days ago. It needed only change the base sdk from 3.2 to 4.1 Hope it helps

marcio
Yup, that fixed it. Thank you, marcio!
Joseph Tura