1

I try to play a song on the browser. When I run the html following occurs : "Uncaught not ready to play file, buffer has yet to load. Try preload()"

HTML:

<!doctype>
<html>
    <head>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/p5.js"></script>
        <script src="p5.js-master/p5.js-master/lib/addons/p5.sound.js"></script>
        <script src="sketch.js"></script>
    </head>
    <body>

    </body>
</html>

sketch.js:


    var song;
    function preload() { 

    song = loadSound("song.mp3");

    }

    function setup() {

        createCanvas(100,100);
        song.play();
    }

    function draw() {
        background(0);
    }

help!

  • Check your network tab in your [developer tools](https://happycoding.io/tutorials/javascript/developer-tools). Is it actually loading `song.mp3`? Is that file located where P5.js is expecting it to be? – Kevin Workman Dec 13 '18 at 21:14
  • I looked the song file it looks there is no problem about. Btw I just noticed there is also cdn link of p5.sound.js. I replaced it instead of downloaded p5.sound file. But this time it gives no error but also song is not playing. – Dt_developer Dec 14 '18 at 18:08
  • It's going to be pretty hard for us to help you since we can't run your code. Can you link to your page, or to a CodePen running your code, or to the P5.js web editor running your code? – Kevin Workman Dec 14 '18 at 18:10
  • It has just worked after I waited a while! Thank you for comment anyway! – Dt_developer Dec 14 '18 at 18:31
  • Update your original question stating that you simply needed to wait. – rpeg Dec 28 '21 at 17:06

0 Answers0