Can you hear the sound when you visit the project from your phone and look around the scene?
I’ve tried with two Xiaomi phones using latest Chrome, no sound… Unless the browser is moved away (minimized) and switched back on
Can you hear the sound when you visit the project from your phone and look around the scene?
I’ve tried with two Xiaomi phones using latest Chrome, no sound… Unless the browser is moved away (minimized) and switched back on
Hi @Newbie_Coder,
I very much think that on mobile you need some DOM/UI element interaction before being able to play any sound.
The div itself, which contains the iframe/canvas, does the trick when you “click” using desktop device, since when “tap, swipe, zoom” is no longer considered equivalent? Update: Firefox mobile isn’t playing either. Supported: Default MI browser, Older Brave, Opera Mini
This article can be of help on the general subject of autoplay in web browsers, this isn’t I think a PlayCanvas specific issue. Hope it helps:
Thanks for the source, definitely has useful info.
So I made a test
Basic Audio | Learn PlayCanvas
Requires 1 TAP to force audio playback.
Forking: PlayCanvas 3D HTML5 Game Engine
Launching from editor ~> Requires 2 TAPS to force audio playback.
Removing second sound slot (sound of firing)
Launching from editor ~> Tap as much as you want there will be no sound, although the other slot has valid audio with autoplay enabled.
How to get around it? If we want autoplay, we have to use a second slot to trigger the playback with onClick onTouch, it is best to use any short silent audio track with overlap checked.
I use this code to avoid playing sound unnecessarily on every click/tap
var SoundTemp = pc.createScript('soundTemp');
SoundTemp.prototype.initialize = function() {
this.preCount = 0;
if (this.app.touch) {
this.app.touch.on('touchstart', this.presound, this);
} else {
this.app.mouse.on('mousedown', this.presound, this);
}
};
SoundTemp.prototype.presound = function () {
this.preCount = this.preCount + 1;
if (this.preCount <= 2) {
this.entity.sound.play('Pre');
}
};
Why 2? Because that’s all it takes to start playing on your phone