Joe*_*Yan 21 html5 android html5-video
我用asp.net开发了一个移动页面来播放mp4视频.
我知道iOS已禁用自动播放功能以最小化用户带宽,那么我如何在Android上自动播放HTML5 mp4视频?
我已经将自动播放放在HTML5代码中,但它不起作用.
以下是我的代码:
<video autoplay controls id='video1' width='100%' poster='images/top_icon.png' webkitEnterFullscreen poster preload='true'>
<source src='http://192.xxx.xxx.xx/XXXXVM01.mp4' type='video/mp4; codecs='avc1.42E01E, mp4a.40.2' >
</video>
Run Code Online (Sandbox Code Playgroud)
此外,我已经解决了用户点击图像叠加层可以播放视频的问题.谢谢Karthi
这是代码:
<script type="text/javascript">
$(document).ready(function() {
$("#video1").bind("click", function() {
var vid = $(this).get(0);
if (vid.paused) { vid.play(); }
else { vid.pause(); }
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
谢谢
乔
Ang*_*ges 30
您可以将"静音"和"自动播放"属性添加到一起,以启用Android设备的自动播放.
例如
<video id="video" class="video" autoplay muted >Run Code Online (Sandbox Code Playgroud)
jam*_*yle 22
我使用了以下代码:
// get the video
var video = document.querySelector('video');
// use the whole window and a *named function*
window.addEventListener('touchstart', function videoStart() {
video.play();
console.log('first touch');
// remove from the window and call the function we are removing
this.removeEventListener('touchstart', videoStart);
});
Run Code Online (Sandbox Code Playgroud)
似乎没有办法自动启动.
这使得它们第一次触摸屏幕时视频将播放.它也将在首次运行时自行删除,以便您可以避免多个侦听器累加.
小智 6
Android实际上有一个API!该方法是setMediaPlaybackRequiresUserGesture().经过大量的视频自动播放和SO的大量尝试攻击后我才发现它.以下是blair vanderhoof的一个例子:
package com.example.myProject;
import android.os.Bundle;
import org.apache.cordova.*;
import android.webkit.WebSettings;
public class myProject extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html");
WebSettings ws = super.appView.getSettings();
ws.setMediaPlaybackRequiresUserGesture(false);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
113443 次 |
| 最近记录: |