public void Register(SoundPlayButton button) { if (button != null && !_buttons.Contains(button)) { _buttons.Add(button); button.PlayStateChanged += ButtonOnPlayStateChanged; } }
public void UnRegister(SoundPlayButton button) { if (button != null && !_buttons.Contains(button)) { _buttons.Add(button); button.PlayStateChanged -= ButtonOnPlayStateChanged; } }
private async void ButtonOnPlayStateChanged( SoundPlayButton activeButton, SoundPlayState newState) { lock (_lockObject) { if (_isLoading) { return; } _isLoading = true; } if (activeButton == null) { return; } _activeButton = activeButton; var notification = new SoundPlayStateChangedNotification { NewSound = (Sound)activeButton.DataContext, NewState = newState }; if (newState == SoundPlayState.Playing) { foreach (SoundPlayButton button in _buttons) { if (button != activeButton && button.State == SoundPlayState.Playing) { button.State = SoundPlayState.Stopped; MediaElementSound.Stop(); } } await SetSound(activeButton.Sound); Play(); } else { activeButton.State = SoundPlayState.Paused; Stop(); } //if (Command != null) // Command.Execute(notification); _isLoading = false; }
private async void ButtonOnPlayStateChanged( SoundPlayButton activeButton, SoundPlayState newState) { lock (_lockObject) { if (_isLoading) return; _isLoading = true; } if (activeButton == null) return; _activeButton = activeButton; var notification = new SoundPlayStateChangedNotification { NewSound = (Sound)activeButton.DataContext, NewState = newState }; if (newState == SoundPlayState.Playing) { foreach (SoundPlayButton button in _buttons) { if (button != activeButton && button.State == SoundPlayState.Playing) { button.State = SoundPlayState.Stopped; MediaElementSound.Stop(); } } await SetSound(activeButton.Sound); Play(); } else { activeButton.State = SoundPlayState.Paused; Stop(); } //if (Command != null) // Command.Execute(notification); _isLoading = false; }