Autostart html5 video using android 4 browser

后端 未结 2 1041
梦毁少年i
梦毁少年i 2020-11-30 10:20

I want to auto-start android html5 video using android 4 ice cream sandwich browser. I tried many java-script functions and autobuffer autoplay tags of html5 video. But noth

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 11:01

    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);
        }
    }
    

    works on Android 4.4.4

提交回复
热议问题