Exemple #1
0
            public CurrentMusicTrack(MusicTrack musicTrack, ProtoPlaylist playlist)
            {
                this.Playlist   = playlist;
                this.MusicTrack = musicTrack;
                // ensure the track is changed
                ComponentMusicSource.MusicResource = MusicResource.NoMusic;
                ComponentMusicSource.MusicResource = musicTrack.MusicResource;
                ComponentMusicSource.IsLooped      = musicTrack.IsLooped;
                this.CurrentFadeInDuration         = musicTrack.FadeInDuration;
                this.CurrentFadeOutDuration        = musicTrack.FadeOutDuration;

                if (MusicTrackLastStopTimeManager.TryGetLastStopTime(musicTrack.MusicResource, out var lastStopTime))
                {
                    this.startAtPosition = lastStopTime;
                    ComponentMusicSource.Seek(lastStopTime);
                    Logger.Important($"Resume music {musicTrack.MusicResource} from {lastStopTime}");
                }
                else
                {
                    this.startAtPosition = null;
                }

                this.Update();
                ComponentMusicSource.Play();
            }
Exemple #2
0
            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();
            }