例如我有网址https://www.youtube.com/watch?v=c2ccXwwmcnA
。如果我将此 URL 传递给UIWebView
它会自动play
视频。我尝试过以下方法
Option-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]]];
Option-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];
Option-3
如何在 UIWebView 中自动播放 YouTube 视频 https://stackoverflow.com/questions/15717754/objective-c-how-to-autoplay-a-youtube-video-in-a-uiwebview
我不想自动播放在 UIWebview 中播放 youtube 视频 https://stackoverflow.com/questions/20344439/i-dont-want-auto-play-the-in-uiwebview-play-youtube-video
但所有的选择都对我没有帮助,
谢谢@Kyle,我尝试了你的评论,我添加了&autoplay=1
在 URL 之后,它工作得很好。答案是
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];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)