User gesture required to start playback in Android HTML5 player

前端 未结 2 1035
北海茫月
北海茫月 2021-01-18 10:38

I am using the HTML5 video tag on android and sometimes the chrome browser says it requires an explicit user gesture/click to start playback:

Failed t

2条回答
  •  梦谈多话
    2021-01-18 11:18

    Auto-play is disabled since Android SDK 17 to avoid poor user experiences with video playback (i.e. undesired playback, undesired data usage). Normally video should only play following a user action. This is recommended behavior for both Android and iOS nowadays.

    You can, however, set setMediaPlaybackRequiresUserGesture to false to enable auto-play if you really need to. Remember to check the SDK version, because this option does not exist before Android SDK 17.

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

    There is a LONG discussion and debate about Google's decision regarding autoplay here: http://chromium-bugs.chromium.narkive.com/cW5IXVgj/issue-178297-in-chromium-android-chrome-does-not-allow-applications-to-play-html5-audio-without-an

提交回复
热议问题