D
D
Deefs2017-07-06 22:20:52
JavaScript
Deefs, 2017-07-06 22:20:52

What is needed to group the code?

There is a recording function, the old method and the new one, in my own way I can’t understand how to insert it into the old recording from the new function, and stop play, let the
NEW FUNCTION remain

function Wo_startRecording() {
  recorder     &&    recorder.record();
  recording_time.removeClass('hidden');
  recorder     && recorder.exportWAV(function(blob){});
  recorder     && setTimeout(Wo_ShowRecordingTime,1000,recording_time);
  console.log('recording started');
}function Wo_stopRecording() {
  recorder     &&          recorder.stop();
  wo_timeout   && clearTimeout(wo_timeout);
  console.log('recording sotopped');
}function Wo_StopLocalStream(){
  localstream  && localstream.getTracks()[0].stop();
  localstream  = false;
  delete(recorder);
}

old function
audioRecorder.start=function(el){
  var audioRecorderElem=$(el).parents('.audioRecorder');
  var status=audioRecorderElem.attr('status');
  
  if(status=='record'){
    audioRecorder.stop(el);		
  }
  else if(status=='stop'){
    audioRecorder.play(el);	
  }
  else if(status=='pause'){
    audioRecorder.play(el);
  }
  else if(status=='play'){	
    audioRecorder.pause(el);
  }
  else{
    audioRecorder.record(el);
  }
};
audioRecorder.record=function(el){
  var audioRecorderElem=$(el).parents('.audioRecorder');
  try{
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
    navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;
    window.URL=window.URL||window.webkitURL;
    audioRecorder.context=new AudioContext;
  }catch(e){
    alert('Ваш браузер не поддерживает веб аудио!');
    return false;
  }
  navigator.getUserMedia({audio:1},function(stream){
    audioRecorder.localStream=stream;
    var input=audioRecorder.context.createMediaStreamSource(stream);
    audioRecorder.recorder=new Recorder(input);
    audioRecorder.recorder.record();
    audioRecorder.startRecordTime(el);
    audioRecorderElem.attr({'status':'record'});
  },function(err){});	
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Di Ma, 2017-07-06
@dimentimor

In the old version, audioRecorder is an object that has start, stop, ..., record methods.
And then you call its methods audioRecorder.recorder.record()and others.
And the new function is three "external" functions that call methods recorder.record(), etc. Why without audioRecorder before recorder.record is not clear. Unless these functions are called in the context of audioRecorder.
The new feature is not a replacement for the old one. It only creates an "interface" for working with audioRecorder. If you need something from it, then move it to the desired method of the audioRecorder object, or to the part where you use it (navigator.getUserMedia).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question