Commit cd3bb1f9 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

Finally works w/ chrome ?

parent c5cd764a
......@@ -2,7 +2,6 @@ var fileName;
function OracleRecorder(recordRTCOptions){
//Constructor of a recorder that requires RecordRTC and recordRTCOptions which are mono 44,1kHz by default
if(typeof recordRTCOptions == "undefined"){
recordRTCOptions = {type: 'audio',
bufferSize: 16384,
......@@ -11,9 +10,6 @@ function OracleRecorder(recordRTCOptions){
disableLogs: true};
}
this.recordRTCOptions = recordRTCOptions ;
this.startRecordingSuccess = function(){alert('zer');};
this.mikeError = function(){alert('zer');};
this.stopRecordingSuccess = function(audioURL, recBlob){alert('zer');};
this.recorder = false ;
this.stream = false ;
......@@ -32,54 +28,57 @@ function OracleRecorder(recordRTCOptions){
this.onMikeError = function(callback){
//a fuction called, when the microphone is not shared
self.mikeError = function(){
self.mikeError = function(err){
console.error(err);
callback() ;
self.recorder = false;
}
};
//actual processes
this.stopRecording = function(){
self.recorder.stopRecording(function(audioURL){
self.stopRecordingSuccess(audioURL, self.recorder.blob);
previewRec(audioURL);
fileName = 'oracle' + Math.round(Math.random() * 999999 + 1);
var fileReader = new FileReader();
fileReader.onload = function(event) {
var newBlob = new Blob([event.target.result], {type:"audio/ogg", endings:"native"});
//~ POST_using_XHR( newBlob );
PostBlob(newBlob, 'audio', fileName + ".ogg");
};
fileReader.readAsArrayBuffer(self.recorder.blob);
});
};
this.startRecording = function(){
if(self.recorder !== false){
//would have tested with self.stream,
//but the stream exists even if it is reset in mikeError
//there might be leftover streams in memory
self.startRecordingSuccess();
if(self.stream !== false){
//clearRecordedData, seems to lose the second parameter of getUserMedia
//so we start a brand new recorder with the same stream
self.recorder = RecordRTC(self.stream, self.recordRTCOptions);
self.recorder.startRecording();
self.startRecordingSuccess();
}
else{
self.stream = navigator.getUserMedia({video: false, audio: true},
navigator.getUserMedia(
{video: false, audio: true},
function(stream){
self.stream = stream;
if(window.isChrome){
stream = new window.MediaStream(stream.getAudioTracks());
self.stream = new window.MediaStream(stream.getAudioTracks());
}
if (stream.getAudioTracks().length === 0) {
console.log('you have no webcam nore mic available on your device');
}
else {
self.recorder = RecordRTC(stream, self.recordRTCOptions);
self.startRecordingSuccess();
self.recorder = RecordRTC(self.stream, self.recordRTCOptions);
self.recorder.startRecording();
self.startRecordingSuccess();
}
},
self.mikeError);
}
};
this.stopRecording = function(){
self.recorder.stopRecording(function(audioURL){
self.stopRecordingSuccess(audioURL, self.recorder.getBlob());
previewRec(audioURL);
fileName = 'oracle' + Math.round(Math.random() * 999999) + 1;
var fileReader = new FileReader();
fileReader.onload = function(event) {
var newBlob = new Blob([event.target.result], {type:"audio/ogg", endings:"native"});
//~ POST_using_XHR( newBlob );
PostBlob(newBlob, 'audio', fileName + ".ogg");
};
fileReader.readAsArrayBuffer(self.recorder.blob);
});
};
}
......
......@@ -3,7 +3,7 @@
function renders(minutes, seconds){
if(seconds == Math.floor(seconds)){
if (seconds < 10){
seconds = "0" + seconds;
seconds = "0" + seconds;
}
$('#countdown').html(minutes + ":" + seconds);
}
......@@ -21,22 +21,18 @@ function finChrono(){
}
//Bouton Rec qui clignote
function FaireClignoterImage (){
//Bouton Rec qui clignote
function FaireClignoterImage (){
$( "#rec1" ).fadeTo( "fast", 0, function() {
$( "#rec1" ).fadeTo( "fast" , 1, function() {
});
});
}
}
// au moment de l'appel à la méthode getUserMedia
var recorder, recordVideo;
var recButton;
var record = document.getElementById('record'); //Bouton d'enregistrement
var valid = document.getElementById('valid'); //Bouton pour valider
var restartRecord = document.getElementById('restart'); //Bouton pour recommencer l'enregistrement
......@@ -48,9 +44,7 @@ var container = document.getElementById('container');
var recordIsOn;
var audioStream;
var fileName;
var fileName;
$("#secondPage").hide();
$("#thirdPage").hide();
......@@ -64,7 +58,7 @@ var zeRecorder = new OracleRecorder() ;
function mikeError(){
var redirect = "index.php";
popUp(redirect);
}
......@@ -73,9 +67,9 @@ function startRecording(){
$("#secondPage").show("slow");
if(!monChrono.isRunning()){
monChrono.start();
}
$(document).ready(function(){
setInterval('FaireClignoterImage()',800);
}
$(document).ready(function(){
setInterval('FaireClignoterImage()',800);
});
}
......@@ -85,13 +79,10 @@ function stopRecording(url, bob){
$("#thirdPage").show("slow");
if(monChrono.isRunning()){
window.clearTimeout(monChrono.timer);
}
$("#form-cmd").hide("slow");
}
zeRecorder.onMikeError(mikeError);
zeRecorder.onStart(startRecording);
zeRecorder.onStop(stopRecording);
......
......@@ -16,7 +16,7 @@ $notif->readNotif();
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<!-- Adaptation au Bootstrap -->
<link rel="stylesheet" type="text/css" href="style/default.css/css/bootstrap.css">
......@@ -90,8 +90,8 @@ $notif->readNotif();
<?php
} else {
?>
<li ><a href="?mode=login" title="login">Se connecter</a></li>
<li ><a href="?mode=register" title="register">S'enregister</a></li>
<li><a href="?mode=login" title="login">Se connecter</a></li>
<li><a href="?mode=register" title="register">S'enregister</a></li>
<?php
}
?>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment