NSBundle mainBundle] pathForResource 获取不到bundle文件

问题

 再利用以下代码获取视频文件路径的时候返回路径为nil


 NSString *noteVideoPath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];

原因

bundle文件没有添加到项目中

解决步骤

  • Build Phases -> Copy Bundle Resources 中添加对应视频文件这样将视频文件加入bundle中
  • 执行上述代码可以获得路径
//获取文件路径
  NSString *noteVideoPath = [[NSBundle mainBundle] pathForResource:@"notevideo20181023" ofType:@"mp4"];
//获取文件Url
  NSURL *videoUrl = [[NSBundle mainBundle] URLForResource:@"video.mp4" withExtension:nil];
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容