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); } } } }
public bool PlaySounds(int index) { StopCurSound(); if (index < 0 || index >= SoundsInfoList.Count) { return(false); } CurSoundInfo = SoundsInfoList[index]; CurSoundsIndex = index; if (null != UpdateSelectItemEvent) { UpdateSelectItemEvent(); } if (!File.Exists(CurSoundInfo.FilePath)) { return(false); } if (m_NAudioSupportFormat.Contains(CurSoundInfo.ExtensionNotDot)) { NAudioPlayer.SupportFormatType type = Convert2NAduioSFT(CurSoundInfo.ExtensionNotDot); if (type == NAudioPlayer.SupportFormatType.NULL) { return(false); } StartCoroutine(LoadFileByNAudio(CurSoundInfo.FilePath, type)); return(true); } else if (m_UnitySupportFormat.Contains(CurSoundInfo.ExtensionNotDot)) { StartCoroutine(LoadFileByUnity(CurSoundInfo.FilePath)); return(true); } else { Debug.Log("Does not support audio formats:" + CurSoundInfo.FilePath); return(false); } }