Jump to content

Preloading audio from JSON


Fenopiù
 Share

Recommended Posts

Hi everybody!

I'm trying to preloading my audio from the same JSON where I preload the images.

This is my JSON file:

{
  "preloading": [
    {
      "type": "image",
      "key": "image1",
      "url": "Images/image1.png",
      "overwrite": false
    },
    {
      "type": "audio",
      "key": "audio1",
      "urls": [ "Audio/audio1.wav" ],
      "autoDecode": true
    }
  ],
  "meta": {
    "generated": "1401380327373",
    "app": "Phaser Asset Packer",
    "url": "http://phaser.io",
    "version": "1.0",
    "copyright": "Photon Storm Ltd. 2014"
  }
}

This is where I read the file:

function preload(): void {
    game.load.removeAll();
    game.load.pack('preloading', 'myjson.json', null, this);
    game.load.audio('audioN', 'Audio/audioN.wav', true);
}

function startOnClick() {
    audio = game.sound.play('audioN');
}

If I launch my game, images are preloaded succesfully as audioN.wav, the audio in JSON give me this error:

phaser.js:72849 Phaser.Loader: No URL given for file type: audio key: audio1

for all the audio file on my JSON file.

The JSON file, the images folder and the audio folder are located in the root of the project.

The audioN is a test that I've added to see if the problem was a type error in JSON or not, it doesn't change anything if I kick away it from my code.

Any idea why I receive this error?

Maybe @Arian Fornaris or anyone else could let me understand where my code is wrong? And, partial OT, why I cannot change the meta tags (except for "copyright")? If I do so it doesn't load nothing anymore.

Link to comment
Share on other sites

  • 2 weeks later...

Hi, @Fenopiù

 

Sorry I was out of the city and just see the comment now.

 

I tried with the json generated by Phaser Editor and it just works.

 

{
  "section": [{
    "type": "audio",
    "key": "bass",
    "urls": ["assets/audio/tech/bass.mp3"],
    "autoDecode": true
  }],
  "meta": {
    "generated": "1513193699726",
    "app": "Phaser Editor",
    "url": "http://phasereditor.boniatillo.com",
    "version": "1.0",
    "copyright": "Arian Fornaris (c) 2015,2016"
  }
}

 

To load the pack:

 

game.load.pack("section", "assets/pack.json");

 

I have no idea of what's happening to you. Maybe you should look into the Dev Tools in the Networks tab, disable cache and reload, look if the Audio/audio1.wav is requested by the browser.

Tell me if you find something, I can send you a small example.

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...