how do I read AudioClip.loadState?

Here’s my code:

if (player.clip.loadState == AudioDataLoadState.Failed) { 
 Debug.Log("clip at URI does not exist");
}

Unity produces this error:

Type UnityEngine.AudioClip' does not contain a definition for loadState’ and no extension method loadState' of type UnityEngine.AudioClip’ could be found (are you missing a using directive or an assembly reference?)

I’ve looked through the documentation and searched for similar questions and forum threads, but I cannot find out if I need more than the using UnityEngine; namespace. It seems like this should be simple, and I really hope I’m just overlooking something small.

I’m using Unity 4.6.4f1, Windows 7 Pro SP1. Any help is greatly appreciated.

JMc

AudioClip.loadState was added in 5.0, so it is not possible to use it in 4.6.

In case it helps, in 4.6 it is possible to use AudioClip.isReadyToPlay, although that doesn’t distinguish between “loading” and “failed” states.

For anyone that still has problems with AudioClip.isReadyToPlay being obsolete, here’s how to update from the old “isReadyToPlay”.
It doesn’t require any additional using definitions, just change all AudioClip.isReadyToPlay into AudioClip.loadState.Equals("Loaded").


For example, for an array of sounds:

//definitions
public AudioClip[] sounds;
public int n;

//Check to see if sound number "n" is loaded (ready to play) and if so, play sound number "n".
    if (sounds[n].loadState.Equals("Loaded"))
    {
    audioSource.PlayOneShot(sounds[n]);
    }

There can be 4 different states of an audioclip, “Unloaded”, “Loading”, “Loaded” and “Failed”.