在 javascript 中使用 webkit-playsinline
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14472690/
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
use webkit-playsinline in javascript
提问by hanism
How do I use webkit-playsinline in javascript instead of in html5 video tag? I want to use it just like using video tag control/autoplay attribute in javascript or if you guys have any other method that is working? I'm working on a PhoneGap iOS app that stream video.
如何在 javascript 中而不是在 html5 视频标签中使用 webkit-playsinline?我想像在javascript中使用视频标签控制/自动播放属性一样使用它,或者你们有没有其他有效的方法?我正在开发用于流式传输视频的 PhoneGap iOS 应用程序。
Below is some approach that I have tried but none are working:
以下是我尝试过但没有奏效的一些方法:
videoPlayer.WebKitPlaysInline = "webkit-playsinline"; videoPlayer.WebKitPlaysInline = "WebKitPlaysInline"; videoPlayer.webkit-playsinline = "webkit-playsinline"; videoPlayer.WebKitPlaysInline = "true"; videoPlayer.WebKitPlaysInline = true; videoPlayer.webkit-playsinline = "true"; videoPlayer.webkit-playsinline = true;
videoPlayer.WebKitPlaysInline = "webkit-playsinline"; videoPlayer.WebKitPlaysInline = "WebKitPlaysInline"; videoPlayer.webkit-playsinline = "webkit-playsinline"; videoPlayer.WebKitPlaysInline = "true"; videoPlayer.WebKitPlaysInline = true; videoPlayer.webkit-playsinline = "true"; videoPlayer.webkit-playsinline = true;
My current code(js):
我当前的代码(js):
function loadPlayer() {
var videoPlayer = document.createElement('video');
videoPlayer.controls = "controls";
videoPlayer.autoplay = "autoplay";
videoPlayer.WebKitPlaysInline = true;
document.getElementById("vidPlayer").appendChild(videoPlayer);
nextChannel();
}
My current code(html):
我当前的代码(html):
<body onload="loadPlayer(document.getElementById('vidPlayer'));"><!-- load js function -->
<li><span class="ind_player"><div id="vidPlayer"></div></span></li><!-- video element creat here -->
Any helps are much appreciate. Thanks.
任何帮助都非常感谢。谢谢。
回答by Jon Lucas
You can do this without jQuery:
您可以在没有 jQuery 的情况下执行此操作:
var videoElement = document.createElement( 'video' );
videoElement.setAttribute('webkit-playsinline', 'webkit-playsinline');
You have to activate this functionality in your iOs application's WebView :
您必须在 iOs 应用程序的 WebView 中激活此功能:
webview.allowsInlineMediaPlayback = true;
You can check this post for more details:
您可以查看此帖子以了解更多详细信息:
回答by Luke Robertson
You need to attach it to the video element and set it as video's attribute
您需要将其附加到视频元素并将其设置为视频的属性
such as :
如 :
<video class="" poster="" webkit-playsinline>
<source src="" type="video/ogg" preload="auto">
<source src="" type="video/mp4" preload="auto">
</video>
so you could do (with jQuery) :
所以你可以做(使用 jQuery):
$('video').attr('webkit-playsinline', '');

