I am new to Js, and p5 and I was trying to play a mp3 from my computer, but I continually get this errors:
Uncaught (in promise) ReferenceError: loadSound is not defined
Uncaught TypeError: Cannot read property 'play' of undefined
[enter image description here][1]
I’m using Visual Studio Code. I was trying to follow an coding train tutorial but it doesn’t seems to work. Sorry if my English is poor.
[1]: https://i.stack.imgur.com/NOoQn.jpg
The only thing I'm doing with the sound file is loadSound and .play(). I think maybe there are problems with my libraries and with index.html file. I'm new to p5 and js so if you need additional files I can post them afterwards.
<html lang="">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>p5.js example</title>
<style>
body {
padding: 0;
margin: 0;
}
</style>
<script src="../p5.js"></script>
<!-- <script src="../addons/p5.sound.js"></script> -->
<script src="https://cdn.jsdelivr.net/gh/bmoren/p5.collide2D/p5.collide2d.min.js"></script>
<script src="sketch.js"></script>
<script src="dio.js"></script>
</head>
<body>
<main>
</main>
</body>
</html>
</>
and this is part of the code in sketch.js
let sound;
function preload() {
sound=loadSound('song.mp3');
}
function setup() {![fku|690x76](upload://P2n8HRc7sGmvC5KBTNetHclIcT.jpeg)
createCanvas(1920, 500);
sound.play();
}
this is were the error comes from, i don’t get errors if I comment loadSound and sound.play. Thins mp3 is just a local file from my computer. And do you know a site from where I cant copy the url so I can play sounds(like how you can post an image on imgur an then link it into the code.