public SoundPlaybackService() { this.playTime = new Timer(); this.playTime.Interval = 1000; this.playTime.Elapsed += new ElapsedEventHandler(this.IncrementCurrentSoundTimeEvent); this.currentSound = default(PlayableSound); }
public void PlaySoundOrStopIfNull(Sound sound) { this.playTime.Stop(); if (sound == null) { if (this.currentSound != null) { this.currentSound.Pause(); } this.currentSound = default(PlayableSound); return; } this.currentSound = new PlayableSound(sound); this.currentSound.Play(); this.playTime.Start(); }
private void IncrementCurrentSoundTimeEvent(object source, ElapsedEventArgs e) { if (DateTime.Now >= this.currentSound.SoundEnd) { this.playTime.Stop(); this.currentSound.Pause(); this.currentSound = default(PlayableSound); if (this.SoundEnds != null) { SoundEnds(this, EventArgs.Empty); } return; } var currentToEndTimespan = this.currentSound.SoundEnd.Subtract(DateTime.Now); this.currentSound.CurrentTime = this.currentSound.Duration - (int)currentToEndTimespan.TotalSeconds; }