iOS:使用ASIHttpRequest获取当前正在下载的字节

时间:2013-10-05 15:01:36

标签: ios download mpmovieplayercontroller asihttprequest nsdata

我正在使用ASIHttpRequest下载视频文件,我可以在下载完成后在目标路径中获取下载的文件。但根据我的要求,我想使用MPMoviePlayerController播放当前下载的视频,如何以NSData格式获取当前下载的字节以与MPMoviePlayerController一起播放?

即。如果视频是200mb,我已经下载了50mb,那么在下载剩余视频时我也可以播放50mb视频。

这是我下载文件的代码。

NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setTag:tag];
[request setTimeOutSeconds:60.f];
[request setShowAccurateProgress:YES];

[request setDownloadProgressDelegate:progressView];

[request setDidFinishSelector:@selector(requestFinished:)];
[request setDidFailSelector:@selector(requestFailed:)];

//    These delgates won't working
//    [request setDidReceiveResponseHeadersSelector:<#(SEL)#>]
//    [request setDidStartSelector:<#(SEL)#>]

[request setDownloadDestinationPath:downloadPath];
[request setAllowResumeForFileDownloads:YES];
[request setShouldContinueWhenAppEntersBackground:YES];
[request startAsynchronous];

//this will not call because I set UIProgressView to show downloading progress, to call it I need to set `self`
-(void)request:(ASIHTTPRequest *)request didReceiveBytes:(long long)bytes

运气好吗?其他解决方案?

1 个答案:

答案 0 :(得分:0)

Apple有一整套用于通过HTTP流式传输视频的API。查看https://developer.apple.com/streaming/上的所有详细信息。