The microphone.start() function doesn't work in Android platform
The code is below, which works for Editor, but when deploy the project to android platform, it doesn't work anymore. The reason is microphone.start() function cannot start the recording correctly, so Microphone.IsRecording() always return false.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Help;
[RequireComponent( typeof( AudioSource ) )]
public class Mic : MonoBehaviour
{
private AudioSource audioSource = null;
private bool toPlayOrListen = false; // true to play, false to listen
public void Start()
{
Button button = GetComponent<Button>();
button.onClick.AddListener( delegate { OnClick(); } );
audioSource = GetComponent<AudioSource>();
audioSource.Stop();
}
void OnClick()
{
if( Microphone.IsRecording( null ) )
{
Microphone.End( null );
}
else if( audioSource.isPlaying )
{
audioSource.Stop();
}
else
{
if( toPlayOrListen )
{
audioSource.Play();
toPlayOrListen = false;
}
else
{
audioSource.clip = Microphone.Start( null, true, 10, 44100 );
toPlayOrListen = true;
}
}
}
}
This happens when upgrading from unity 4.6 to unity 5.2. I cost 2 days on this and haven't found a solution. Some similar link I found is below but doesn't help. Hope can find answer by asking a question here. Thanks in advance.
http://answers.unity3d.com/questions/1083977/updated-to-unity-52-and-suddenly-my-mic-input-scri.html
Your answer
Follow this Question
Related Questions
Fix sound delay 6 Answers
How can i select music from mobile that will play in unity audiosource? 0 Answers
Difficult Question - Multitrack recoring using microphone issue 0 Answers
Trying to use derive pitch and db from realtime microphone input 0 Answers
Trying to use derive pitch and db from realtime microphone input 0 Answers