如何将本地视频文件嵌入到HTML中以在UIWebView中播放? [英] How to Embed a Local Video File Into Html to play in UIWebView?

查看:257
本文介绍了如何将本地视频文件嵌入到HTML中以在UIWebView中播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在WebView中播放视频文件,但视频正在自动播放,而无需用户交互。所以现在我采用了不同的方法来实现这一点。

I can play video files in WebView , but the videos are playing automatically without the user interaction. So now I am following different approach to achieve that.

    NSString* embedHTML = @"\
        <html><head>\
        <style type=\"text/css\">\
        body {\
        background-color: transparent;\
        color: white;\
        }\
        </style>\
        </head><body style=\"margin:0\">\
        <embed id=\"yt\" src=\"http://www.businessfactors.de/bfcms/images/stories/videos/defaultscreenvideos.mp4\" type=\"application/x-shockwave-mp4\" \
        width=\"%0.0f\" height=\"%0.0f\"></embed>\
        </body></html>";


 _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 412.0)];

    [_webView setOpaque:NO];
    NSString *html = [NSString stringWithFormat:embedHTML, _webView.frame.size.width, _webView.frame.size.height];
    [_webView loadHTMLString:html baseURL:nil];

这样,我可以从互联网上播放视频文件。但是我想从本地内存中播放文件。

This way , I can play video file from the internet. But I want to play the files from the Local memory.

即使尝试传递本地文件路径变量,视频也无法播放。任何人都可以告诉我如何将我的本地文件嵌入html,以便我可以在网络视频播放,就像互联网视频?

Even if tried to pass the local file path variable, the video is unable to play. Can anyone tell me how to embed my local file into the html so that I can play in webview as like the internet video ?

案例1:视频自动播放在WebView中,但播放按钮仍然在顶部。
CASE 2:如上所示嵌入在线视频网址,并且可以播放视频。但我想传递本地视频文件路径,而不是在线视频网址

推荐答案

从本地内存如果你使用UIWebView。如果您希望影片无法自动播放,您必须在HTML档案中输入验证码(假设您目前显示的HTML档案属于自己的影片)。

you can't run files from local memory if you are using UIWebView. If you want your video to not play automatically, you have to enter code into your HTML file (I'm assuming the HTML files you are displaying are your own) to disable auto play for the video.

如果您使用object,下面是您可以关注的示例代码:

If you are using object, here is a sample code for you to follow

<object width="160" height="144">
<param name="autoplay" value="false">

<embed src="sample.mov" width="160" height="144"
autoplay="false" controller="false"
</embed>

</object> 

这篇关于如何将本地视频文件嵌入到HTML中以在UIWebView中播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆