11

iphone (sdk 4)에 구현 된 뮤직 플레이어가 있으며 Mp3 (Transcoded on the fly) 또는 원시 프로그레시브 다운로드 모두에서 작동합니다.캐시 MPMoviePlayerController에서 프로그레시브 다운로드 콘텐츠

progressivedownloaded 콘텐츠 (직접 제어 할 수 없음)를 캐시하여 어쨌든 전체 콘텐츠를 다시 다운로드하지 않습니까?

또는 제어 할 글로벌 캐시 설정이 있습니까? ASIHTTP API를 사용하여 HTTP 서버에 접속하고 캐싱을 허용하는 데이터에 액세스했습니다.

미리 감사드립니다.

답변

1

NSURLConnection을 사용하여 파일을 저장하고 재생할 수 있습니다.

예 :

아래
-(void)downloadFileAtPath:(NSString *)path 
{ 
    NSURL *url     = [NSURL URLWithString:path];  
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 
     NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 
    [connection start]; 
} 

-(void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response 
{ 
    //NSLog(@"%s", __PRETTY_FUNCTION__); 
    [[NSFileManager defaultManager] createFileAtPath:pathForCurrentFile contents:nil attributes:nil]; 
    currentFile = [NSFileHandle fileHandleForUpdatingAtPath:pathForCurrentFile]; 
    if (currentFile) 
    { 
     [currentFile seekToEndOfFile]; 
    } 
} 

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data 
{ 
    //NSLog(@"%s", __PRETTY_FUNCTION__); 
    if(currentFile != nil){ 
     if (currentFile) { 
      [currentFile seekToEndOfFile]; 
     } 
     [currentFile writeData:data]; 
    } 
} 

-(void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error 
{ 
    NSLog(@"%s, %@", __PRETTY_FUNCTION__, error); 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    [currentFile closeFile]; 
} 

당신이 작동 테스트 한

//Playback 
NSString *loopFilePath = [[self applicationDocumentsDirectory].path stringByAppendingPathComponent:vidFileName]; 

NSURL *vidURL = [NSURL fileURLWithPath:vidFilePath]; 

self.vidController = [[MPMoviePlayerController alloc] initWithContentURL:vidURL]; 
self.vidController.view.frame = CGRectMake(0, 0, 640, 480); 
self.vidController.controlStyle = MPMovieControlStyleDefault; 
[self.view addSubview:self.vidController.view]; 
[self.vidController prepareToPlay]; 
[self.vidController play]; 
+0

재생을위한 코드? – vaughan

+0

안녕하세요,이 솔루션으로 성공하셨습니까? – Bkillnest

관련 문제