Exemple #1
0
    IEnumerator LoadFileByNAudio(string filePath, NAudioPlayer.SupportFormatType type)
    {
        if (type != NAudioPlayer.SupportFormatType.NULL)
        {
            WWW www = new WWW("file://" + filePath);
            yield return(www);

            if (null != www && null != www.bytes && www.bytes.Length > 0)
            {
                AudioClip clip = NAudioPlayer.GetClipByType(www.bytes, type);
                if (null != clip)
                {
                    while (clip.loadState == AudioDataLoadState.Loading)
                    {
                        yield return(null);
                    }
                    if (clip.loadState == AudioDataLoadState.Loaded)
                    {
                        clip.name = Path.GetFileNameWithoutExtension(filePath);
                    }
                }
                if (!PlaySounds(clip))
                {
                    MarkPlayErrorItem(filePath);
                }
            }
        }
    }