3

iOS 장비 용 비디오를 스트리밍하는 Mac OS X에 서버를 구현하려고합니다.CocoaHTTPServer로 비디오 스트리밍

서버 측에서 CocoaHTTPServer를 사용하여 .mp4 비디오를 반환합니다.

- (HTTPFileResponse*)video:(NSString*)pPath 
    {  
     BOOL    fileExists = [[NSFileManager defaultManager] fileExistsAtPath:pPath]; 
     HTTPFileResponse *fileResponse = nil; 

     if (fileExists && [self isVideo:pPath]) 
     { 
      fileResponse = [[HTTPFileResponse alloc] initWithFilePath:pPath forConnection:self]; 
     } 

     return fileResponse; 
    } 

클라이언트 측에서는 MPMoviePlayerController를 사용하여 비디오를 읽습니다. 내가 비디오를 읽으려고 할 때

, 나는이 오류를 얻을 :

MPMovieFinishReasonPlaybackError.error : Error Domain=MediaPlayerErrorDomain Code=-11828 "Cannot Open" UserInfo=0xb92ca80 {NSLocalizedDescription=Cannot Open}" 

답변

4

을 나는 그렇게 HTTPFileResponse의 httpHeaders를 재정 의하여이 문제를 해결 : HTTPFileResponse없이 비디오를 반환하기 때문에

- (NSDictionary *)httpHeaders 
{ 
    NSString *key = @"Content-Disposition"; 
    NSString *value = [NSString stringWithFormat:@"attachment; filename=\"%@\"", [filePath lastPathComponent]]; 

    return [NSDictionary dictionaryWithObjectsAndKeys:value, key, nil]; 
} 

이 발생 신장. 그리고 MPMoviePlayerController는 확장자없이 비디오를 읽을 수 없습니다.

+0

나는 또한 비디오 재생 문제가 있습니다. 내 구현은 iOS7 버전보다 낮게 작동하지만 iOS7에서는 실패합니다. 오류 = "네트워크 손실"제안이 있습니까? –

+0

@JimiMerply 안녕하세요 Jimi, CocoaHttpServer를 사용하여 비디오를 스트리밍하는 소스 코드가 있습니까? 몇 가지 작업이 필요합니다. 고맙습니다. –

+0

@Almas Adilbek CocoaHttpServer로 비디오 스트리밍을 구현하는 것은 매우 쉽습니다. 내 대답과 마찬가지로 HTTPFileResponse를 사용하고 httpHeaders 메서드를 재정의해야합니다. 나머지는 CocoaHttpServer 샘플을보십시오. – JimiMerply