Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

html - Android webview html5 video autoplay not working on android 4.0.3

I have developed an application where the user can set videos on a web page: - They can specify a Youtube URL OR - They can upload a video

Depending on which option the user chooses i render a video page like this : If a video is from youtube:

<iframe type="text/html" width="640" height="385" src="http://www.youtube.com/embed/YOUTUBEID?autoplay=1&loop=1&autohide=1&fs=0"  frameborder="0"></iframe>

If the video is being uploaded:

<video id="video" style="cursor: pointer;" width="640" height="480"  autoplay controls loop>
  <source src="../video/Tareas_Diarias_Resumen.mp4" type="video/mp4" />
</video>

OK. All this works perfect on Google Chrome, but the fact is that the video is going to be watched on 16 Samsung GT-P5100 Android 4.03 Tablets.

We created an Android application which embeds an webView like that:

WebView engine = (WebView) findViewById(R.id.web_engine);
engine.setWebChromeClient(new WebChromeClient());
engine.getSettings().setPluginsEnabled(true);
engine.getSettings().setPluginState(PluginState.ON);
engine.getSettings().setJavaScriptEnabled(true);
engine.getSettings().setAllowFileAccess(true);
engine.loadUrl(miUrl);

And here I have two issues: 1- Youtube video. It works ok, I can see the video but with no autoplay, and we want it to work with autoplay. Any solution? 2- The uploaded video does not work, I can see the player but no video.

The video was converted with handbrake, choosing iphone & ipod-touch preset and "Web Optimized" option.

Any help or clue? Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Auto-play is disabled since Android SDK 17, but you can set setMediaPlaybackRequiresUserGesture to false to re-enable auto-play. Don't forget to check the SDK version because there is not such function in earlier versions.

    int SDK_INT = android.os.Build.VERSION.SDK_INT;
    if (SDK_INT > 16) {
        engine.getSettings().setMediaPlaybackRequiresUserGesture(false);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...