Failed to execute 'play' on 'HTMLMedia

2019-07-28 09:00发布

问题:

play() trigger simultaneously in chrome android without user gesture on soundmanager2

Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture.

but its works fine when we change datasaver off by site settings in chrome android

please help me from this

回答1:

If you are attempting to "auto-play" audio, i.e., on load or page display etc., then it is usually going to be blocked by mobile devices. iOS does this basically all the time.

http://www.schillmania.com/projects/soundmanager2/doc/technotes/#mobile-device-limitations

For HTML5 audio load and playback to work, you need to call the audio stuff immediately from a user touch/click/gesture, and no setTimeout() or other asynchronous stuff is allowed in-between.