0
var actx = new AudioContext();
var src = "https://dl.dropboxusercontent.com/s/knpo4d2yooe2u4h/tank_driven.wav", 
audioData, srcNode;

fetch(src, {mode: "cors"}).then(function(resp) {return resp.arrayBuffer()}).then(decode);

when src has URL with a full path it works and play. But I need to be able to play this file placed near my webapp. When I write:

var src = "/sounds/tank_driven.wav", 

No sound at all, and a TypeError: Failed to fetch at audioplayer.js:5:1

how to fix it and make it able to play local audio files?

ps. Using any webserver is not considered, i need to make it work on a simple html5 page that will be opened from a flash drive.

peak
  • 105,803
  • 17
  • 152
  • 177
Andrew Bro
  • 471
  • 2
  • 6
  • 20
  • "Using any webserver is not considered, i need to make it work on a simple html5 page that will be opened from a flash drive" — Then your URL is wrong (because you're pointing at the root of the file system) **and** you won't have permission via CORS. Both of these would have been easier to determine if you'd done basic debugging and (a) looked at the Network tab to see what URL was being requested and (b) quoted the rest of the error messages displayed on the browser console. – Quentin Nov 12 '22 at 12:04

1 Answers1

-1

Try:

var src = "./sounds/tank_driven.wav", 
Henryc17
  • 851
  • 4
  • 16