2013-07-08 171 views
2

我想播放音频和视频文件,我没有这些文件的URL。我正在使用AFNetwork下载文件,文件数据将以字节形式显示。下载时播放Mp4和Mp3文件

[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但没有发生。 请告诉我,如果这可能是部分下载的文件。

回答

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]; 
+1

谢谢,但我没有文件的URL我下载使用Web服务的文件。 –

+0

你有一个到web应用程序的源代码的例子吗? 你需要解析他提取的网址。 – VivienCormier

+1

我有一个Web服务用于下载一个文件,该文件以字节形式返回文件数据在进度块中。 –