2014-03-29 5 views
3

내 주요 목표는 테이블보기 항목을 클릭하고 비디오를로드 할 수 있습니다.비디오 재생하기 UITableView

void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder 
    NSString *dataPath = documentsDirectory; 
    filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:dataPath error:nil]; 

} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 

    return [filePathsArray count]; 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"SimpleTableCell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
    } 

    cell.textLabel.text = [filePathsArray objectAtIndex:indexPath.row]; 
    return cell; 
} 

그러나 파트 I : 테이블 뷰가 문서 디렉토리의 내용으로 채워집니다 내가 성공적으로이 작업을 수행 할 셀의 레이블에 파일 이름을 추가 할 수 있었다, 나는 다음과 같은 코드를 사용하여이 작업을 수행 한 어려운 부분을 찾는 것은 파일 부분을 여는 것입니다. 이것은 지금까지 내 코드입니다 : jQuery과 셀에 사용자가 클릭으로 비디오 플레이어를 전체 화면으로 열리도록하고 그냥 말할 때 어떻게됩니까

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"didSelectRowAtIndexPath"); 
    myURL=[NSURL URLWithString:[filePathsArray objectAtIndex:indexPath.row]]; 
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:myURL]; 
    [self.view addSubview:moviePlayerController.view]; 
    moviePlayerController.fullscreen = YES; 
    [moviePlayerController play]; 
    [self setController:moviePlayerController]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 

"로드 ..."전체 시간과 비디오하지 않습니다 로드 할 때 디버거에서 오류가보고되지 않습니다. 변수 myURL을 어떻게 설정해야합니까? 어떤 도움이라도 대단히 감사하겠습니다.

답변

3

마지막으로 잠시 후에 알아 냈이 있었다 문제는 단지 전체 파일 디렉토리가 아닌 이름을 가져 오는 것이었다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
NSLog(@"didSelectRowAtIndexPath"); 

NSString *currentFileName = [filePathsArray[indexPath.row] lastPathComponent]; 
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:currentFileName]; 

//Play the movie now 
NSURL *videoURL =[NSURL fileURLWithPath:filePath]; 
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL]; 
videoPlayerView.moviePlayer.fullscreen=TRUE; 

[self presentMoviePlayerViewControllerAnimated:videoPlayerView]; 
[videoPlayerView.moviePlayer play]; 
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

} 
+1

moviePlayer는 .h 파일의 속성이며 다음과 같습니다. @property (비 원자, 읽기 전용) MPMoviePlayerController * moviePlayer; – jjdoherty

0

NSURL은 리소스에 액세스하는 데 사용되는 프로토콜이 들어있는 경로와 다릅니다. 예를 들어 , 나는이 문제를 추측 http://stackoverflow.com

http:// 당신이 경로 문자열에서 URL을 만드는 것입니다,이 시도 :

NSString *urlStr = [NSString stringWithFormat:@"file://%@", [filePathsArray objectAtIndex:indexPath.row]]; 
myURL = [NSURL URLWithString:urlStr]; 
+0

불행하게도 그것이 작동하지 않았다,하지만 당신의 도움을 주셔서 감사 어쨌든 : VAR/모바일 ... 너무 비디오 플레이어에 문제가 있었다,이 작업 사람이 나와 같은 작업을 수행하고자하는 코드이다 ! 다른 아이디어가 떠오르면 나는이 문제로 인해 화를 냈다. – jjdoherty