I have tried to put music on my project and works perfectly on desktop and Android but not on iOS (tried on iPad and iPhone 5 with iOS 9.2). Despite that is very simple to play a sound file on an scene, I looked for a tutorial that helps me to know if I were doing something wrong. I’ve tried with the Basic Audio tutorial (http://developer.playcanvas.com/en/tutorials/beginner/basic-audio/) with same results, thats means, work ok on desktop and Android but not on iOS.
iOS does not allow sounds to be played unless you start playing them as a result of user interaction. So you could do something like:
var audiosource = this.entity.audiosource;
var startSound = function () {
document.removeEventListener('click', startSound);
audiosource.play('mysound');
}
var isIOS = /iPad|iPhone|iPod/.test(navigator.platform);
if (isIOS)
document.addEventListener('click', startSound);
Hi guys, I do have the same issue. I don’t know if something has changed in this 3 years but I copied and pasted the code with no result. Could anybody help me out? Is there a particular spot where to put the code?
I was happy after your comment but I tried even this tutorial scene https://playcanvas.com/editor/scene/440346 and nothing worked but only on the Ipad pro. Good news is working on the ipad air 2 mini after touching the screen. Is there something in the security settings that doesn’t allow play the sound?
@petru23 I have just tested that scene on the iPhone X and the iPhone XS and both function as expected. Maybe there’s some bug in Safari on iPad Pro? Can you get any non-PlayCanvas WebGL apps with audio working on your iPad Pro?