-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from bnidevs/starwarswii
added sound assignment
- Loading branch information
Showing
5 changed files
with
231 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,30 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<head> | ||
<script src="https://code.jquery.com/jquery-3.4.1.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.1.3/howler.min.js"></script> | ||
|
||
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> | ||
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/howler/2.1.3/howler.min.js"></script> | ||
|
||
<link href="style.css" rel="stylesheet"> | ||
<script type="module" src="js/index.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
||
<div id="root"> | ||
<div id="ctn"> | ||
|
||
<div id="recordplay-btn-div"> | ||
<button id="record-btn"><i id="micIcon" class="fa fa-microphone"></i></button> | ||
<button id="play-btn"><i id="playIcon" class="fa fa-play"></i></button> | ||
</div> | ||
|
||
<!-- filled by jquery --> | ||
<table id="grid" /> | ||
|
||
</div> | ||
|
||
<div id="recordPlay"> | ||
<button id="recordButton"><i id="recordIcon" class="fa fa-microphone"></i></button> | ||
<button id="playButton"><i id="playIcon" class="fa fa-play"></i></button> | ||
</div> | ||
|
||
<input type="file" id="fileInput"> | ||
|
||
<input id="fileInput" type="file"> | ||
|
||
<span id="status" style="margin-right: 15px;">no sound</span> | ||
<button id="pendingPlay">play</button> | ||
<button id="assign">assign</button> | ||
|
||
<!-- filled by jquery --> | ||
<table id="grid" /> | ||
|
||
</body> | ||
</html> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//sets up the audio for recording and returns start and stop functions | ||
const initRecorder = () => new Promise(async resolve => { | ||
|
||
const stream = await navigator.mediaDevices.getUserMedia({audio: true}); | ||
const mediaRecorder = new MediaRecorder(stream); | ||
console.log(mediaRecorder.mimeType); | ||
|
||
const audioChunks = []; | ||
|
||
mediaRecorder.addEventListener("dataavailable", event => { | ||
audioChunks.push(event.data); | ||
}); | ||
|
||
//start recording | ||
const start = () => mediaRecorder.start(); | ||
|
||
//stop recording and return audio | ||
const stop = () => new Promise(resolve => { | ||
|
||
mediaRecorder.addEventListener("stop", () => { | ||
|
||
const audioBlob = new Blob(audioChunks); | ||
const audioUrl = URL.createObjectURL(audioBlob); | ||
|
||
const audio = new Howl({ | ||
src: audioUrl, | ||
format: "webm" | ||
}); | ||
|
||
//return the sound | ||
resolve(audio); | ||
}); | ||
|
||
mediaRecorder.stop(); | ||
}); | ||
|
||
//return the start and stop functions | ||
//this is the same as {start: start, stop: stop} | ||
resolve({start, stop}); | ||
}); | ||
|
||
let recorder = null; | ||
|
||
export async function start() { | ||
recorder = await initRecorder(); | ||
recorder.start(); | ||
} | ||
|
||
export async function stop() { | ||
let audio = await recorder.stop(); | ||
recorder = null; | ||
return audio; | ||
} | ||
|
||
export function isRecording() { | ||
return recorder !== null; | ||
} |
Oops, something went wrong.