Play Mp4 and Mp3 file while downloding

Saad Ur Rehman picture Saad Ur Rehman · Jul 8, 2013 · Viewed 14.5k times · Source

I want to play a audio and video file i dont have the URL of these file. I am downloading the file right now using AFNetwork and the file data is coming is bytes form.

[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) 
{
     float val = (float)totalBytesRead / totalBytesExpectedToRead;
     if(!isStart && val >= 0.5)
     {
        isStart = YES;

        UIWindow *window = [UIApplication sharedApplication].keyWindow;

        window = [[UIApplication sharedApplication].windows objectAtIndex:0];
            UIWebView * webView = [[UIWebView alloc]initWithFrame:window.frame];
            NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]];

            [webView loadRequest:urlRequest];
            [window addSubview:webView];
       }
}];

But the UIWebView is not opening this file I also used MPMoviePlayer but nothing happen. Please tell me if this possible partially downloaded file.

Answer

VivienCormier picture VivienCormier · Jul 8, 2013

You can play movie with MPMoviePlayerController streaming :

NSURL *fileURL = [NSURL URLWithString:@"http://www.website.com/video.mp4"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController play];
[self.view addSubview:_moviePlayerController.view];