10 examples of 'javascript play mp3' in JavaScript

Every line of 'javascript play mp3' 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
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}
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

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}
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}
72function playURL(url)
73{
74 initPlayer();
75
76 theWMPCore.SetURL(url);
77
78 var tryAgain = false;
79 try {
80 playPlayer();
81 } catch(e) {
82 tryAgain = true;
83 dump(e + "\n");
84 }
85
86 if(tryAgain)
87 {
88 try {
89 playPlayer();
90 } catch(e) {
91 tryAgain = true;
92 dump(e + "\n");
93 }
94 }
95
96 setPlayerVolume(lastVolume);
97}
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}
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}
63async function play(filename) {
64 if (!filename) {
65 return;
66 }
67
68 // We use AudioContext instead of Audio since it works more
69 // reliably in different browsers (Chrome, FF, Brave).
70 let context = new AudioContext();
71
72 let source = context.createBufferSource();
73 source.connect(context.destination);
74 source.buffer = await new Promise(async (resolve, reject) => {
75 let content = await Chrome.files.readBinary(filename);
76 context.decodeAudioData(content, buffer => resolve(buffer), error => reject(error));
77 });
78
79 await new Promise(resolve => {
80 // Cleanup audio context after sound plays.
81 source.onended = () => {
82 context.close();
83 resolve();
84 }
85 source.start();
86 });
87}
72function play(){
73 if(!stopped){
74
75 if(currentNote == 0 && currentChord == 0 && currentScale == 0)
76 console.log(":::::::\n:::::::\n:::::::\nNEW ROUND");
77 if(currentNote == 0 && currentChord == 0)
78 console.log(":::::::\nSCALE: " + scales[currentScale].scale);
79 if(currentNote == 0)
80 console.log("CHORD: " + scales[currentScale].chords[currentChord]);
81 console.log("NOTE: " + scales[currentScale].notes[currentNote]);
82
83 var pause = 150;
84
85 var note = getNote('sawtooth',scales[currentScale].notes[currentNote],0.2,0.1,0.9,0.4,0.1);
86 note.play();
87
88 if(currentNote == 0){
89 var chord = getChord(scales[currentScale].chords[currentChord],0.1);
90 chord.play();
91 }
92
93 currentNote++;
94 currentNote%=scales[currentScale].notes.length;
95
96 if(currentNote == 0){
97 pause = 1000;
98
99 currentChord++;
100 currentChord%=scales[currentScale].chords.length;
101
102 if(currentChord == 0){
103 pause = 2000;
104
105 currentScale++;
106 currentScale%=scales.length;
107
108 if(currentScale == 0){
109 pause = 4000;
110 }
111
112 }
113 }
114 setTimeout(play,pause);
115 }
116}
43async play() {
44 if (!this.player) throw "No! Something went wrong, try again.";
45 else if (!this.queue.length) throw "Can't play songs from an empty queue.";
46
47 const [song] = this.queue;
48 this.player.play(song.track);
49 if (this.client.config.main.patreon) this.player.volume(this.volume);
50 this.playing = true;
51 return this.player;
52}
23function play(url) {
24 video.poster = "./img/transparent-1px.png";
25 video.style.background = "center transparent url('./img/spinner.gif') no-repeat";
26 video.src = url;
27 video.play();
28}

Related snippets