-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
58 lines (50 loc) · 1.86 KB
/
main.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var startTime, endTime;
function _start() {
startTime = new Date();
}
function _end(name) {
endTime = new Date();
var diff = endTime - startTime;
var msg = 'interval ' + name + ' takes: ' + (endTime - startTime) + ' ms';
if(diff > 1000){
console.log('%c' + msg, 'color: #ff0000');
} else {
console.log(msg);
}
}
$(document).ready(function() {
var audio_file = document.querySelector('#mvaudio__input_file');
var mediaElement = document.querySelector('#mvaudio__audio-element');
audio_file.onchange = function() {
document.querySelector('#mvaudio__loader').style.display = 'block';
var file = this.files[0];
var reader = new FileReader();
reader.onload = function() {
var editor = new AudioEditor(mediaElement.duration);
editor.on('change_duration', function(data){
console.log('on change duration');
console.log(data);
});
editor.on('save', function(data){
console.log('on save');
console.log(data);
});
// Peaks.js use the same decodeAudioData function which is expensive
/*var context = new(window.AudioContext || window.webkitAudioContext)();
context.decodeAudioData(reader.result, function(buffer) {
_end('decodeAudioData');
//buffer: AudioBuffer
console.log(buffer);
var editor = new AudioEditor(buffer);
editor.on('save', function(data){
console.log('on save');
console.log(data);
});
});*/
};
reader.readAsArrayBuffer(file);
var blob = window.URL || window.webkitURL;
var fileURL = blob.createObjectURL(file);
mediaElement.src = fileURL;
};
});