public void Stop() { if (audioSource) { audioSource.Stop(); } playState = AudioPlayState.Stop; if (sourceType == AudioSourceType.Music) { if (!isCallPreStop) { isCallPreStop = true; if (AudioPlayManager.OnMusicPreStopCallBack != null) { AudioPlayManager.OnMusicPreStopCallBack(AssetName, musicChannel, flag); } } if (AudioPlayManager.OnMusicStopCallBack != null) { AudioPlayManager.OnMusicStopCallBack(AssetName, musicChannel, flag); } } else { if (AudioPlayManager.OnSFXStopCallBack != null) { AudioPlayManager.OnSFXStopCallBack(AssetName, flag); } } }
/// <summary> /// 检查音频是否播放完成 /// </summary> public void CheckState() { if (playState == AudioPlayState.Stop) { return; } //Debug.Log("audioSource.time:" + audioSource.time + " clip.lenth:" + audioSource.clip.length); if (audioSource.clip.length > 1 && audioSource.time >= (audioSource.clip.length - 1) && !isCallPreStop) { isCallPreStop = true; if (AudioPlayManager.OnMusicPreStopCallBack != null) { AudioPlayManager.OnMusicPreStopCallBack(AssetName, musicChannel, flag); } } if (audioSource == null || (!audioSource.isPlaying && playState != AudioPlayState.Pause)) { Stop(); } }