use webkit-playsinline in javascript
如何在javascript中而不是在html5视频标签中使用webkit-playsinline? 我想像在javascript中使用视频标签控件/自动播放属性一样使用它,或者是否还有其他方法可以使用? 我正在研究流视频的PhoneGap iOS应用。
以下是我尝试过的一些方法,但都没有用:
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;
我当前的代码(js):
1 2 3 4 5 6 7 8 | function loadPlayer() { var videoPlayer = document.createElement('video'); videoPlayer.controls ="controls"; videoPlayer.autoplay ="autoplay"; videoPlayer.WebKitPlaysInline = true; document.getElementById("vidPlayer").appendChild(videoPlayer); nextChannel(); } |
我当前的代码(html):
1 2 3 4 5 6 7 | <body onloadx="loadPlayer(document.getElementById('vidPlayer'));"><!-- load js function --> <li> <span class="ind_player"></span> </li> <!-- video element creat here --> |
任何帮助都非常感谢。 谢谢。
您可以在没有jQuery的情况下执行此操作:
1 2 | var videoElement = document.createElement( 'video' ); videoElement.setAttribute('webkit-playsinline', 'webkit-playsinline'); |
您必须在iOs应用程序的WebView中激活此功能:
1 | webview.allowsInlineMediaPlayback = true; |
您可以查看此帖子以获取更多详细信息:
iPhone与iPad /浏览器上的HTML5嵌入式视频
您需要将其附加到video元素并将其设置为video的属性
如 :
1 2 3 4 | <video class="" poster="" webkit-playsinline> <source src="" type="video/ogg" preload="auto"> <source src="" type="video/mp4" preload="auto"> </video> |
这样就可以做到(使用jQuery):
1 | $('video').attr('webkit-playsinline', ''); |