Question by
bf_glue · Sep 26, 2018 at 06:38 PM ·
microphone
Microphone start recording with lag
I'm trying to record a sample from the microphone by this code
private bool recording = false;
void Start () {
Button btnREC = recordButton.GetComponent<Button>();
btnREC.onClick.AddListener(RecordToggle);
Button btnPlay = playButton.GetComponent<Button>();
btnPlay.onClick.AddListener(PlayAudioSource);
}
public void RecordToggle(){
if (recording) {
StopRecording ();
} else {
StartCoroutine("StartRecording");
}
}
IEnumerator StartRecording(){
source.clip = Microphone.Start(null, true, 10, 44100);
while(!(Microphone.GetPosition(null) > 0)){
yield return true;
}
recording = true;
recIndicator.SetActive (true);
StopCoroutine("StartRecording");
}
In the editor, all is fine but in the build, I have a lag between button click and recording start (my recIndicator also shown after a lag). How can I fix this and start recording immediately after the button click?,
Comment