public void RequestStop() { if (this.IsStopRequested) { // stop return; } if (!ComponentMusicSource.IsReady) { // music resource is not loaded and stop requested - simply stop right now ComponentMusicSource.IsLooped = false; ComponentMusicSource.Stop(); return; } if (this.Playlist != CurrentPlaylist) { // playlist changed, in that case a special fade out duration applies this.CurrentFadeOutDuration = Math.Min(this.CurrentFadeOutDuration, this.Playlist.FadeOutDurationOnPlaylistChange); } this.stopAtPosition = ComponentMusicSource.Position + this.CurrentFadeOutDuration; if (this.stopAtPosition > ComponentMusicSource.Duration) { // clamp to duration this.stopAtPosition = ComponentMusicSource.Duration; } ComponentMusicSource.IsLooped = false; }
public void Update() { if (!ComponentMusicSource.IsReady) { ComponentMusicSource.Volume = 0; return; } if (this.IsStopRequested && ComponentMusicSource.Position > (this.stopAtPosition ?? ComponentMusicSource.Duration)) { if (this.stopAtPosition.HasValue) { if (this.MusicTrack.IsLooped // If track is not looped, check whether there is enough track time remains // to continue playing the track on the resume. // Enough time: at least 10 seconds plus track fade in and out durations. || ((ComponentMusicSource.Duration - this.stopAtPosition.Value) > (10 + this.MusicTrack.FadeInDuration + this.MusicTrack.FadeOutDuration))) { Logger.Important( $"Stop music and remember stop time {this.MusicTrack.MusicResource} at {this.stopAtPosition.Value}"); MusicPlaylistLastStopTimeManager.RememberLastTrack(this.Playlist, this.MusicTrack); MusicTrackLastStopTimeManager.RememberLastTrack(this.MusicTrack.MusicResource, this.stopAtPosition.Value); } } ComponentMusicSource.Stop(); return; } this.ApplyFade(); }