Skip to content

Instantly share code, notes, and snippets.

@rbreve
Created November 25, 2016 16:04
Show Gist options
  • Select an option

  • Save rbreve/bd1c732ed99f7e3f16cc7bced5d6ea28 to your computer and use it in GitHub Desktop.

Select an option

Save rbreve/bd1c732ed99f7e3f16cc7bced5d6ea28 to your computer and use it in GitHub Desktop.
download video
-(void) downloadVideo:(NSString *) urlToDownload
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Downloading Started");
NSURL *url = [NSURL URLWithString:urlToDownload];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSString *outputURL = NSTemporaryDirectory();
outputURL = [outputURL stringByAppendingPathComponent:@"downloaded.mp4"];
//saving is done on main thread
dispatch_async(dispatch_get_main_queue(), ^{
[urlData writeToFile:outputURL atomically:YES];
NSLog(@"downloaded! %@", outputURL);
[self.loadingImageIndicator setHidden:YES];
self.videoView = [[VideoPlayerView alloc] init];
[self loadVideoToView:[NSURL fileURLWithPath:outputURL]];
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment