【问题标题】:autoplay on video in UIWebview,iOS在 UIWebview,iOS 中自动播放视频
【发布时间】:2016-03-29 11:55:22
【问题描述】:

我有例如 https://www.youtube.com/watch?v=c2ccXwwmcnA 的 URL。如果我将此 URL 传递给 UIWebView 它会自动将 play 视频。我尝试了以下方法

选项-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

但所有选项都没有帮助我,

【问题讨论】:

  • 我认为你必须在embed 标签内添加一个autoplay 属性。
  • 您要自动播放视频还是不自动播放视频?另外,您是否考虑过使用YouTube`s Helper Library for iOS
  • 我们已经尝试过这个,我们附加了用于播放视频的 ID 的链接,但我的要求是先加载 URL,然后我需要自动播放视频。
  • @KyleEmmanuel -- 等我试一次
  • @ShangariC:只是想知道当 Apple 因为占用用户数据而禁止自动播放时,您如何能够在 UIWebView 中自动播放?

标签: ios objective-c swift


【解决方案1】:

感谢@Kyle,我尝试了您的评论,我在 URL 之后添加了&amp;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]; 

【讨论】:

    猜你喜欢
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 2011-10-24
    • 2012-05-10
    • 1970-01-01
    相关资源
    最近更新 更多