private void NAudioEngine_PropertyChanged(object sender, PropertyChangedEventArgs e) { NAudioEngine engine = NAudioEngine.Instance; switch (e.PropertyName) { case "FileTag": if (engine.FileTag != null) { TagLib.Tag tag = engine.FileTag.Tag; if (tag.Pictures.Length > 0) { using (MemoryStream albumArtworkMemStream = new MemoryStream(tag.Pictures[0].Data.Data)) { try { BitmapImage albumImage = new BitmapImage(); albumImage.BeginInit(); albumImage.CacheOption = BitmapCacheOption.OnLoad; albumImage.StreamSource = albumArtworkMemStream; albumImage.EndInit(); albumArtPanel.AlbumArtImage = albumImage; } catch (NotSupportedException) { albumArtPanel.AlbumArtImage = null; // System.NotSupportedException: // No imaging component suitable to complete this operation was found. } albumArtworkMemStream.Close(); } } else { albumArtPanel.AlbumArtImage = null; } } else { albumArtPanel.AlbumArtImage = null; } break; case "ChannelPosition": clockDisplay.Time = TimeSpan.FromSeconds(engine.ChannelPosition); break; default: // Do Nothing break; } }
public MainWindow() { InitializeComponent(); NAudioEngine soundEngine = NAudioEngine.Instance; soundEngine.PropertyChanged += NAudioEngine_PropertyChanged; UIHelper.Bind(soundEngine, "CanStop", StopButton, Button.IsEnabledProperty); UIHelper.Bind(soundEngine, "CanPlay", PlayButton, Button.IsEnabledProperty); UIHelper.Bind(soundEngine, "CanPause", PauseButton, Button.IsEnabledProperty); UIHelper.Bind(soundEngine, "SelectionBegin", repeatStartTimeEdit, TimeEditor.ValueProperty, BindingMode.TwoWay); UIHelper.Bind(soundEngine, "SelectionEnd", repeatStopTimeEdit, TimeEditor.ValueProperty, BindingMode.TwoWay); spectrumAnalyzer.RegisterSoundPlayer(soundEngine); waveformTimeline.RegisterSoundPlayer(soundEngine); LoadExpressionDarkTheme(); }