edit html pages focused on web audio players
parent
02ecbb32f2
commit
49c6c37a42
@ -0,0 +1,189 @@
|
||||
// set up basic variables for app
|
||||
|
||||
var record = document.querySelector('.record');
|
||||
var stop = document.querySelector('.stop');
|
||||
var soundClips = document.querySelector('.sound-clips');
|
||||
var canvas = document.querySelector('.visualizer');
|
||||
var mainSection = document.querySelector('.main-controls');
|
||||
|
||||
// disable stop button while not recording
|
||||
|
||||
stop.disabled = true;
|
||||
|
||||
// visualiser setup - create web audio api context and canvas
|
||||
|
||||
var audioCtx = new (window.AudioContext || webkitAudioContext)();
|
||||
var canvasCtx = canvas.getContext("2d");
|
||||
|
||||
//main block for doing the audio recording
|
||||
|
||||
if (navigator.mediaDevices.getUserMedia) {
|
||||
console.log('getUserMedia supported.');
|
||||
|
||||
var constraints = { audio: true };
|
||||
var chunks = [];
|
||||
|
||||
var onSuccess = function(stream) {
|
||||
var mediaRecorder = new MediaRecorder(stream);
|
||||
|
||||
visualize(stream);
|
||||
|
||||
record.onclick = function() {
|
||||
mediaRecorder.start();
|
||||
console.log(mediaRecorder.state);
|
||||
console.log("recorder started");
|
||||
record.style.background = "red";
|
||||
|
||||
stop.disabled = false;
|
||||
record.disabled = true;
|
||||
}
|
||||
|
||||
stop.onclick = function() {
|
||||
mediaRecorder.stop();
|
||||
console.log(mediaRecorder.state);
|
||||
console.log("recorder stopped");
|
||||
record.style.background = "";
|
||||
record.style.color = "";
|
||||
// mediaRecorder.requestData();
|
||||
|
||||
stop.disabled = true;
|
||||
record.disabled = false;
|
||||
}
|
||||
|
||||
mediaRecorder.onstop = function(e) {
|
||||
console.log("data available after MediaRecorder.stop() called.");
|
||||
|
||||
var clipName = prompt('Enter a name for your sound clip?','My unnamed clip');
|
||||
console.log(clipName);
|
||||
var clipContainer = document.createElement('article');
|
||||
var clipLabel = document.createElement('p');
|
||||
var audio = document.createElement('audio');
|
||||
var deleteButton = document.createElement('button');
|
||||
var saveButton = document.getElementById('save').href.toString();// document.getElementById("save").innerHTML;// = xhttp.responseText;; // you have to check how to get the data from your saveAudio() method
|
||||
window.alert(saveButton);
|
||||
|
||||
clipContainer.classList.add('clip');
|
||||
audio.setAttribute('controls', '');
|
||||
deleteButton.textContent = 'Delete';
|
||||
deleteButton.className = 'delete';
|
||||
saveButton.textContent = 'Save';
|
||||
saveButton.className = 'save';
|
||||
|
||||
if(clipName === null) {
|
||||
clipLabel.textContent = 'My unnamed clip';
|
||||
} else {
|
||||
clipLabel.textContent = clipName;
|
||||
}
|
||||
|
||||
clipContainer.appendChild(audio);
|
||||
clipContainer.appendChild(clipLabel);
|
||||
clipContainer.appendChild(deleteButton);
|
||||
soundClips.appendChild(clipContainer);
|
||||
clipContainer.appendChild(saveButton);
|
||||
|
||||
audio.controls = true;
|
||||
var blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' });
|
||||
chunks = [];
|
||||
var audioURL = window.URL.createObjectURL(blob);
|
||||
audio.src = audioURL;
|
||||
console.log("recorder stopped");
|
||||
|
||||
saveButton.onclick = function() {
|
||||
(window.XMLHttpRequest) ? clipName = new XMLHttpRequest() : (window.ActiveXObject) ? clipName = new ActiveXObject("Microsoft.XMLHTTP") : clipName = false;
|
||||
clipName.open("POST", audioURL, true);
|
||||
clipName.setRequestHeader("Content-Type", "multipart/form-data");
|
||||
|
||||
if(saveButton != null) //&& data != "")
|
||||
{
|
||||
clipName.send(saveButton);
|
||||
}}
|
||||
|
||||
deleteButton.onclick = function(e) {
|
||||
evtTgt = e.target;
|
||||
evtTgt.parentNode.parentNode.removeChild(evtTgt.parentNode);
|
||||
}
|
||||
|
||||
clipLabel.onclick = function() {
|
||||
var existingName = clipLabel.textContent;
|
||||
var newClipName = prompt('Enter a new name for your sound clip?');
|
||||
if(newClipName === null) {
|
||||
clipLabel.textContent = existingName;
|
||||
} else {
|
||||
clipLabel.textContent = newClipName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mediaRecorder.ondataavailable = function(e) {
|
||||
chunks.push(e.data);
|
||||
}
|
||||
}
|
||||
|
||||
var onError = function(err) {
|
||||
console.log('The following error occured: ' + err);
|
||||
}
|
||||
|
||||
navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
|
||||
|
||||
} else {
|
||||
console.log('getUserMedia not supported on your browser!');
|
||||
}
|
||||
|
||||
function visualize(stream) {
|
||||
var source = audioCtx.createMediaStreamSource(stream);
|
||||
|
||||
var analyser = audioCtx.createAnalyser();
|
||||
analyser.fftSize = 2048;
|
||||
var bufferLength = analyser.frequencyBinCount;
|
||||
var dataArray = new Uint8Array(bufferLength);
|
||||
|
||||
source.connect(analyser);
|
||||
//analyser.connect(audioCtx.destination);
|
||||
|
||||
draw()
|
||||
|
||||
function draw() {
|
||||
WIDTH = canvas.width
|
||||
HEIGHT = canvas.height;
|
||||
|
||||
requestAnimationFrame(draw);
|
||||
|
||||
analyser.getByteTimeDomainData(dataArray);
|
||||
|
||||
canvasCtx.fillStyle = 'rgb(200, 200, 200)';
|
||||
canvasCtx.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
canvasCtx.lineWidth = 2;
|
||||
canvasCtx.strokeStyle = 'rgb(0, 0, 0)';
|
||||
|
||||
canvasCtx.beginPath();
|
||||
|
||||
var sliceWidth = WIDTH * 1.0 / bufferLength;
|
||||
var x = 0;
|
||||
|
||||
|
||||
for(var i = 0; i < bufferLength; i++) {
|
||||
|
||||
var v = dataArray[i] / 128.0;
|
||||
var y = v * HEIGHT/2;
|
||||
|
||||
if(i === 0) {
|
||||
canvasCtx.moveTo(x, y);
|
||||
} else {
|
||||
canvasCtx.lineTo(x, y);
|
||||
}
|
||||
|
||||
x += sliceWidth;
|
||||
}
|
||||
|
||||
canvasCtx.lineTo(canvas.width, canvas.height/2);
|
||||
canvasCtx.stroke();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
window.onresize = function() {
|
||||
canvas.width = mainSection.offsetWidth;
|
||||
}
|
||||
|
||||
window.onresize();
|
@ -0,0 +1,321 @@
|
||||
body {font-family: "Old Standard TT"; font-size: 20px; line-height: 1.4; letter-spacing: 1px;}
|
||||
section {margin-bottom: 50px;margin-top: 20px;}
|
||||
a {font-weight: bold; text-decoration: none; }
|
||||
h2 {
|
||||
text-align: center;
|
||||
letter-spacing: 4px;
|
||||
font-size: 28px;}
|
||||
table, th, td {vertical-align: top; border-collapse: separate; padding: 6px;}
|
||||
button {width: 100px;}
|
||||
.short-description{
|
||||
margin-left: 40%;
|
||||
margin-right: 40%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.internet {font-weight: regular; font-size: 18px; text-decoration: none; }
|
||||
.list {
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
list-style: none;
|
||||
border-top: 1px solid #47505e;
|
||||
}
|
||||
.description {
|
||||
font-size: 12px;
|
||||
float: right;
|
||||
font-weight: normal !important;
|
||||
}
|
||||
/* .mini-player {
|
||||
background-size: 100% 100%;
|
||||
background-image: url(/project/images/player.png);
|
||||
cursor: pointer;
|
||||
}*/
|
||||
.audio-mini {
|
||||
width: 50px;
|
||||
}
|
||||
.dropbtn {
|
||||
font-family: "Old Standard TT";
|
||||
font-weight: bold;
|
||||
font-size: 24px;
|
||||
color: black;
|
||||
padding: 16px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dropbtn:hover, .dropbtn:focus {
|
||||
background-color: pink;
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dropdown-content {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background-color: white;
|
||||
min-width: 1900px;
|
||||
overflow: auto;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.dropdown-content a {
|
||||
color: black;
|
||||
padding: 12px 16px;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.dropdown a:hover {background-color: none;}
|
||||
|
||||
.show {display: block;}
|
||||
|
||||
|
||||
|
||||
/*style internet sources*/
|
||||
.dropbtn2 {
|
||||
font-family: "Old Standard TT";
|
||||
font-weight: regular;
|
||||
font-size: 24px;
|
||||
color: black;
|
||||
padding: 16px;
|
||||
cursor: pointer;
|
||||
background-color: rgba(255, 255, 255, 0.9);
|
||||
border:1px;
|
||||
border-style:solid;
|
||||
border-color:black;
|
||||
}
|
||||
|
||||
.dropbtn2:hover, .dropbtn2:focus {
|
||||
background-color: pink;
|
||||
}
|
||||
|
||||
.dropdown2 {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dropdown-content2 {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background-color: white;
|
||||
min-width: 1000px;
|
||||
overflow: auto;
|
||||
z-index: 1;
|
||||
border:1px;
|
||||
border-style:solid;
|
||||
border-color:black;
|
||||
}
|
||||
|
||||
.dropdown-content2 a {
|
||||
color: black;
|
||||
padding: 12px 16px;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.dropdown2 a:hover {background-color: none;}
|
||||
|
||||
.show2 {display: block;}
|
||||
|
||||
/*style list of podcasts*/
|
||||
.dropbtn3 {
|
||||
font-family: "Old Standard TT";
|
||||
font-weight: regular;
|
||||
font-size: 24px;
|
||||
color: black;
|
||||
padding: 16px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dropbtn3:hover, .dropbtn3:focus {
|
||||
background-color: pink;
|
||||
}
|
||||
|
||||
.dropdown3 {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dropdown-content3 {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background-color: white;
|
||||
min-width: 1000px;
|
||||
overflow: auto;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.dropdown-content3 a {
|
||||
color: black;
|
||||
padding: 12px 16px;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.dropdown3 a:hover {background-color: none;}
|
||||
|
||||
.show3 {display: block;}
|
||||
|
||||
|
||||
|
||||
/* Make the clips use as much space as possible, and
|
||||
* also show a scrollbar when there are too many clips to show
|
||||
* in the available space */
|
||||
.sound-clips {
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
/*section, article {
|
||||
display: block;
|
||||
}*/
|
||||
|
||||
.clip {
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
/*audio {
|
||||
width: 100%;
|
||||
display: block;
|
||||
margin: 1rem auto 0.5rem;
|
||||
}*/
|
||||
|
||||
.clip p {
|
||||
display: inline-block;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.clip button {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
button.delete {
|
||||
background: #f00;
|
||||
padding: 0.5rem 0.75rem;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* Checkbox hack to control information box display */
|
||||
|
||||
/*label {
|
||||
font-size: 3rem;
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 3px;
|
||||
z-index: 5;
|
||||
cursor: pointer;
|
||||
}*/
|
||||
|
||||
input[type=checkbox] {
|
||||
position: absolute;
|
||||
top: -100px;
|
||||
}
|
||||
|
||||
/*aside {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
transform: translateX(100%);
|
||||
transition: 0.3s all ease-out;
|
||||
background-color: #efefef;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
aside p {
|
||||
font-size: 1.2rem;
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
|
||||
aside a {
|
||||
color: #666;
|
||||
}
|
||||
*/
|
||||
/* Toggled State of information box */
|
||||
input[type=checkbox]:checked ~ aside {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
/* Cursor when clip name is clicked over */
|
||||
|
||||
.clip p {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Adjustments for wider screens */
|
||||
@media all and (min-width: 800px) {
|
||||
/* Don't take all the space as readability is lost when line length
|
||||
goes past a certain size */
|
||||
/*.wrapper {
|
||||
width: 90%;
|
||||
max-width: 1000px;
|
||||
margin: 0 auto;
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
/*hover of images and transcriptions style*/
|
||||
.tooltip-wrap {
|
||||
position: relative;
|
||||
}
|
||||
.tooltip-wrap .tooltip-content {
|
||||
display: none;
|
||||
position: absolute;
|
||||
/*top: 20%;*/
|
||||
bottom: 100%;
|
||||
left: 2%;
|
||||
/*right: 100%;*/
|
||||
padding: .5em;
|
||||
background-color: rgba(255, 255, 255, 0.9) ;
|
||||
border:1px;
|
||||
border-style:solid;
|
||||
border-color:black;
|
||||
|
||||
}
|
||||
.tooltip-wrap:hover .tooltip-content {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/*transcript wrapper,text following audio style*/
|
||||
|
||||
#transcriptWrapper {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#transcript > div {
|
||||
transition: all .8s ease;
|
||||
list-style-type: disc;
|
||||
}
|
||||
.speaking {
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
#transcriptWrapper3 {
|
||||
overflow: hidden;
|
||||
}
|
||||
#transcript3 > div {
|
||||
transition: all .8s ease;
|
||||
list-style-type: disc;
|
||||
}
|
||||
.speaking3 {
|
||||
font-weight:bold
|
||||
}
|
||||
|
||||
/*one image next to the other*/
|
||||
.column {
|
||||
float: left;
|
||||
width: 50%;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
/* Clear floats after image containers */
|
||||
.row::after {
|
||||
content: "";
|
||||
clear: both;
|
||||
display: table;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
$save_folder = dirname(__FILE__) ."/js";
|
||||
if(! file_exists($save_folder)) {
|
||||
if(! mkdir($save_folder)) {
|
||||
die("failed to create save folder $save_folder");
|
||||
}
|
||||
}
|
||||
|
||||
$key = 'filename';
|
||||
$tmp_name = $_FILES["audiofile"]["tmp_name"];
|
||||
$upload_name = $_FILES["audiofile"]["name"];
|
||||
$type = $_FILES["audiofile"]["type"];
|
||||
$filename = "$save_folder/$upload_name";
|
||||
$saved = 0;
|
||||
if(($type == 'audio/x-wav' || $type == 'application/octet-stream') && preg_match('/^[a-zA-Z0-9_\-]+\.wav$/', $upload_name) ) {
|
||||
|
||||
$saved = move_uploaded_file($tmp_name, $filename) ? 1 : 0;
|
||||
}
|
||||
|
||||
//name is needed to send in the php file
|
||||
|
||||
?>
|
Loading…
Reference in New Issue