3

iOS デバイス用のビデオをストリーミングするサーバーを MAC OS X に実装しようとしています。

サーバー側では、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

1 に答える 1

4

HTTPFileResponse の httpHeaders を次のようにオーバーライドして、この問題を修正しました。

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

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

これは、HTTPFileResponse が拡張子なしでビデオを返すために発生します。また、MPMoviePlayerController は拡張子がないと動画を読み込めません。

于 2013-07-12T06:16:07.090 に答える