/// <summary> /// Initializes the wrapper. /// </summary> /// <param name="audioSourceDirectory">The directory of the audio source.</param> /// <returns>True if successful.</returns> public bool Initialize(string audioSourceDirectory) { try { _logger = AudioBandLogManager.GetLogger($"AudioSourceWrapper({new DirectoryInfo(audioSourceDirectory).Name})"); _logger.Debug("Initializing wrapper"); AppDomain.CurrentDomain.UnhandledException += (o, e) => _logger.Error(e.ExceptionObject as Exception, "Unhandled exception in wrapper"); _audioSource = AudioSourceLoader.LoadFromDirectory(audioSourceDirectory); _audioSource.Logger = new AudioSourceLogger(_audioSource.Name); _audioSource.SettingChanged += (o, e) => SettingChanged?.Invoke(this, e); _audioSource.TrackInfoChanged += (o, e) => TrackInfoChanged?.Invoke(this, e); _audioSource.IsPlayingChanged += (o, e) => IsPlayingChanged?.Invoke(this, e); _audioSource.TrackProgressChanged += (o, e) => TrackProgressChanged?.Invoke(this, e); _audioSource.VolumeChanged += (o, e) => VolumeChanged?.Invoke(this, e); _audioSource.ShuffleChanged += (o, e) => ShuffleChanged?.Invoke(this, e); _audioSource.RepeatModeChanged += (o, e) => RepeatModeChanged?.Invoke(this, e); _audioSourceSettingsList = _audioSource.GetSettings(); foreach (AudioSourceSetting setting in _audioSourceSettingsList) { _audioSourceSettings.Add(setting.Attribute.Name, setting); } _logger.Debug("Wrapper initialization complete"); return(true); } catch (Exception e) { _logger.Error(e); return(false); } }
private List <AudioSourceSettingVM> CreateSettingViewModels(AudioSourceSettings existingSettings, IAudioSource source) { var viewmodels = new List <AudioSourceSettingVM>(); var audioSourceSettingInfos = source.GetSettings(); foreach (var audioSourceSettingInfo in audioSourceSettingInfos.OrderByDescending(s => s.Attribute.Priority)) { var matchingSetting = existingSettings.Settings.FirstOrDefault(s => s.Name == audioSourceSettingInfo.Attribute.Name); if (matchingSetting != null) { viewmodels.Add(new AudioSourceSettingVM(matchingSetting, audioSourceSettingInfo)); } else { var name = audioSourceSettingInfo.Attribute.Name; var defaultValue = audioSourceSettingInfo.GetValue(); var newSetting = new AudioSourceSetting { Name = name, Value = defaultValue }; Model.Settings.Add(newSetting); viewmodels.Add(new AudioSourceSettingVM(newSetting, audioSourceSettingInfo, false)); } } return(viewmodels); }