/// <summary> /// After constructor all properties all set and <see cref="AudioClip"/> is created. /// Use <see cref="StartLoading"/> to start loading. /// At this point you can subscribe to events to make sure you don't miss any. /// </summary> /// <param name="config"></param> public AudioLoader(AudioLoaderConfig config) { this.Config = config; CreateReader(); if (reader != null) { CreateAudioClip(); } }
public static AudioClip Load( Stream dataStream, SelectDecoder audioFormat, string unityAudioClipName, LoadMethod loadType = LoadMethod.AllPartsInBackgroundThread, bool diposeDataStreamIfNotNeeded = true #if UNITY_4 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 , bool is3D = true #endif ) { var config = new AudioLoaderConfig() { DataStream = dataStream, AudioFormat = audioFormat, UnityAudioClipName = unityAudioClipName, LoadMethod = loadType, DisposeDataStreamIfNotNeeded = diposeDataStreamIfNotNeeded, PreferredDecoder = PreferredDecoder, #if UNITY_4 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 Is3D = is3D, #endif }; var audioLoader = new AudioLoader(config); audioLoader.OnLoadingDone += () => OnLoadingDonePrivate(audioLoader); audioLoader.OnLoadingAborted += () => OnLoadingAbortedPrivate(audioLoader); audioLoader.OnLoadingFailed += (exception) => OnLoadingFailedPrivate(audioLoader, exception); if (loadType == LoadMethod.StreamInUnityThread) { SetAudioClipLoadType(audioLoader.AudioClip, AudioClipLoadType.Streaming); } else { SetAudioClipLoadType(audioLoader.AudioClip, AudioClipLoadType.DecompressOnLoad); } SetAudioClipLoadState(audioLoader.AudioClip, audioLoader.LoadState); audioLoader.StartLoading(); SetAudioClipLoadState(audioLoader.AudioClip, audioLoader.LoadState); return(audioLoader.AudioClip); }
/// <summary> /// Returns AudioFormat enum from filePath extension /// </summary> /// <returns>AudioFormat if filePath extension is supported format, -1 otherwise</returns> public static SelectDecoder GetAudioFormat(string filePath) { return(AudioLoaderConfig.GetAudioFormat(filePath)); }
/// <summary> /// Checks if filePath constains file with supported extension /// </summary> /// <returns>true if extension is supported, false if not</returns> public static bool IsSupportedFormat(string filePath) { return(AudioLoaderConfig.IsSupportedFormat(filePath)); }