2

我想播放一个音频和视频文件,我没有这些文件的 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 但没有任何反应。请告诉我这是否可能是部分下载的文件。

4

1 回答 1

1

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

NSURL *fileURL = [NSURL URLWithString:@"http://www.website.com/video.mp4"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController play];
[self.view addSubview:_moviePlayerController.view];
于 2013-07-08T10:58:47.700 回答