instanciate an audio file object

Issue

This Content is from Stack Overflow. Question asked by Chris Toulon

instead of this code which works fine

<input type="file" id="my_file">

<script>
var file = document.getElementById('my_file').files[0],
reader = new FileReader();
reader.onload = function(e) {
//...
}
reader.readAsArrayBuffer(file);
</script>

I would like to instantiate an object to play an mp3 audio file

<script>
// for example the following or whatever to pass a file object to readAsArrayBuffer()
var file = new File("./fichier.mp3");       // don't work

reader = new FileReader();
reader.onload = function(e) {
//...
}
reader.readAsArrayBuffer(file);
</script>

thanks for your answers



Solution

Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?