Jump to content

audio: XMLHttpRequest cannot load file


vmars316
 Share

Recommended Posts

Hello & Thanks ,
I can't seem to play an *.mp3 file . 
XMLHttpRequest cannot load file:///C:/Phaser/vm-WIP/CowMoo.mp3. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Pls, what am I doing wrong ?
Thanks

Quote

 

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'vm-benghazi-audio-CKjs', { preload: preload, create: create, update: update });
function preload() {
    game.load.audio('cowmoo', 'CowMoo.mp3');
}
var onceThru =1;
var cowMoo;
function create() {
    cowMoo = game.add.audio('cowmoo');
}

function update() {
    if (onceThru = 1) {
        collisionLies02();
        }
    onceThru = onceThru + 1;
}
function collisionLies02() {

    cowMoo = game.audio.play('cowmoo')
    cowMoo.play();
}
 

 

Link to comment
Share on other sites

4 hours ago, vmars316 said:

Hello & Thanks ,
I can't seem to play an *.mp3 file . 
XMLHttpRequest cannot load file:///C:/Phaser/vm-WIP/CowMoo.mp3. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Pls, what am I doing wrong ?
Thanks

 

are you doing this via jsFiddle?

Link to comment
Share on other sites

What you're doing wrong is, basically, not using an HTTP server to serve you content. Yes you need that even for local machine.

Luckily for you, there's a really simple method that requires precisely zero fiddling.

1) Install node.js

2) open up node.js console, switch to directory in which you wish to install server (you can simply use Node's own directory)

3) install http-server via npm (type "npm install http-server")

4) start http-server, type your game directory as an argument (e.g. "http-server c:/phaser/vm-wip/"), keep the console window open

5) open up your game in your browser by your local address on port 8080 (e.g. "localhost:8080/")

7) next time you want to start the server, you first need to switch to the directory in which it's installed and start it from there

Voila. Now you develop your game in the same (more or less) environment as it would be on a real server. If something doesn't work with this setup, there's very good chance it won't work on real server either.

As a side note, cross origin content is a huge security hole. You should always consider possibility of attack through it.

Link to comment
Share on other sites

Thanks ,

I decided to reWrite code from 'play music.js' example to be sure I had it right .

It works , except the sound keeps on playing .

Sounds like it is stuck on static reverb .

I specified loop = 'false' . 

Any ideas why it does that ?

It runs fine here:

 http://liesandcowpies.com/testMe/vm-phaser/vm-play-music-WEB.html 

I also tried to run it here: http://phaser.io/sandbox/edit/wojtlUJC 

but just get a black screen .

Quote

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'vm-play-music', { preload: preload, create: create, update: update});
//    "use strict";
function preload() {
    game.load.audio('boden', 'CowMoo.mp3');
}
var s;
var music;
var onceThru =1;
function create() {
    music = game.add.audio('boden',2,'false');
    music = game.add.audio('boden');
    music.play();
}
function update() {
    if (onceThru = 1) {
        collisionLies02();
        }
    onceThru = onceThru + 1;
}
function collisionLies02() {
    music = game.add.audio('boden',2,'false');
    music.play();

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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