我是新手。我正在尝试从阵列中调用视频。我知道我正在将字符串与对象混合。但我不知道该替换它。这是[错误的]代码行:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: _arrayVidSrc ofType:@".mp4" inDirectory:@"videos"]];
我该如何解决?
这是整个代码块:
- (void)viewDidLoad
{
[super viewDidLoad];
self.titlelabel.text = self.titlecontents;
self.navBar.title = self.titlecontents;
//video load from array
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: _arrayVidSrc ofType:@".mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
}
答案 0 :(得分:2)
从上下文中我想你想获得视频的URL数组。如果_arrrayVidSrc
是一个数组,则只应传递其中一个元素(例如,在不正确的代码行中尝试使用_arrayVidSrc[0]
):
NSString * firstVideoFileName = _arrayVidSrc[0];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:firstVideoFileName
ofType:@".mp4"]];