0

I’m using in my project phaser@3.24.0 and I have a problem with games on Safari 13.1.

In my preload method I have my loadConfig object with sound data:

var data = {
  mediaURL: "../../../static/sound/",
  dataObjects: [
    { type: "sound", name: "ok", file: "ok.ogg" },
    { type: "sound", name: "wrong", file: "wrong.ogg" },
    { type: "sound", name: "missing", file: "missing.png" },
  ],
};

loadData(data, this);

Helper function:

function loadData(data, game) {
    data.loadObjects.forEach((element) => {
    game.load.audio(element.name, config.mediaURL + element.file);
   }
}

In my create method:

this.sound.add("ok")
When I load the scene I get:
    Error: There is no audio asset with key “ok” in the audio cache
    initialize — phaser.min.js
    add — phaser.min.js
    create — culture.js
    create — phaser.min.js

On other browsers everything works fine, I don’t have problems with this.

**: this.sound.add("ok")

This is not working, I have all my paths to the file etc in the game scene entries/data. But it seems no to be added in a create method - only in safari.

James Skemp
  • 8,018
  • 9
  • 64
  • 107
Dex
  • 71
  • 7

3 Answers3

2

Safari doesn't support Ogg Vorbis.

Luca Fagioli
  • 12,722
  • 5
  • 59
  • 57
John Harper
  • 135
  • 1
  • 7
  • This doesn't help. I was thinking about the AudioContext spcific to Safari but this is not a problem. On Chrome I can see entries in sounds under cache.audio etc, but not in Safari. – Dex Aug 05 '20 at 14:35
  • Too bad -- sorry that didn't help you. If it isn't the Auto-Play blocking in Safari, maybe try both values for disableWebAudio in the config object passed to Phaser.Game()? See: https://rexrainbow.github.io/phaser3-rex-notes/docs/site/audio/ – John Harper Aug 05 '20 at 14:40
  • I did try all of these. Problem belongs to the safari itself, maybe the order of rendering and loading data. Something that is different then in Chrome etc. other then audiocontext. – Dex Aug 05 '20 at 15:05
  • 2
    Maybe Safari doesn't support Ogg Vorbis and Chrome does? Perhaps try converting the audio files to MP3? Just a shot in the dark! – John Harper Aug 05 '20 at 15:17
  • @JohnHarper I took the liberty to edit your answer based on your last comment, so I could upvote it. – Luca Fagioli Dec 22 '20 at 06:17
  • Hmm. I wonder if the original answer should have been left and the Ogg added to it? I think having both might still be valuable. – James Skemp Dec 22 '20 at 18:06
  • @JohnHarper trust me, if it was valuable I would have left it. – Luca Fagioli Dec 26 '20 at 19:21
0

Solution: there need to be an alternative in .mp3 format for Safari. Safari cannot proceed .oog files.

Dex
  • 71
  • 7
  • 1
    It sounds like John helped you come to this, so he probably should have updated his answer so you could accept it. If you choose not to do that, you should mark this as the solution if it was. – James Skemp Sep 16 '20 at 01:51
  • @JamesSkemp good point. I took the liberty to edit John's answer, so I could upvote it. Dex, please delete your answer and accept John's one. – Luca Fagioli Dec 22 '20 at 06:16
0

As other said here, Safari doesn't support .ogg format - https://caniuse.com/ogg-vorbis

So you should create a substitute sound with the extension mp3, m4a or something else depend on your research(I personally use m4a).

In order to load 2 sounds, one as back up, in Phaser do something like this:

scene.load.audio("ok", ["ok.ogg", "ok.m4a"]);

You can load an array of sounds with the same key, and the successful sound will play. https://rexrainbow.github.io/phaser3-rex-notes/docs/site/audio/#load-audio-file

Although you would need to change a bit your loadData() function to match an array of files.