を果たしています。しかし、なぜ私のコードが機能していないのかわかりません。私はビデオがMPMoviePlayerViewController</strong><strong>を使用していること<strong>ダウンロード</strong>または<strong><strong></strong>保存ユーチューブビデオ</strong>ドキュメントディレクトリで、その後<strong>プレイ</strong>するドキュメントディレクトリ内の動画を保存したり、ダウンロードすることができませんでしだと、ドキュメントディレクトリから
私はコードの下に、これを使用しています:
prgrma MARK-ダウンロードまたは保存
-(IBAction)onclick_download:(id)sender
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Downloading Started");
NSString *urlToDownload = @"youtubeurl";
NSURL *url = [NSURL URLWithString:urlToDownload];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if (urlData)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"thefile.mp4"];
//saving is done on main thread
dispatch_async(dispatch_get_main_queue(), ^{
[urlData writeToFile:filePath atomically:YES];
NSLog(@"File Saved !");
});
}
});
}
プラグマMARK-あなたはで提供あなたのリンクとしてドキュメントディレクトリ
-(IBAction)onclick_playvideolocally:(id)sender
{
[self playvideolocally];
}
-(void)playvideolocally
{
NSURL *videoUrl;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
NSLog(@"files array %@", filePathsArray);
NSString *fullpath;
for (NSString *apath in filePathsArray)
{
fullpath = [documentsDirectory stringByAppendingPathComponent:apath];
videoUrl =[NSURL fileURLWithPath:fullpath];
}
MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl];
[self presentMoviePlayerViewControllerAnimated:videoPlayerView];
[videoPlayerView.moviePlayer play];
}
WebKitのWKWebViewクラス。 –
URLから直接YouTubeビデオをダウンロードすることはできません。また、そのアプリケーションストアではないsafe.appleはサードパーティからのビデオをダウンロードすることを許可しません –
@SunnyShah:URLからチューブビデオをダウンロードするにはどうすればいいですか? –