vmars316

audio: XMLHttpRequest cannot load file

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();
}
 

 

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post
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();

 

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...

  • Recently Browsing   0 members

    No registered users viewing this page.