use webkit-playsinline in javascript

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

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.

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;

My current code(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):

<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.

回答1:

You can do this without jQuery:

var videoElement = document.createElement( 'video' ); videoElement.setAttribute('webkit-playsinline', 'webkit-playsinline'); 

You have to activate this functionality in your iOs application's WebView :

webview.allowsInlineMediaPlayback = true; 

You can check this post for more details:

HTML5 inline video on iPhone vs iPad/Browser



回答2:

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) :

$('video').attr('webkit-playsinline', ''); 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!