Hi,
My app reported the following exception:
java.lang.IllegalStateException: stop() called on uninitialized AudioTrack.
at android.media.AudioTrack.stop(AudioTrack.java:780)
at org.fmod.FMODAudioDevice.run(Unknown Source)
does anyone know, what might be the cause of the exception:
My code to play and stop sound is as below:
public static function PlayAudioClip (audioClip : AudioClip, position : Vector3)
{
var gameObject = new GameObject ("OneShotAudio");
gameObject.transform.position = position;
gameObject.tag = "SoundGameObject";
var source : AudioSource = gameObject.AddComponent (AudioSource);
source.clip = audioClip;
source.Play ();
Destroy (gameObject, audioClip.length);
return source;
}
public static function PlaySound(audioClip:AudioClip)
{
if(audioClip==sBonusTimeBGM)
{
PlayAudioClip(audioClip, sPlaySoundPosition);
}
if(GameStat.sSoundEnabled==0)
{
return;
}
if(!sHasWindowFocus)
{
return;
}
PlayAudioClip(audioClip, sPlaySoundPosition);
mSilentTime = 0;
}
function EnableSound()
{
GameStat.sSoundEnabled = 1;
}
function StopAllSound()
{
try{
var allPrefab : GameObject[] = GameObject.FindGameObjectsWithTag("SoundGameObject");
for (var aPrefab : GameObject in allPrefab) {
Destroy(aPrefab);
}
}catch(e){
Debug.Log("StopAllSound(), exception captured");
}
}