Custom gesture required to start playing HTML5 Android player

I use the HTML video tag on Android, and sometimes the chrome browser says that it requires explicit user gestures / click to start playback:

Failed to execute 'play' in 'HTMLMediaElement': API can only be initiated by user gesture

I know this is a known issue in Android, but I don’t understand why it sometimes plays automatically, and in other cases it requires user action!

I am using a video tag with an auto play option.

+5
source share
2 answers

Auto play is disabled with the Android SDK 17 to avoid poor user experience when playing videos (for example, unwanted playback, unwanted use of data). Typically, a video should only be played after a user action. It is recommended for Android and iOS at present.

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

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

Today, Google’s decision regarding autorun is discussed and discussed: http://chromium-bugs.chromium.narkive.com/cW5IXVgj/issue-178297-in-chromium-android-chrome-does-not-allow-applications-to-play-html5 -audio-without-an

+2
source

As of January 24, 2017

HTML5 video tags can automatically run on android if the video is disabled. You will need to include the muted and auto-play attributes in the tag so that they work as intended.

Here is the link to the article: Autostart on Chrome for Android from version 53

+2
source

Source: https://habr.com/ru/post/1238301/


All Articles