下载时播放Mp4和Mp3文件



我想播放一个音频和视频文件,但我没有这些文件的URL。我现在正在使用AFNetwork下载文件,文件数据是字节形式的。

[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];
       }
}];

但是UIWebView没有打开这个文件,我也使用了MPMoviePlayer,但什么都没发生。请告诉我这是否可能是部分下载的文件。

您可以使用MPMoviePlayerController流媒体播放电影:

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

最新更新