3

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}"
Jamie Taylor
  • 4,709
  • 5
  • 44
  • 66
JimiMerply
  • 71
  • 6

1 Answers1

4

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.

JimiMerply
  • 71
  • 6
  • I am also facing issue with Playing video.My implementation works well with lower than iOS7 version But fails on iOS7. Error="Network lost"Any suggestion? – Ganesh Amrule Sep 24 '13 at 10:40
  • @JimiMerply Hi Jimi, do you have working source code to stream video using CocoaHttpServer? I need some working implementation. Thank you. – Almas Adilbek Dec 11 '13 at 11:53
  • @Almas Adilbek To implement video streaming with CocoaHttpServer is pretty easy. You should just use HTTPFileResponse and override httpHeaders method as in my answer. For the rest look CocoaHttpServer samples. – JimiMerply Dec 11 '13 at 15:12
  • @JimiMerply now, actually i'm trying to do it. If you have time, and source code, it would be nice to see ur implementation. Saying this because i've limited time to do it. Thank you. – Almas Adilbek Dec 11 '13 at 16:30