2014-04-01 5 views
2

내 iPhone 사진 라이브러리에서 영화 파일을 검색하고이를 내 App의 Documents 디렉토리에 저장했습니다. 하나의 동영상 파일을 클릭하면 MPMoviePlayerController를 사용하여 재생하려고합니다. 불행하게도 다음과 같은 오류가있는 동영상 파일을 재생하지 못합니다.MPMoviePlayerController가 itemFailedToPlayToEnd와 함께 실패했습니다.

_itemFailedToPlayToEnd: { 
    kind = 1; 
    new = 2; 
    old = 0; 
    } 

이 문제를 해결하기 위해 오랜 시간 동안 검색했습니다. 누군가는 형식이 지원되지 않을 수도 있다고 말합니다. 동영상 파일은 사진 라이브러리에서 검색되므로 형식이 정상입니다. 또한 NSBundle에 파일을 복사하고 MPMoviePlayerController에서 재생할 수 있습니다. 그래서 파일은 괜찮습니다. 변경

NSString *newstr = [mFilePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
    DLog(@"the raw is %@ the newstr is %@", mFilePath, newstr); 
    NSURL *url = [NSURL URLWithString:newstr]; 
    DLog(@"the url is %@", url); 
#if 0 
    NSBundle *bundle = [NSBundle mainBundle]; 
    if (bundle) { 
     NSString *path = [bundle pathForResource:@"test" ofType:@"MOV"]; 
     if (path) { 
      url = [NSURL fileURLWithPath:path]; 
      DLog(@"the new url is %@", url); 
     } 
    } 
#endif 

    mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
    [mPlayer setMovieSourceType:MPMovieSourceTypeFile]; 
    [mPlayer prepareToPlay]; 
    [mPlayer.view setFrame:self.view.bounds]; 

    [mPlayer play]; 
    [self.view addSubview:mPlayer.view]; 

Can someone help me ? Thanks in advances! 
+0

동일한 오류가 발생하지만 서버에서 직접 재생할 때 오류가 발생하지 않습니다. –

답변

0

:

NSURL *url = [NSURL URLWithString:path]; 

다음, 나를 위해 그것을 고정

NSURL *url = [NSURL fileURLWithPath:path]; 

에 : 다음은 내 코드입니다

mPlayer.contentURL = url; 
[mPlayer prepareToPlay]; 

하지만 당신은 이미 제대로 이렇게. 일단 mPlayer를 만든 다음 다른 동영상에 대해 contentURL을 (alloc + initWithContentURL 대신) 이동하십시오. 너 그거 해봤 니?