Sign in to follow this  
Fenopiù

Preloading audio from JSON

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.

Share this post


Link to post
Share on other sites

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.

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.