How to autoplay HTML5 mp4 video on Android?

后端 未结 15 965
一向
一向 2020-11-27 05:53

I had developed a mobile page by asp.net to play mp4 video.

I know iOS had disabled the autoplay function to minimize user bandwidth, so how can i autoplay HTML5 mp

相关标签:
15条回答
  • 2020-11-27 06:21

    I simplified the Javascript to trigger the video to start.

     var bg = document.getElementById ("bg"); 
     function playbg() {
       bg.play(); 
     }
    <video id="bg" style="min-width:100%; min-height:100%;"  playsinline autoplay loop muted onload="playbg(); "><source src="Files/snow.mp4" type="video/mp4"></video>
    </td></tr>
    </table>

    *"Files/snow.mp4" is just sample url

    0 讨论(0)
  • 2020-11-27 06:24

    Android actually has an API for this! The method is setMediaPlaybackRequiresUserGesture(). I found it after a lot of digging into video autoplay and a lot of attempted hacks from SO. Here's an example from 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);
        }
    }
    
    0 讨论(0)
  • 2020-11-27 06:24

    don't use "mute" alone, use [muted]="true" for example following code:

    <video id="videoPlayer" [muted]="true" autoplay playsinline loop style="width:100%; height: 100%;">
    <source type="video/mp4" src="assets/Video/Home.mp4">
    <source type="video/webm" src="assets/Video/Home.webm">
    </video>
    

    I test in more Android and ios

    0 讨论(0)
提交回复
热议问题