Iphone 从HTML下载视频+;UIWebView
在我的新应用程序中,我需要从不同的网站下载视频,比如说它是视频下载应用程序。为此,我计划在html中搜索.mp4和.Flv url,然后尝试下载视频。有很多应用程序已经在做同样的事情了 我想问的是,我们如何下载视频?任何代码或链接之类的。这个应用程序是如何工作的?任何帮助都将不胜感激Iphone 从HTML下载视频+;UIWebView,iphone,ios,video,uiwebview,download,Iphone,Ios,Video,Uiwebview,Download,在我的新应用程序中,我需要从不同的网站下载视频,比如说它是视频下载应用程序。为此,我计划在html中搜索.mp4和.Flv url,然后尝试下载视频。有很多应用程序已经在做同样的事情了 我想问的是,我们如何下载视频?任何代码或链接之类的。这个应用程序是如何工作的?任何帮助都将不胜感激 我需要的是,当你在UIWebview中打开一个页面时,说你打开了“www.youtube.com”,然后选择一个要播放的视频,然后要求下载。下载时我需要URL(嵌入URL、Flv URL、mpv URL),这样我
我需要的是,当你在UIWebview中打开一个页面时,说你打开了“www.youtube.com”,然后选择一个要播放的视频,然后要求下载。下载时我需要URL(嵌入URL、Flv URL、mpv URL),这样我就可以使用paas来运行。我需要知道这个URL,如果你能使用这个库,它非常简单。您可以发出HTTP请求并使用其属性将文件下载到设备。假设您将下载按钮连接到一个函数
downloadVideoFromURL:withName:
- (void)downloadVideoFromURL:(NSURL*)url withName:(NSString*)videoName
{
//filepath to your app's documents directory
NSString *appDocPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *videosPath = [appDocPath stringByAppendingPathComponent:@"Videos"];
NSString *filePath = [videosPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4", videoName]];
//check to make sure video hasn't been downloaded already
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
//file was already downloaded
}
//video wasn't downloaded, so continue
else
{
//enable the network activity indicator
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
//create a temporary filepath while downloading
NSString *tmpPath = [videosPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-tmp.mp4", videoName]];
//the outputStream property is the key to downloading the file
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:tmpPath append:NO];
//if operation is completed successfully, do following
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//rename the downloaded video to its proper name
[[NSFileManager defaultManager] moveItemAtPath:tmpPath toPath:filePath error:nil];
//disable network activity indicator
[AFNetworkActivityIndicatorManager sharedManager].enabled = NO;
//optionally, post a notification to anyone listening that the download was successful
[[NSNotificationCenter defaultCenter] postNotificationName:@"DownloadedVideo" object:nil];
//if the operation fails, do the following:
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", error);
//delete the downloaded file (it is probably partially downloaded or corrupt)
[[NSFileManager defaultManager] removeItemAtPath:tmpPath error:nil];
//disable network activity indicator
[AFNetworkActivityIndicatorManager sharedManager].enabled = NO;
}];
//start the operation
[operation start];
}
}
如果你真的想进行黑客攻击,你会得到苹果的私有库“webkit”,如果你试图找到UIWebview的子视图,它可能会对你有所帮助,我从未尝试过,但你可以用这个逻辑进行测试。感谢Anthony的快速响应,这很有帮助,但我需要的是当你在UIWebview中打开一个页面时,说你打开了“www.youtube.com”选择要播放的视频,然后要求下载。下载时我需要URL(嵌入URL、Flv URL、mpv URL),这样我就可以使用paas来运行。我需要知道那件事URL@Mangesh维亚斯,你找到解决问题的办法了吗?我在我的应用程序中有相同的任务,我现在正在寻找解决方案。没有petr…我还没有。。。。我也很感兴趣。。我发现的是硬编码的网页端,然后在html中搜索视频URL,然后开始下载。。。。。。但我要寻找的是safari浏览器是否有API或黑客攻击,因为使用web浏览器进行视频播放……是否有人找到了解决方案。我仍在寻找答案,因为市场上有很多应用程序,所以一定有办法做到这一点。如果您使用UIWebView,而不是使用此链接@Mangesh,你找到解决办法了吗?我现在也在做同样的事情。嘿,你找到这个解决方案了吗?你对我的问题给了我答案