пыльник у меня есть некоторый код, который должен играть видео после того, как пользователь выбрал видео, которое он хочет по имени в uitableview
:Objective-C: Как воспроизвести видео с UITableViewCell?
NSLog(@"url %@",[filePathsArray objectAtIndex:indexPath.row]);
NSString *currentFileName = [filePathsArray[indexPath.row] lastPathComponent];
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:currentFileName];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
//Play the movie now
movieController = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];
[[movieController view] setFrame: [self.view bounds]];
[self.view addSubview: [movieController view]];
[movieController play];
Код должен принять filePathsArray
который является только имя файла, в моих документах каталог и корс, я не могу использовать только имя файла для воспроизведения видео, это должен быть полный путь. Например, мне нужно получить полный путь, как в симуляторе. «/ Users/UserName/Library/Application Support/iPhone Simulator/4.3.2/Applications» вместо этого я получаю только имя файла, например «123.mp4».
Проблема с кодом этой строки: NSString *currentFileName = [filePathsArray[indexPath.row] lastPathComponent];
еще раз, что связано с получением имени файла. Проблема приводит к сбою симулятора, и я получаю следующее:
Thread 1: EXC_BAD_ACCESS(code=1, address=0xc08384e7)
Может кто-нибудь помочь?
Редактировать
Я поместил NSLog(@"row %i - filePathsArray %@", indexPath.row, filePathsArray);
в - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {}
, где мои другие коды и я в очередной раз получил ошибку нить, но я тогда поставил NSLog(@"row %i - filePathsArray %@", indexPath.row, filePathsArray);
в
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}
и что в выходных данных отладчика :
filePathsArray (
"1372954494.023550.mp4",
"1372954525.440379.mp4",
"1372954698.070642.mp4",
"1372954717.124080.mp4",
"1372954881.568860.mp4",
"1372954995.932892.mp4",
"1372955079.400627.mp4",
"1372955121.735828.mp4",
"1372955151.191822.mp4",
"1372955204.253028.mp4",
"1372955317.622774.mp4",
"1372955394.617367.mp4",
"1372955455.130194.mp4",
"1372955748.579562.mp4",
"1372955801.431035.mp4",
"1372955982.626679.mp4",
"1372956220.934516.mp4",
"1372956313.205083.mp4",
"1372956396.179499.mp4",
"1372956433.715887.mp4",
"1372956521.383647.mp4",
"1372956556.635456.mp4",
"1372956865.871915.mp4",
"1372957260.725387.mp4",
"1372957729.062718.mp4",
"1372957817.498707.mp4",
"1372958542.838564.mp4",
"1372958898.002360.mp4",
"1372958944.864006.mp4",
"1372958981.295354.mp4",
"1372959288.333242.mp4",
"1372959511.324370.mp4",
"1372959557.161786.mp4",
"1372959979.054552.mp4",
"1372960381.754023.mp4",
"1372960609.649583.mp4",
"1372964668.874020.mp4",
"1372964985.709783.mp4",
"1372965088.565757.mp4",
"1372965163.876937.mp4",
"1372965296.464444.mp4",
"1373027973.427050.mp4",
"1373028300.018729.mp4",
"1373028402.868729.mp4",
"1373031752.143091.mp4"
)
которые являются правильными именами мои сохраненные файлы.
EDIT
Вот мой полный код:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(!filePathsArray)
{
return 0;
}
if ([filePathsArray count] > 0)
return [filePathsArray count];
else
return 0;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray = [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil]mutableCopy];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"row %i - filePathsArray %@", indexPath.row, filePathsArray);
NSString *currentFileName = filePathsArray[indexPath.row];
NSLog(@"url %@",[filePathsArray objectAtIndex:indexPath.row]);
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES) objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:currentFileName];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
//Play the movie now
movieController = [[MPMoviePlayerController alloc] initWithContentURL: fileURL];
[[movieController view] setFrame: [self.view bounds]];
[self.view addSubview: [movieController view]];
[movieController play];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"urlstring %@",[filePathsArray objectAtIndex:indexPath.row]);
cell.textLabel.text = [filePathsArray[indexPath.row] lastPathComponent];
return cell;
}
Каков результат работы NSLog на вашей первой линии? Есть ли путь или просто имя файла? В случае, если это просто имя файла, вам придется изменить путь к файлу: NSString * currentFileName = filePathsArray [indexPath.row]; – Swissdude
@Swissdude это просто имя файла для файлаPathArray – user2536879
@Swissdude и ваш код по-прежнему вызывает сбой – user2536879