public void LoadSegmentAsync(AudioPlaybackLayerChannelUnity audioPlaybackChannel) { #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { Logger.Instance.Log("LoadSegmentAsync() pathToClip=" + audioPlaybackChannel.PathToClip+ " tryToUseWrappers=" + AudioPlaybackLayerChannelUnity._tryToUseWrappers + " audioPlaybackChannel.GetHashCode()=" + audioPlaybackChannel.GetHashCode(), LogLevel.debug); } #endif StartCoroutine("LoadSegmentAsync_Coroutine", audioPlaybackChannel); }
public void LoadSegmentAsync(AudioPlaybackLayerChannelUnity audioPlaybackChannel) { #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { Logger.Instance.Log("LoadSegmentAsync() pathToClip=" + audioPlaybackChannel.PathToClip + " tryToUseWrappers=" + AudioPlaybackLayerChannelUnity._tryToUseWrappers + " audioPlaybackChannel.GetHashCode()=" + audioPlaybackChannel.GetHashCode(), LogLevel.debug); } #endif StartCoroutine("LoadSegmentAsync_Coroutine", audioPlaybackChannel); }
private IEnumerator LoadSegmentAsync_Coroutine(AudioPlaybackLayerChannelUnity audioPlaybackChannel) { if (AudioPlaybackLayerChannelUnity._tryToUseWrappers) { ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClipWrapper, typeof(GameObject)); yield return request; #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { string logMessage = "LoadSegmentAsync_Coroutine [Wrappers] complete, asset=" + request.asset.name; logMessage += " ImmediatePlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending; Logger.Instance.Log(logMessage, LogLevel.debug); } #endif GameObject wrapperGameObject = request.asset as GameObject; if (wrapperGameObject == null) { #if (!PSAI_NOLOG) if (LogLevel.errors <= Logger.Instance.LogLevel) { Logger.Instance.Log("The Wrapper prefab '" + audioPlaybackChannel.PathToClipWrapper + "' was not found! Please run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled.", LogLevel.errors); } #endif } else { PsaiAudioClipWrapper wrapperComponent = wrapperGameObject.GetComponent<PsaiAudioClipWrapper>(); if (wrapperComponent == null || wrapperComponent._audioClip == null) { Debug.LogError("a Wrapper prefab for AudioClip '" + audioPlaybackChannel.PathToClip + "' was found, but it was invalid. Please re-run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled."); } else { audioPlaybackChannel.AudioClip = wrapperComponent._audioClip; } } } else { ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClip, typeof(AudioClip)); yield return request; #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { string logMessage = "LoadSegmentAsync_Coroutine [No Wrappers] complete, asset=" + request.asset.name; logMessage += " ImmediatePlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending + " audioPlaybackChannel.GetHashCode()" + audioPlaybackChannel.GetHashCode(); Logger.Instance.Log(logMessage, LogLevel.debug); } #endif AudioClip clip = request.asset as AudioClip; if (clip == null) { #if (!PSAI_NOLOG) if (LogLevel.errors <= Logger.Instance.LogLevel) { Logger.Instance.Log("The AudioClip '" + audioPlaybackChannel.PathToClip + "' was not found!", LogLevel.errors); } #endif } else { audioPlaybackChannel.AudioClip = clip; } } if (audioPlaybackChannel.PlaybackIsPending) { while (!audioPlaybackChannel.IsReadyToPlay()) { yield return null; #if (!PSAI_NOLOG) if (LogLevel.warnings <= Logger.Instance.LogLevel) { Logger.Instance.Log("ImmediatePlayback is pending but AudioClip is not ready to play!", LogLevel.warnings); } #endif } audioPlaybackChannel.PlayBufferedClipImmediately(); } }
private IEnumerator LoadSegmentAsync_Coroutine(AudioPlaybackLayerChannelUnity audioPlaybackChannel) { ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClip, typeof(AudioClip)); yield return request; #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { string logMessage = "LoadSegmentAsync_Coroutine complete, asset=" + request.asset.name; logMessage += " PlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending + " audioPlaybackChannel.GetHashCode()" + audioPlaybackChannel.GetHashCode(); Logger.Instance.Log(logMessage, LogLevel.debug); } #endif AudioClip clip = request.asset as AudioClip; if (clip == null) { #if (!PSAI_NOLOG) if (LogLevel.errors <= Logger.Instance.LogLevel) { Logger.Instance.Log("The AudioClip '" + audioPlaybackChannel.PathToClip + "' was not found!", LogLevel.errors); } #endif } else { audioPlaybackChannel.AudioClip = clip; audioPlaybackChannel.AudioClip.LoadAudioData(); } if (audioPlaybackChannel.PlaybackIsPending) { while (!audioPlaybackChannel.IsReadyToPlay()) { yield return null; #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { Logger.Instance.Log("Playback is pending but AudioClip is not ready to play!", LogLevel.debug); } #endif } int delayMillis = audioPlaybackChannel.TargetPlaybackTimestamp - Logik.GetTimestampMillisElapsedSinceInitialisation(); if (delayMillis < 0 && Time.timeSinceLevelLoad > 1.0f) { #if (!PSAI_NOLOG) if (LogLevel.warnings <= Logger.Instance.LogLevel) { Logger.Instance.Log(string.Format("playback timing problem detected! Missing milliseconds: {0} ", delayMillis), LogLevel.warnings); } if (clip.loadType == AudioClipLoadType.Streaming) { Logger.Instance.Log("Please increase the 'Max Playback Latency' in PsaiCoreManager for the current target platform.", LogLevel.warnings); } else { Logger.Instance.Log("We highly recommend setting the 'Load Type' of all psai Audio Clips to 'Streaming'.", LogLevel.warnings); } #endif } audioPlaybackChannel.PlayBufferedClip(delayMillis); } }
private IEnumerator LoadSegmentAsync_Coroutine(AudioPlaybackLayerChannelUnity audioPlaybackChannel) { if (AudioPlaybackLayerChannelUnity._tryToUseWrappers) { ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClipWrapper, typeof(GameObject)); yield return(request); #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { string logMessage = "LoadSegmentAsync_Coroutine [Wrappers] complete, asset=" + request.asset.name; logMessage += " ImmediatePlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending; Logger.Instance.Log(logMessage, LogLevel.debug); } #endif GameObject wrapperGameObject = request.asset as GameObject; if (wrapperGameObject == null) { #if (!PSAI_NOLOG) if (LogLevel.errors <= Logger.Instance.LogLevel) { Logger.Instance.Log("The Wrapper prefab '" + audioPlaybackChannel.PathToClipWrapper + "' was not found! Please run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled.", LogLevel.errors); } #endif } else { PsaiAudioClipWrapper wrapperComponent = wrapperGameObject.GetComponent <PsaiAudioClipWrapper>(); if (wrapperComponent == null || wrapperComponent._audioClip == null) { Debug.LogError("a Wrapper prefab for AudioClip '" + audioPlaybackChannel.PathToClip + "' was found, but it was invalid. Please re-run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled."); } else { audioPlaybackChannel.AudioClip = wrapperComponent._audioClip; } } } else { ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClip, typeof(AudioClip)); yield return(request); #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { string logMessage = "LoadSegmentAsync_Coroutine [No Wrappers] complete, asset=" + request.asset.name; logMessage += " ImmediatePlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending + " audioPlaybackChannel.GetHashCode()" + audioPlaybackChannel.GetHashCode(); Logger.Instance.Log(logMessage, LogLevel.debug); } #endif AudioClip clip = request.asset as AudioClip; if (clip == null) { #if (!PSAI_NOLOG) if (LogLevel.errors <= Logger.Instance.LogLevel) { Logger.Instance.Log("The AudioClip '" + audioPlaybackChannel.PathToClip + "' was not found!", LogLevel.errors); } #endif } else { audioPlaybackChannel.AudioClip = clip; } } if (audioPlaybackChannel.PlaybackIsPending) { while (!audioPlaybackChannel.IsReadyToPlay()) { yield return(null); #if (!PSAI_NOLOG) if (LogLevel.warnings <= Logger.Instance.LogLevel) { Logger.Instance.Log("ImmediatePlayback is pending but AudioClip is not ready to play!", LogLevel.warnings); } #endif } audioPlaybackChannel.PlayBufferedClipImmediately(); } }
private IEnumerator LoadSegmentAsync_Coroutine(AudioPlaybackLayerChannelUnity audioPlaybackChannel) { ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClip, typeof(AudioClip)); yield return(request); #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { string logMessage = "LoadSegmentAsync_Coroutine complete, asset=" + request.asset.name; logMessage += " PlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending + " audioPlaybackChannel.GetHashCode()" + audioPlaybackChannel.GetHashCode(); Logger.Instance.Log(logMessage, LogLevel.debug); } #endif AudioClip clip = request.asset as AudioClip; if (clip == null) { #if (!PSAI_NOLOG) if (LogLevel.errors <= Logger.Instance.LogLevel) { Logger.Instance.Log("The AudioClip '" + audioPlaybackChannel.PathToClip + "' was not found!", LogLevel.errors); } #endif } else { audioPlaybackChannel.AudioClip = clip; audioPlaybackChannel.AudioClip.LoadAudioData(); } if (audioPlaybackChannel.PlaybackIsPending) { while (!audioPlaybackChannel.IsReadyToPlay()) { yield return(null); #if (!PSAI_NOLOG) if (LogLevel.debug <= Logger.Instance.LogLevel) { Logger.Instance.Log("Playback is pending but AudioClip is not ready to play!", LogLevel.debug); } #endif } int delayMillis = audioPlaybackChannel.TargetPlaybackTimestamp - Logik.GetTimestampMillisElapsedSinceInitialisation(); if (delayMillis < 0 && Time.timeSinceLevelLoad > 1.0f) { #if (!PSAI_NOLOG) if (LogLevel.warnings <= Logger.Instance.LogLevel) { Logger.Instance.Log(string.Format("playback timing problem detected! Missing milliseconds: {0} ", delayMillis), LogLevel.warnings); } if (clip.loadType == AudioClipLoadType.Streaming) { Logger.Instance.Log("Please note: playback timing problems may occur when starting a Scene or when the Log Output in the PsaiCoreManager is set to Debug. If the warning shows up frequently during the game, please increase the 'Max Playback Latency' in PsaiCoreManager for the current target platform.", LogLevel.warnings); } else { Logger.Instance.Log("We highly recommend setting the 'Load Type' of all psai Audio Clips to 'Streaming'.", LogLevel.warnings); } #endif } audioPlaybackChannel.PlayBufferedClip(delayMillis); } }