【问题标题】:Creating a new class in iOS在 iOS 中创建一个新类
【发布时间】:2013-12-25 04:45:39
【问题描述】:

嗨,我是 iOS 应用程序开发的新手,我已经创建了一个带有两个 ViewController 的应用程序,第二个控制器是在名为视频控制视图的类上创建的。一切都很好,但是当我点击播放时,我收到这样的警告,我不知道这是什么,任何人都可以帮助我,我被困在这里很长时间了。

2013-12-25 10:10:12.890 politicalapp[346:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

这是我为视频播放器输入的代码:

- (IBAction)play:(UIButton *)sender {
    NSURL  *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"d" ofType:@"mp4"]];

    MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc]initWithContentURL: url];

    [self presentMoviePlayerViewControllerAnimated:player];
    player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;[player.moviePlayer play];
    player = Nil;
}
@end

【问题讨论】:

  • 您将 nil 字符串传递给 initFileURLWithPath:您需要显示调用该方法的代码。
  • @user3133826 reason: ' -[NSURL initFileURLWithPath:]: nil string parameter' ** 首先请检查您的字符串是否为空..?或者把代码放在这里理解..

标签: ios mpmovieplayercontroller


【解决方案1】:

您的问题是 pathForResource 返回 nil。这可能有多种原因。尝试将其更改为:

NSURL  *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"d.mp4" ofType:nil]];

如果这不能解决问题,只需在 stackoverflow 上搜索多个名为“资源返回 nil 的路径”的问题,然后根据已经讨论的各种问题进行故障排除。

【讨论】:

    猜你喜欢
    • 2015-03-16
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    相关资源
    最近更新 更多