-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayApp.js
More file actions
28 lines (24 loc) · 725 Bytes
/
Copy pathPlayApp.js
File metadata and controls
28 lines (24 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Create audio context
var audioContext = new (window.AudioContext || window.webkitAudioContext)();
//specify gain to control the output level
var gainControl = audioContext.createGain();
//Define play function on input change events
function PrepareAndPlay() {
soundFile.onchange = function() {
audio.pause();
audio.load();
audio.src = URL.createObjectURL(this.files[0]);
audio.play();
}
audio.onloadedmetadata = function() {
var elementSource = audioContext.createMediaElementSource(this);
elementSource.connect(gainControl);
audio.play();
}
};
//Couple gain to have effect on output
function ConnectObjects() {
gainControl.connect(audioContext.destination);
};
PrepareAndPlay();
ConnectObjects();