저는 인터넷에서 로밍을 해왔습니다. 내가 뭘 잘못하고 있는지 정말로 모르겠습니다. 나는이 문제를 며칠 동안 지켜 봤다.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
, 테이블 셀을 선택하면 여기
NSCachesDirectory
NSDocumentDirectory
에의 데이터를 전송하기 위해 작동하지 않았다 코드입니다 ? –답장을 보내 주셔서 감사합니다. 내가 브레이크 포인트로 말할 수있는 것은 그것이 여러 번 호출된다는 것입니다. 그러나 나는 왜 그런지 모른다. ... – Joze
백 트레이스 (즉, "checkAndPlay"가 호출되는 원인이되는 이벤트)를 보면 어떤 일이 발생했는지 알 수 있습니다. 이론적으로, 코드를 올바르게 이해하면 표 셀을 선택하면 한 번만 호출해야합니다. 예? –