【问题标题】:Movie play error电影播放错误
【发布时间】:2012-05-31 10:18:14
【问题描述】:

我正在尝试在设备上播放视频。视频是这个 video

和我的代码:

  NSString *urlStr = @"http://easyhtml5video.com/images/happyfit2.mp4";
NSURL *url = [NSURL fileURLWithPath:urlStr];
  moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0, 0, 320, 400);  
[moviePlayer play];

当我启动应用程序时,会看到一个电影屏幕,但没有播放电影。你能帮我看看错在哪里吗?

【问题讨论】:

    标签: ios objective-c mpmovieplayercontroller


    【解决方案1】:

    尝试使用 NSURL *url = [NSURL URLWithPath:urlStr];

    而不是 NSURL *url = [NSURL fileURLWithPath:urlStr]; 这是一个网页网址而不是文件网址。

    【讨论】:

      【解决方案2】:

      查看此视频以供参考。这对我有用-

      - (IBAction)playMovie:(id)sender
      {
          NSString *filepath   =   @"http://easyhtml5video.com/images/happyfit2.mp4";
          NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
          MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
      
          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete:)
                                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                                   object:moviePlayerController];
      
          [self.view addSubview:moviePlayerController.view];
          moviePlayerController.fullscreen = YES;
          [moviePlayerController play];
      }
      
      - (void)moviePlaybackComplete:(NSNotification *)notification
      {
          MPMoviePlayerController *moviePlayerController = [notification object];
          [[NSNotificationCenter defaultCenter] removeObserver:self
                                               name:MPMoviePlayerPlaybackDidFinishNotification
                                                                                      object:moviePlayerController];
      
          [moviePlayerController.view removeFromSuperview];
          [moviePlayerController release];
      }
      

      【讨论】:

      • 它没有播放。屏幕显示了几秒钟,但视频没有播放。您导入了哪个框架?你的 .h 课怎么样
      • 试试这个 - mobile.tutsplus.com/tutorials/iphone/…。这也有源代码。
      • 错误是这样的:AVPlayerItem 类的实例 0x7a58230 已被释放,而键值观察者仍向其注册。观察信息被泄露,甚至可能被错误地附加到其他对象上。在 NSKVODeallocateBreak 上设置断点以在调试器中停止。这是当前观察信息: ( Context: 0x0, Property: 0x78593e0>
      • 答案在堆栈跟踪本身中。
      • 我遇到了同样的问题——仅限 iOS5。每当播放器被释放时,我都会得到 AVPlayerItem 泄漏,然后再崩溃。有什么帮助吗??
      猜你喜欢
      • 1970-01-01
      • 2012-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多