当 webview 加载 Youtube URL 时,我想实现播放和停止按钮相同的 sd youtube。我使用了下面的代码,但是当它加载到 webview 中时它开始播放(自动播放)。我只想将其加载到 webview 中而不是自动播放。我该怎么做?
这是我的代码:
UIWebView *videoview = [[UIWebView alloc] initWithFrame:CGRectMake(10,80,275.0,150)];
NSURL *nsurl=[NSURL URLWithString:strpreview];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[videoview loadRequest:nsrequest];
[self addSubview:videoview];
提前致谢
最佳答案
这里是使用 iFrame 在 iPhone 中创建加载嵌入视频的代码
NSString *yourURL = @"http://www.cloudstringers.com:14556/ingCloud/users/400010003/mp4_320p/efda2f8a618be8e4a36b81d31251752820130710115909.mp4";
NSString *embedHTML =[NSString stringWithFormat:@"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: #666666;\
padding:%f %f %f %f;\
color: blue;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe height=\"%f\" width=\"%f\" title=\"YouTube Video\" class=\"youtube-player\" src=\"%@" ></iframe>\
</body></html>",paddingTop,paddingRight,paddingBottom,paddingLeft,videoHeight,videoWidth,yourURL];
[self.webView loadHTMLString:embedHTML baseURL:nil];
希望这对您有所帮助。如果您需要更多信息,请告诉我。
关于iphone - 如何避免在 UIWebView 中自动播放 Youtube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17583716/