forked from zzarcon/microm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
103 lines (84 loc) · 2.11 KB
/
example.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
(function() {
window.onload = ready;
window.microm = null;
var status, currentTime, duration;
function ready() {
window.microm = new Microm();
status = $('#status span');
currentTime = $('#current-time span');
duration = $('#duration span');
// Microm events
microm.on('timeupdate', updateCurrentTime);
microm.on('loadedmetadata', onLoaded);
microm.on('play', onPlayEvent);
microm.on('pause', onPauseEvent);
microm.on('ended', onEndEvent);
// DOM element events
click('#record', onRecord);
click('#play', onPlay);
click('#pause', onPause);
click('#stop', onStop);
click('#get-mp3', onGetMp3);
click('#get-wav', onGetWav);
click('#get-base64', onGetBase64);
click('#download', onDownload);
}
function onLoaded(time) {
duration.innerHTML = time;
}
function updateCurrentTime(time) {
currentTime.innerHTML = time;
}
function onPlayEvent() {
status.innerHTML = 'Playing';
}
function onPauseEvent(currentTime) {
status.innerHTML = 'Paused';
}
function onEndEvent() {
status.innerHTML = 'Ended';
}
function onRecord() {
microm.record().then(function() {
status.innerHTML = 'Recording';
}).catch(function(error) {
console.log('error recording', error);
})
}
function onPlay() {
console.log('onPlay');
microm.play();
}
function onPause() {
console.log('onPause');
microm.pause();
}
function onStop() {
microm.stop().then(function(mp3) {
status.innerHTML = 'Paused';
});
}
function onGetMp3() {
microm.getMp3().then(function(mp3) {
console.log('onGetMp3', mp3);
});
}
function onGetWav() {
console.log('onGetWav');
microm.getWav();
}
function onGetBase64() {
microm.getBase64().then(function(base64string) {
console.log(base64string);
});
}
function onDownload() {
microm.download('microm');
}
function $(selector) {
return document.querySelector(selector);
}
function click(selector, callback) {
$(selector).addEventListener('click', callback);
}
})();