我有 URL,例如 https://www.youtube.com/watch?v=c2ccXwwmcnA
。如果我将此 URL 传递给 UIWebView
,它会自动播放
视频。我尝试了以下方法
选项 1
@property (weak, nonatomic) IBOutlet UIWebView *webvie;
NSString *url=@"https://www.youtube.com/watch?v=7jYa7dfrXKU";
self.webvie.allowsInlineMediaPlayback = YES;
self.webvie.scrollView.bounces = NO;
self.webvie.mediaPlaybackRequiresUserAction = NO;
[self.webvie loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
选项 2
NSString *youTubeHTMLTemplate = @"<html><head><style type=\"text/css\">body { background-color: transparent;color: white;}</style></head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"></embed></body></html>";
finalHtml = [NSString stringWithFormat:youTubeHTMLTemplate, fullYopuTubeUrl, htmlFrameWidth, htmlFrameHeight];
选项 3
How to autoplay a YouTube video in a UIWebView
I dont want auto play the in UIWebview play youtube video
但所有选项都没有帮助我,
最佳答案
谢谢@Kyle,我试过你的评论,我在 URL 之后添加了 &autoplay=1
,它运行良好。答案是
NSString *url=@"https://www.youtube.com/watch?v=7jYa7dfrXKU&autoplay=1";
[self.webvie loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
self.webvie.scrollView.bounces = NO;
[self.webvie setMediaPlaybackRequiresUserAction:NO];
关于ios - 在 UIWebview,iOS 中自动播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34429042/