10 examples of 'play sound javascript' in JavaScript

Every line of 'play sound javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
80play() {
81 var audio = Sound.getAudio(this.options.src);
82 audio.id = this.id;
83 audio.play();
84 return this;
85}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

68function play(audioId) {
69 // TODO: Attach an invisible element for this instead
70 // which listens?
71 var audio = document.getElementById(audioId);
72 if (audio) {
73 audio.load();
74 audio.play();
75 }
76}
109play() {
110 // start music
111 if (this.html5Audio.paused && this.html5Audio.duration) {
112 this.html5Audio.play();
113 // remove play, add pause
114 this.$pButton.removeClass('play').addClass('pause');
115 } else { // pause music
116 this.html5Audio.pause();
117 // remove pause, add play
118 this.$pButton.removeClass('pause').addClass('play');
119 }
120}
16play() {
17 this._jsNode = this._context.createScriptProcessor(this.streamSize, 1, 2);
18 this._jsNode.onaudioprocess = (e) => {
19 this.processor.process(this.streamSize);
20 e.outputBuffer.getChannelData(0).set(this.processor.streams[0]);
21 e.outputBuffer.getChannelData(1).set(this.processor.streams[1]);
22 };
23 this._jsNode.connect(this._context.destination);
24
25 this._bufSrc = this._context.createBufferSource();
26 this._bufSrc.start(0);
27 this._bufSrc.connect(this._jsNode);
28}
8public play(id:string){
9 var sound:Sound = LoaderManager.getInstance().get(id),
10 audioObject:Sound = null;
11
12 if(!sound || !sound.canPlay()) {
13 return;
14 }
15
16 audioObject = sound;
17 this._playOnlyOneSimultaneously(audioObject);
18}
22function play (sound) {
23 var i = sounds.indexOf(sound);
24 var curr = currents[i];
25 buffers[i][curr].play();
26 currents[i] = curr+1<BUFFERS ? curr+1 : 0;
27}
189function playStream(streamName) {
190 playFirstSound();
191 var stream = new Stream();
192 stream.name = document.getElementById("streamId").value;
193 stream.hasVideo = true;
194 stream.mediaProvider = MediaProvider.WSPlayer;
195 this.stream = f.playStream(stream);
196}
147function playAudio() {
148 ARRAY_BILLS.forEach((bill, i) => {
149 setTimeout(() => {
150 animateBill(bill, i);
151
152 THREESTUFF.scene.add(bill);
153 }, 230*i)
154 })
155
156
157 const button = document.getElementById('buttonPlayAudio');
158
159 button.style.display = 'none';
160 // INIT WEB AUDIO
161 try {
162 window.AudioContext = window.AudioContext || window.webkitAudioContext;
163 contextAudio = new AudioContext();
164 } catch (e) {
165 console.log('Web Audio API is not supported in this browser.');
166 }
167 if (contextAudio) {
168 const bufferLoader = new BufferLoader(
169 contextAudio,
170 ['./audio/bella_ciao.mp3'],
171 (bufferList) => {
172 const around = contextAudio.createBufferSource();
173
174 around.buffer = bufferList[0];
175
176 around.connect(contextAudio.destination);
177 around.loop = true;
178 around.start();
179 }
180 );
181 bufferLoader.load();
182 }
183}
55function play() {
56 if (isPlaying) {
57 csound.Event("i-1 0 -1");
58 csound.Event("i-2 0 -1");
59 wavesurfer.stop();
60 document.getElementById("playPauseButton").src = "/static/images/play_colored.png";
61 } else {
62 csound.Event("i1 0 -1");
63 csound.Event("i2 0 -1");
64 wavesurfer.play();
65 document.getElementById("playPauseButton").src = "/static/images/pause_colored.png";
66 }
67 isPlaying = !isPlaying
68}
17function play(callback) {
18 sound.node[0].play();
19
20 if(typeof callback === "function") {
21 sound.node.end(callback);
22 }
23}

Related snippets