Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UITableView中获取视频文件路径?(tmp目录)_Ios_Objective C_Uitableview_Mpmovieplayercontroller - Fatal编程技术网

Ios 如何在UITableView中获取视频文件路径?(tmp目录)

Ios 如何在UITableView中获取视频文件路径?(tmp目录),ios,objective-c,uitableview,mpmovieplayercontroller,Ios,Objective C,Uitableview,Mpmovieplayercontroller,我正在UITableView中显示tmp目录的内容,但无法获取每个单元格的文件路径 当按下该单元格时,我的应用程序应使用MPMoviePlayer播放该文件,但不会 这就是我到目前为止所做的: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *tmpDirectory = NSTemporaryDirectory(); fileList

我正在UITableView中显示tmp目录的内容,但无法获取每个单元格的文件路径

当按下该单元格时,我的应用程序应使用MPMoviePlayer播放该文件,但不会

这就是我到目前为止所做的:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


NSString *tmpDirectory = NSTemporaryDirectory();
fileList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tmpDirectory error:nil]; //nsarray

NSString *movieURL = [fileList objectAtIndex:indexPath.row];

NSURL *url = [NSURL URLWithString:movieURL];

_moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];

[self presentModalViewController:_moviePlayerViewController animated:YES];
}
NSlog提供了视频的名称,但没有提供路径。由于睡眠不足,我觉得我已经想得太多了。

当你使用这个:

NSString *movieURL = [fileList objectAtIndex:indexPath.row];
NSString *movieURL = [tmpDirectory stringByAppendingPathComponent:[fileList objectAtIndex:indexPath.row]];

NSURL*url = [NSURL fileURLWithPath:movieURL];
它将只返回临时目录中的文件名, 所以用这个:

NSString *movieURL = [fileList objectAtIndex:indexPath.row];
NSString *movieURL = [tmpDirectory stringByAppendingPathComponent:[fileList objectAtIndex:indexPath.row]];

NSURL*url = [NSURL fileURLWithPath:movieURL];
使用此选项时:

NSString *movieURL = [fileList objectAtIndex:indexPath.row];
NSString *movieURL = [tmpDirectory stringByAppendingPathComponent:[fileList objectAtIndex:indexPath.row]];

NSURL*url = [NSURL fileURLWithPath:movieURL];
它将只返回临时目录中的文件名, 所以用这个:

NSString *movieURL = [fileList objectAtIndex:indexPath.row];
NSString *movieURL = [tmpDirectory stringByAppendingPathComponent:[fileList objectAtIndex:indexPath.row]];

NSURL*url = [NSURL fileURLWithPath:movieURL];

更改您的代码,如:

    NSString *tmpDirectory = NSTemporaryDirectory();
    NSLog(@"%@",tmpDirectory);
    NSArray *fileList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tmpDirectory error:nil]; //nsarray

    NSString *movieURL = [fileList objectAtIndex:indexPath.row];
    NSString *path=[tmpDirectory stringByAppendingPathComponent:movieURL];

更改您的代码,如:

    NSString *tmpDirectory = NSTemporaryDirectory();
    NSLog(@"%@",tmpDirectory);
    NSArray *fileList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tmpDirectory error:nil]; //nsarray

    NSString *movieURL = [fileList objectAtIndex:indexPath.row];
    NSString *path=[tmpDirectory stringByAppendingPathComponent:movieURL];

哇!非常感谢,我真不敢相信我忘记了stringByAppendingPathComponent.wow。非常感谢,我真不敢相信我忘记了stringByAppendingPathComponent。@CokePokes:事实上Midhun议员在我面前给出了正确的答案。答案是在我写答案时加载的,这就是为什么会出现重复。@CokePokes:事实上Midhun Mp在我面前给出了正确的答案。答案是在我写答案时加载的,这就是为什么会出现重复。