/// <summary> /// Creates AudioManager. /// </summary> /// <param name="audioInfoList">Audio info list.</param> /// <param name="dataDirectory">Audio data directory.</param> /// <param name="notification">Notification manager.</param> /// <returns>AudioManager.</returns> public static AudioManager CreateAudioManager(AudioInfo[] audioInfoList, Pathfinder dataDirectory, NotificationManager notification) { var audioManager = new AudioManager(); var loadedAudios = new Dictionary <string, AudioData>(); var audioItems = new List <AudioItem>(); var settings = App.Settings; var audioWaveFormat = settings.AudioWaveFormat; int resamplingQuality = settings.AudioResamplingQuality; int itemsLimit = settings.ItemsLimit; foreach (var item in audioInfoList) { try { if (!String.IsNullOrWhiteSpace(item.File) && item.Name != null) { AudioData data; if (!loadedAudios.TryGetValue(item.File, out data)) { data = AudioData.LoadAudio(dataDirectory.FindPathName(item.File), audioWaveFormat, item.IsCached, item.Volume, resamplingQuality); loadedAudios.Add(item.File, data); } string guid = Guid.NewGuid().ToString("N"); var audioItem = new AudioItem { Id = guid, Name = item.Name, Data = data }; audioManager.audios.Add(guid, audioItem); audioItems.Add(audioItem); itemsLimit--; if (itemsLimit <= 0) { break; } } } catch (Exception ex) { Log.Warning(ex, "Failed to load audio file: FileName = {FileName}", item.File); notification.Notify( String.Format(LocalizedInfo.MessagePatternFailedToLoadAudioFile, item.File), NotificationLevel.Warn); } } audioManager.AudioItems = ImmutableList.Create(audioItems.ToArray()); return(audioManager); }
/// <summary> /// Tries to get AudioItem corresponds with the key. /// </summary> /// <param name="key">key for the audio.</param> /// <param name="audioItem">Audio item.</param> /// <returns>true if the data is got successfully.</returns> public bool TryGetAudioItem(string key, out AudioItem audioItem) { return(this.audios.TryGetValue(key, out audioItem)); }