Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从url播放视频_Ios_Objective C_Iphone - Fatal编程技术网

Ios 从url播放视频

Ios 从url播放视频,ios,objective-c,iphone,Ios,Objective C,Iphone,我在viewDidLoad方法中使用了此编码:- NSURL *fileURL = [NSURL URLWithString:@"https://www.youtube.com/watch?v=R4-YdC5N6Lo"]; moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; [moviePlayerController.view setFrame:CGRectMake(10,

我在
viewDidLoad
方法中使用了此编码:-

NSURL *fileURL = [NSURL URLWithString:@"https://www.youtube.com/watch?v=R4-YdC5N6Lo"];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(10, 100, self.view.frame.size.width-20, 260)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];

当我运行应用程序时,会显示一个黑屏,但不会播放视频。我想从url播放视频。有人能帮我吗。

MPMoviePlayerController不直接播放youtube视频,它在ios中只播放视频文件路径Url,请尝试


有关更多信息,请参阅MPMoviePlayerController,它不直接播放youtube视频,只在ios中播放视频文件路径Url,请尝试


有关更多信息,请参见iOS10中不推荐使用的MPMoviePlayerController,您现在可以使用
AVKit

NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self.view addSubview:playerViewController.view];
[self presentViewController:playerViewController animated:YES completion:nil];

MPMoviePlayerController
在iOS10中已被弃用,现在您可以使用
AVKit

NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self.view addSubview:playerViewController.view];
[self presentViewController:playerViewController animated:YES completion:nil];

你想播放特别的Youtube视频吗?你不能使用
MPMoviePlayerController直接播放Youtube视频
你可以测试你想播放特别的Youtube视频吗?你不能使用
MPMoviePlayerController直接播放Youtube视频
你可以测试@perfectThanks@perfect谢谢