1

저는 인터넷에서 로밍을 해왔습니다. 내가 뭘 잘못하고 있는지 정말로 모르겠습니다. 나는이 문제를 며칠 동안 지켜 봤다.MPMoviePlayerViewController가 작동하지 않습니다.

//NSDocumentDirectory doesn't work either. 
NSArray *newPath = NSSearchPathForDirectoriesInDomains(NSMoviesDirectory, 
                 NSUserDomainMask, YES); 
NSString *moviesDirectory = [NSString stringWithFormat:@"%@/WebSurg", 
                [newPath objectAtIndex:0]]; 
// Check if the directory already exists 
if (![[NSFileManager defaultManager] fileExistsAtPath:moviesDirectory]) { 
    // Directory does not exist so create it 
    [[NSFileManager defaultManager] createDirectoryAtPath:moviesDirectory 
         withIntermediateDirectories:YES attributes:nil error:nil]; 
} 

이 응용 프로그램의 tableView에이 디렉터리의 내용을 표시합니다. 행을 두드리면 비디오가 재생됩니다. 그러나 그렇지 않습니다. 그것은 나에게 MPMoviePlayerViewController 모달 뷰를 보여 주며 아마 1 초 후에 숨 깁니다. 이것은 내가 그것을 사용하는 코드입니다 : 나는 쓸데없는 경로를 얻는 두 가지 방법을 시도했다.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSArray *moviesPath = NSSearchPathForDirectoriesInDomains(NSMoviesDirectory, 
                   NSUserDomainMask, YES); 
    NSString *moviesDirectory = [NSString stringWithFormat:@"%@/WebSurg", 
                 [moviesPath objectAtIndex:0]]; 
    NSString *movie = [self.tableData objectAtIndex:indexPath.row]; 
    NSString *moviePath = [NSString stringWithFormat:@"%@/%@", 
                 moviesDirectory, movie]; 
    NSURL *movieURL = [NSURL fileURLWithPath:moviePath]; 
    NSLog(@"MOVIEPATH: %@", moviePath); 

    NSString *alternatePath = [NSString stringWithFormat:@"%@/%@", 
              [[NSBundle mainBundle] resourcePath], movie]; 
    NSURL *alternateMoviePath = [NSURL fileURLWithPath:moviePath]; 
    movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:alternateMoviePath]; 
    movieViewController.moviePlayer.movieSourceType= MPMovieSourceTypeFile; 
    NSLog(@"Movie Load State: %d", [[movieViewController moviePlayer] loadState]); 
    NSLog(@"Alternate movie Path: %@", alternatePath); 
    [self presentMoviePlayerViewControllerAnimated:movieViewController]; 
    [movieViewController.moviePlayer play]; 
    [self checkAndPlay]; 
} 

- (void) checkAndPlay { 
    if ([[self.movieViewController moviePlayer] loadState] == MPMovieLoadStateUnknown) { 
     [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector: 
           @selector(checkAndPlay) userInfo:nil repeats:NO]; 
    } else { 
     [self.movieViewController setModalTransitionStyle: 
            UIModalTransitionStyleCrossDissolve]; 
     [self presentModalViewController:movieViewController animated:YES]; 
    } 
} 

그리고이 콘솔의 결과입니다

2012-10-08 10:14:52.392 WebsurgTemplates[3722:17903] MOVIEPATH: /Users/THISISME/Library/Application Support/iPhone Simulator/5.0/Applications/E075DBE3-BFEA-4F6A-9DFA-2CC912E14863/Movies/WebSurg/FirstVideo.mp4 
2012-10-08 10:14:52.459 WebsurgTemplates[3722:17903] Movie Load State: 0 
2012-10-08 10:14:52.460 WebsurgTemplates[3722:17903] Alternate movie Path: /Users/THISISME/Library/Application Support/iPhone Simulator/5.0/Applications/E075DBE3-BFEA-4F6A-9DFA-2CC912E14863/WebsurgTemplates.app/FirstVideo.mp4 

내가 크게 어떤 제안을 주셔서 감사하고 도움이 될 것이다!

UPDATE

는 지금까지 아무런 진전이 없다. 콘솔에 다른 데이터를 기록 할 수 있었는데,이 문제를 해결하는 데 도움이 될만한 정보가 있습니다. 비디오를 재생할 링크로 비디오를 직접 다운로드하는 빈 프로젝트를 만들려고했으나 작동하지 않았습니다. 일어나는 일은 똑같은 일입니다. jaydee3은 아마 NSMoviesDirectory에 액세스 할 수 없었기 때문에 예정된 것 같습니다. 그래서 NSDocumentDirectory로 바뀌었지만 문제가 해결되지 않았습니다. 파일이 존재하고 플레이어가 읽을 수 있도록 파일이 저장되어있는 형식인지 확인했습니다. 여전히 작동하지 않습니다. 내가 뭘 잘못하고 있는지 모르겠다. 제안/도움에 다시 한 번 감사드립니다.

여기 디버그 결과입니다. 완료 :

if ([[NSFileManager defaultManager] fileExistsAtPath:moviePath]) { 
    NSLog(@"FILE EXISTS"); 
    CFStringRef fileExtension = (__bridge CFStringRef) [moviePath pathExtension]; 
    CFStringRef fileUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL); 

    if (UTTypeConformsTo(fileUTI, kUTTypeImage)) NSLog(@"It's an image"); 
    else if (UTTypeConformsTo(fileUTI, kUTTypeMovie)) NSLog(@"It's a movie"); 
    else if (UTTypeConformsTo(fileUTI, kUTTypeText)) NSLog(@"It's text"); 
} 

RESULTS 
[6343:17903] MOVIEPATH: /Users/myname/Library/Application Support/iPhone Simulator/5.0/Applications/E075DBE3-BFEA-4F6A-9DFA-2CC912E14863/Documents/FirstVideo.mp4 
[6343:17903] FILE EXISTS 
[6343:17903] It's a movie 
+1

, 테이블 셀을 선택하면 여기 NSCachesDirectoryNSDocumentDirectory에의 데이터를 전송하기 위해 작동하지 않았다 코드입니다 ? –

+0

답장을 보내 주셔서 감사합니다. 내가 브레이크 포인트로 말할 수있는 것은 그것이 여러 번 호출된다는 것입니다. 그러나 나는 왜 그런지 모른다. ... – Joze

+0

백 트레이스 (즉, "checkAndPlay"가 호출되는 원인이되는 이벤트)를 보면 어떤 일이 발생했는지 알 수 있습니다. 이론적으로, 코드를 올바르게 이해하면 표 셀을 선택하면 한 번만 호출해야합니다. 예? –

답변

1

좋아요. 그래서 문제를 해결하고 범인을 찾을 수있었습니다.

간단한 설명은 다운로드 한 영화가 제대로 저장되지 않았기 때문입니다 (현재 가능한 이유를 조사 중입니다). 그리고이 때문에 플레이어는 존재하는 파일을 재생하려했으나 올바른 형식과 올바른 이름으로되어 있었지만 그 파일은 비어있었습니다. 다운로드 및 전송 및 재생 후 모든 파일 크기를 로깅하여이 사실을 알았습니다.

더 자세한 설명을 드리 자면이 영화를 NSCachesDirectory으로 다운로드 한 다음 NSDocumentDirectory에 저장했습니다. 파일을 실제로 찾았는지 그리고 파일이 "먹을 수있는"것인지 궁금해하기 시작했기 때문에 이것을 발견했습니다. NSDocumentDirectory에 직접 다운로드 할 때 동영상이 잘 재생됩니다. 이제 연결이 끊어 질 경우를 대비해서 해결해야합니다. NSCachesDirectory에 저장하면 자동으로 해결됩니다. 나는 그 제안에 대해 공개적이다. 그것은 두 번 호출되고 당신이 당신의 "`checkAndPlay`"방법에 중단 점을 설정 한 경우

NSArray *paths = NSSearchPathForDirectoriesInDomains 
       // HERE I changed NSCachesDirectory to NSDocumentDirectory fixed it 
          (NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *cachesDirectory = [paths objectAtIndex:0]; 
NSString *downloadPath = [cachesDirectory stringByAppendingPathComponent: 
                @"DownloadedVideo.mp4"]; 
NSArray *newPath = NSSearchPathForDirectoriesInDomains 
            (NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *moviesDirectory = [NSString stringWithFormat:@"%@", 
               [newPath objectAtIndex:0]]; 
self.downloadOperation = [ApplicationDelegate.mainDownloader downloadVideoFrom: 
            @"http://www.blablabla.web/iphone/download.php"          
              toFile:downloadPath];