Exercise: Fix questions type audio - refs BT21319

pull/5037/head
christian 2 years ago
parent 1c71b47eab
commit b7519ba638
  1. 39
      public/main/inc/lib/javascript/record_audio/record_audio.js

@ -1,12 +1,12 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
window.RecordAudio = (function () { window.RecordAudio = (function () {
function startTimer() { function startTimer(parentWrap) {
$("#timer").show(); parentWrap.find("#timer").show();
var timerData = { var timerData = {
hour: parseInt($("#hour").text()), hour: parseInt(parentWrap.find("#hour").text()),
minute: parseInt($("#minute").text()), minute: parseInt(parentWrap.find("#minute").text()),
second: parseInt($("#second").text()) second: parseInt(parentWrap.find("#second").text())
}; };
clearInterval(window.timerInterval); clearInterval(window.timerInterval);
@ -24,17 +24,17 @@ window.RecordAudio = (function () {
timerData.hour++; timerData.hour++;
} }
$("#hour").text(timerData.hour < 10 ? '0' + timerData.hour : timerData.hour); parentWrap.find("#hour").text(timerData.hour < 10 ? '0' + timerData.hour : timerData.hour);
$("#minute").text(timerData.minute < 10 ? '0' + timerData.minute : timerData.minute); parentWrap.find("#minute").text(timerData.minute < 10 ? '0' + timerData.minute : timerData.minute);
$("#second").text(timerData.second < 10 ? '0' + timerData.second : timerData.second); parentWrap.find("#second").text(timerData.second < 10 ? '0' + timerData.second : timerData.second);
}, 1000); }, 1000);
} }
function stopTimer() { function stopTimer(parentWrap) {
$("#hour").text('00'); parentWrap.find("#hour").text('00');
$("#minute").text('00'); parentWrap.find("#minute").text('00');
$("#second").text('00'); parentWrap.find("#second").text('00');
$("#timer").hide(); parentWrap.find("#timer").hide();
} }
function pauseTimer() { function pauseTimer() {
@ -101,9 +101,10 @@ window.RecordAudio = (function () {
} }
btnStart.on('click', function () { btnStart.on('click', function () {
var parentWrap = $(this).parent();
function successCallback(stream) { function successCallback(stream) {
stopTimer(); stopTimer(parentWrap);
startTimer(); startTimer(parentWrap);
recordRTC = RecordRTC(stream, { recordRTC = RecordRTC(stream, {
recorderType: RecordRTC.StereoAudioRecorder, recorderType: RecordRTC.StereoAudioRecorder,
type: 'audio', type: 'audio',
@ -122,7 +123,7 @@ window.RecordAudio = (function () {
} }
function errorCallback(error) { function errorCallback(error) {
stopTimer(); stopTimer(parentWrap);
alert(error); alert(error);
} }
@ -157,7 +158,8 @@ window.RecordAudio = (function () {
btnPause.prop('disabled', false).removeClass('hidden'); btnPause.prop('disabled', false).removeClass('hidden');
btnStop.prop('disabled', false).removeClass('hidden'); btnStop.prop('disabled', false).removeClass('hidden');
recordRTC.resumeRecording(); recordRTC.resumeRecording();
startTimer(); var parentWrap = $(this).parent();
startTimer(parentWrap);
}); });
btnStop.on('click', function () { btnStop.on('click', function () {
@ -165,7 +167,8 @@ window.RecordAudio = (function () {
return; return;
} }
stopTimer(); var parentWrap = $(this).parent();
stopTimer(parentWrap);
recordRTC.stopRecording(function (audioURL) { recordRTC.stopRecording(function (audioURL) {
btnStart.prop('disabled', false).removeClass('hidden'); btnStart.prop('disabled', false).removeClass('hidden');
btnPause.prop('disabled', true).addClass('hidden'); btnPause.prop('disabled', true).addClass('hidden');

Loading…
Cancel
Save