aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2024-01-05 01:53:30 +0100
committerpacien2024-01-05 01:53:30 +0100
commit0bf2af62baeb7912d6274bab4ff6d7f83dd692ee (patch)
tree49628f18a158081f492227cd8e3ba58b884eba7c
parentb562cf4a27f7e1f8f15d772da156b9b28a7f3119 (diff)
downloadechoclip-0bf2af62baeb7912d6274bab4ff6d7f83dd692ee.tar.gz
only play one audio clip at once
-rw-r--r--app.js25
1 files changed, 21 insertions, 4 deletions
diff --git a/app.js b/app.js
index 5095e20..6d2df4e 100644
--- a/app.js
+++ b/app.js
@@ -11,6 +11,25 @@ const autoplayCheckbox = document.querySelector("#autoplay");
11const clearBtn = document.querySelector("#clear"); 11const clearBtn = document.querySelector("#clear");
12const clips = document.querySelector("#clips"); 12const clips = document.querySelector("#clips");
13 13
14function stopPlayer(player) {
15 player.pause();
16 player.currentTime = 0;
17}
18
19function stopOtherPlayersExcept(player) {
20 document.querySelectorAll("audio").forEach(other => {
21 if (other != player)
22 stopPlayer(other);
23 });
24}
25
26function makeExclusive(player) {
27 player.addEventListener("play", _event => {
28 stopOtherPlayersExcept(player);
29 });
30 return player;
31}
32
14function wrapElement(wrapper, child) { 33function wrapElement(wrapper, child) {
15 const wrapperElement = document.createElement(wrapper); 34 const wrapperElement = document.createElement(wrapper);
16 wrapperElement.append(child); 35 wrapperElement.append(child);
@@ -41,7 +60,7 @@ function onGetDeviceSuccess(stream) {
41 recordingIndicator.classList.remove("active"); 60 recordingIndicator.classList.remove("active");
42 const blob = new Blob(recordingChunks, { type: mediaRecorder.mimeType }); 61 const blob = new Blob(recordingChunks, { type: mediaRecorder.mimeType });
43 recordingChunks = []; 62 recordingChunks = [];
44 const audioElement = audioElementForBlob(blob); 63 const audioElement = makeExclusive(audioElementForBlob(blob));
45 64
46 // TODO: record blob and list to local persistent storage 65 // TODO: record blob and list to local persistent storage
47 // TODO: "clear all" button to clear all clips 66 // TODO: "clear all" button to clear all clips
@@ -50,10 +69,8 @@ function onGetDeviceSuccess(stream) {
50 69
51 clips.prepend(wrapElement("li", audioElement)); 70 clips.prepend(wrapElement("li", audioElement));
52 71
53 if (autoplayCheckbox.checked) { 72 if (autoplayCheckbox.checked)
54 // TODO: stop playing any other clip
55 audioElement.play(); 73 audioElement.play();
56 }
57 }); 74 });
58 75
59 recordBtn.addEventListener("mousedown", _event => { 76 recordBtn.addEventListener("mousedown", _event => {