Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No sounds on iOS safari after 3.53 #5696

Closed
laineus opened this issue May 13, 2021 · 7 comments
Closed

No sounds on iOS safari after 3.53 #5696

laineus opened this issue May 13, 2021 · 7 comments

Comments

@laineus
Copy link

laineus commented May 13, 2021

Version

  • Phaser Version: 3.53 or higher. 3.52 is ok.
  • Operating system: iOS 14
  • Browser: safari

Description

No sounds on iOS 14 safari after ver 3.53.
I found this commit 7cbf384 is making the issue.

SceneManager.loadComplete will no longer try to unlock the Sound Manager, preventing AudioContext was not allowed to start console warnings after each Scene finishes loading.

Example Test Code

// This is revert of https://github.com/photonstorm/phaser/commit/7cbf3840af296c2f1f510be15b39a2519f7a72cf
// If remove below, safari doesn't play sounds
Phaser.Scenes.SceneManager.prototype.loadComplete = function (loader) {
  const scene = loader.scene
  if (this.game.sound && this.game.sound.onBlurPausedSounds) {
    this.game.sound.unlock()
  }
  this.create(scene)
}

const config = {
  type: Phaser.AUTO,
  width: 200,
  height: 200,
  audio: {
    disableWebAudio: true // Another issue (?) https://stackoverflow.com/questions/63864590/no-sound-in-phaser-3-app-when-using-capacitor-to-build-for-ios
  },
  scene: {
    preload () {
      this.load.setBaseURL('https://libra.laineus.com')
      this.load.audio('bgm', ['audio/bgm/happy.ogg', 'audio/bgm/happy.m4a'])
    },
    create () {
      this.sound.add('bgm', { loop: true, volume: 1 }).play()
    }
  }
}
new Phaser.Game(config)

Additional Information

@laineus laineus changed the title No sounds on iOS safari after Phaser 3.53 No sounds on iOS safari after 3.53 May 13, 2021
@richso
Copy link

richso commented Jan 28, 2022

It's already more than half year and iOS15, when will this be fixed? Or any quick fix for embedding Phaser3 games using ionic framework + Angular instead of using v3.52?

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

@edooley
Copy link

edooley commented Nov 15, 2022

@photonstorm Just making sure I'm not missing something obvious (have searched all around and surprised how little I'm finding). We are building a cross platform iOS and Android app in phaser for a client. Audio on OSX Safari works completely fine but I cannot get a single thing to work for iOS Safari (testing on an iPhone 13 Pro running 15.6.1 and an iPad mini 2 running 12.4.8).

At first I thought it had to do with ionic/capacitor (which was supposedly fixed here, #5706) but then I saw that even the examples online don't work on my devices (https://phaser.io/examples/v3/category/audio/web-audio). @laineus mentioned here that "3.52 is ok" and you said it's been addressed in master, but that behavior seems to only apply to the HTML5 audio examples when dropping down the build version from the examples online. The web audio examples do not work on iOS for me no matter what Phaser Version I select (we need Web Audio working for performance reasons).

Any ideas? Thanks!

@photonstorm
Copy link
Collaborator

photonstorm commented Nov 15, 2022

@edooley just tested this example https://labs.phaser.io/view.html?src=src/audio/Web%20Audio/basic%20playback%20and%20events.js on an iPhone 14 running iOS 16 and it works perfectly.

Here is a video of the same test (and a couple of others) running on an iPhone 13 with iOS 15:

screenRecording-15-10-2022-17-28.mp4

Video recorded via Browserstack, but that's still real hardware, not emulated.

Both demos are working with 3.55.2 and 3.60 Beta 14. I didn't test any further back. Both are definitely Web Audio.

If you can isolate this with a simple test case, please open another issue.

Edit: Sorry, wasn't aware the Browserstack videos didn't include audio! I can guarantee 100% it was playing though. Will record another video if I get time.

@edooley
Copy link

edooley commented Nov 15, 2022

@photonstorm Thanks for the quick and thorough response. I think I finally figured it out, but it's still a bit strange. Out of habit, I keep the silent toggle enabled on my iOS devices (didn't even think to try that until just now, as playing media always works in Silent Mode for me). In fact, this is the first media scenario I've ever seen where I've been forced to toggle off Silent Mode to get something to play. Is this by design or an issue worth reporting? Thanks!

@photonstorm
Copy link
Collaborator

@edooley it's not possible for Phaser (or indeed the browser) to detect if you've got the Silent Mode toggle enabled or not. Media doesn't play by the same rules, so will ignore it, but Web Audio respects it. Apparently there may be a hacky work-around, but I've never tested it (and am doubtful it still works): goldfire/howler.js#1436

@edooley
Copy link

edooley commented Nov 15, 2022

Ah ok. So this seems to be a key difference between HTML5 and web audio. As long as it is intended behavior then I'm not worried about it. It has been my experience that iOS users are pretty conditioned to the silent mode switch and shouldn't have an issue with it. I'm just one of those rare cases where I prefer to leave it on all the time and have somewhat forgotten it exists. Thanks for all the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants