How to autoplay HTML5 mp4 video on Android?

后端 未结 15 1025
一向
一向 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: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  in config.xml
            super.loadUrl(Config.getStartUrl());
            //super.loadUrl("file:///android_asset/www/index.html");
    
            WebSettings ws = super.appView.getSettings();
            ws.setMediaPlaybackRequiresUserGesture(false);
        }
    }
    

提交回复
热议问题