MPMoviePlayerController 仅在通用应用程序中抛出错误

发布于 2024-09-26 23:15:14 字数 1835 浏览 4 评论 0原文

我的应用程序启动时以全屏模式播放视频。从 3.0 到 4.1 一切都运行完美。

但是,如果我为通用应用程序编译相同的代码,它将在 iPad 上运行,但不再在 iPhone(模拟器)上运行。

有人解决这个问题了吗?

这是代码:

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];
 }

这是错误:

-[MPMoviePlayerControllerOld 视图]:发送到实例的选择器无法识别

0x7924470

即使我尝试像这样阻止这种情况...

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

...仍然会抛出错误。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙味迷妹 2024-10-03 23:15:14

几天前我遇到了同样的错误。只需要将基础 sdk 从 3.2 更改为 4.1
希望有帮助

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

染墨丶若流云 2024-10-03 23:15:14

我还没有对该错误的解释。但这似乎有效(需要在较旧的设备上进行测试):

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];
    }

如果我能记得为什么我首先以其他方式这样做就好了;)

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 ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文