- Home /
Question by
wohoa · May 17, 2012 at 03:26 AM ·
androidmicrophonerecordunity3.5
A bug about record and play sound at same time
Unity 3.5 can not record and play sound at same time on android. When call microphone.start(...), all audiosource will work incorrect, android will report "obtainBuffer() track 0x307030 disabled, restarting", when call microphone.end(), all audiosource will work good. PC version has not this problem. We test android 2.3 and 3.0, all have this problem. Not use untiy, use java direct call android API to record and play sound at same time, it work good. Is unity bug? or we do something wrong?
thank
Comment
I have the same problem, here is some sample code (plays back in near real time on PC version, but waits until recording is finished on Android version.
using UnityEngine;
using System.Collections;
public class $$anonymous$$icrophoneSource : $$anonymous$$onoBehaviour {
string m_micSelected = "";
AudioClip m_clip;
IEnumerator RecordPlayAnalyse() {
// record a two-second clip
m_clip = $$anonymous$$icrophone.Start(m_micSelected, false, 2, AudioSettings.outputSampleRate);
yield return null;
while ($$anonymous$$icrophone.GetPosition(m_micSelected) < 100)
{
yield return null;
}
// play the clip back
audio.clip = m_clip;
audio.Play();
}
void Present$$anonymous$$icChoice() {
foreach(string device in $$anonymous$$icrophone.devices) {
if (GUILayout.Button("Start recording with " + device)) {
m_micSelected = device;
StartCoroutine(RecordPlayAnalyse());
}
}
GUILayout.Label("End");
}
void OnGUI() {
if (m_micSelected == "" || (!audio.isPlaying && !$$anonymous$$icrophone.IsRecording(m_micSelected))) {
Present$$anonymous$$icChoice();
}
else {
if ($$anonymous$$icrophone.IsRecording(m_micSelected)) {
GUILayout.Label("Recording");
}
else if (audio.isPlaying) {
GUILayout.Label("Playing");
}
}
}
}