xcode 在 UIWebView 中自动播放视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9992735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Video playing automatically in UIWebView
提问by Cyril
Hi I have a webview and when i tried to load the video files in that , it starts playing the video automatically without user intervention. And also the play button is still displayed in webview (video is playing behind that). I am using the following code to load the URL
嗨,我有一个 webview,当我尝试在其中加载视频文件时,它会在没有用户干预的情况下自动开始播放视频。而且播放按钮仍然显示在 webview 中(视频在后面播放)。我正在使用以下代码加载 URL
NSURL* url = [NSURL fileURLWithPath:filePath];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
Can you tell me how to disable the play button OR the Video should start playing only after the user taps the play button ??
你能告诉我如何禁用播放按钮或者视频应该在用户点击播放按钮后才开始播放吗??
回答by Kuldeep
- (void)videoThumb:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = @"\
<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>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width,frame.size.height];
[webView loadHTMLString:html baseURL:nil];
[self.view addSubview:webView];
[webView release];
}
//Include above function to your page and call it by passing the urlstring
[self videoThumb:url:frame];
//frame : this parameter needs the size of the thumb you want to use.
I hope this may help you and better way for your purpose.
我希望这可以帮助您并更好地实现您的目的。