Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone Audio object

I am aware of how to clone an object, but I'm wondering, how do I clone an audio object? Should I clone it differently than I would clone an object?

To "illustrate" what I mean:

var audio = new Audio("file.mp3");
var audio2 = $.extend({}, audio); // Clones `audio`

Is this the correct way to do this?

Reason why I'm asking this is that I want to be able to play the same sound multiple times simultaneously.

like image 614
MiJyn Avatar asked Jul 04 '13 04:07

MiJyn


People also ask

What is an audio object?

The combination of an audio buffer and its corresponding Metadata is referred to as an Audio Object. Audio Objects in the Bus Hierarchy differ from System Audio Objects sent to the endpoint.

Can JavaScript play WAV files?

Can JavaScript play WAV files? Method 2: JavaScript You may also load a sound file with JavaScript, with new Audio() . const audio = new Audio("freejazz. wav"); You may then play back the sound with the .

What is audio in JavaScript?

Audio() The Audio() constructor creates and returns a new HTMLAudioElement which can be either attached to a document for the user to interact with and/or listen to, or can be used offscreen to manage and play audio.


1 Answers

I had exactly the same predicament as originally raised. The following worked perfectly well for me :

var audio2 = audio.cloneNode();
like image 79
GedByrne Avatar answered Oct 30 '22 13:10

GedByrne