Known issues about Autoplay
Autoplay in mobile browsers
For most of mobile webview and browsers, autoplay with sound is prevented by default, even if config.autoplay
is configured with the value of true
. Listen to Events.AUTOPLAY_PREVENTED
if you want to know when the autoplay was prevented
import Player, { Events } from 'xgplayer'
const player = new Player({
...,
autoplay: true
})
player.on(Events.AUTOPLAY_PREVENTED, () => {
console.log('autoplay was prevented!!')
})
Since autoplay with sound is generally prevented, another way to make media source start playing without is to set config.autoplayMuted
to true
for a muted playback
var player = new Player({
...,
autoplayMuted: true,
autoplay: true
})
There are serveral way for native app developers to customrize the webview for autoplay support
- IOS
mediaplaybackrequiresuseraction
IOS10+ TypesRequiringUserActionForPlayback
Notice
For IOS devices in low power mode, autoplay are prevented in any case
- Android
[setMediaPlaybackRequiresUserGesture](https://developer.android.com/reference/android/webkit/WebSettings#setMediaPlaybackRequiresUserGesture( Boolean))
Autoplay in PC browsers
- for PC playback, autoplayMuted is supported widely
var player = new Player({
...,
autoplayMuted: true,
autoplay: true
})
For chrome users, visit
chrome://media-engagement/
to see if current site is allowed for autoplay with soundFor safari users, site could be Authorized for autoplay with sound by configurating permissions of the site
Listen to
Events.AUTOPLAY_PREVENTED
if you want to know when the autoplay was prevented
import Player, { Events } from 'xgplayer'
const player = new Player({
...,
autoplay: true
})
player.on(Events.AUTOPLAY_PREVENTED, () => {
console.log('autoplay was prevented!!')
})