Stream video with CocoaHTTPServer
cocoahttpserver, ios, macos, mpmovieplayercontroller, objective-c
Solution
I fixed this problem by overriding httpHeaders of HTTPFileResponse like that :
- (NSDictionary *)httpHeaders
{
NSString *key = @"Content-Disposition";
NSString *value = [NSString stringWithFormat:@"attachment; filename=\"%@\"", [filePath lastPathComponent]];
return [NSDictionary dictionaryWithObjectsAndKeys:value, key, nil];
}
It happens because HTTPFileResponse return video without extension. And MPMoviePlayerController can't read video without extension.
Problem
I'm trying to implement a server on MAC OS X that streams video for iOS devices. On the server side I use CocoaHTTPServer to return an .mp4 video. ``` - (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; } ``` On the client side I use MPMoviePlayerController to read the video. When I try to read the video, I obtain this error: ``` MPMovieFinishReasonPlaybackError.error : Error Domain=MediaPlayerErrorDomain Code=-11828 "Cannot Open" UserInfo=0xb92ca80 {NSLocalizedDescription=Cannot Open}" ```