Esempio n. 1
0
        public async Task <PlaybackService> InitializeAsync()
        {
            // Initialize Setting
            //Setting.InitializeSettingBinary(RepeatMode, nameof(RepeatMode), MediaRepeatMode.None);
            //Setting.InitializeSetting(EnableShuffle, nameof(EnableShuffle), false);

            Player             = new MediaPlayer();
            _playlistContainer = new PlaylistContainer();

            Setting.Playback.Volume
            .Subscribe(x => Player.Volume = x / 100d);

            Observable.FromEventPattern <TypedEventHandler <MediaPlayer, object>, object>(
                h => Player.MediaEnded += h, h => Player.MediaEnded -= h)
            .Subscribe(async _ =>
            {
                IsPlaying.OnNext(false);

                if (_playlistContainer.RepeatMode == MediaRepeatMode.Track)
                {
                    await PlayAsyncInner(_playlistContainer.CurrentTrack);
                    return;
                }

                if (_playlistContainer.HasNext())
                {
                    await PlayAsyncInner(_playlistContainer.Next());
                }
            });

            Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(500))
            .SkipUntil(IsPlaying.DistinctUntilChanged().Where(x => x))
            .TakeUntil(IsPlaying.DistinctUntilChanged().Where(x => !x))
            .Repeat()
            .Subscribe(_ =>
            {
                PlaybackPosition.OnNext(Player.PlaybackSession);
            });

            NewTrackPlayed
            .Do(x => WriteSmtcThumbnail(x.PlaybackItem, x.Track))
            .ObserveOnCoreDispatcher()
            .Subscribe(x =>
            {
                if (_previousTrack != null)
                {
                    _previousTrack.IsPlaying = false;
                }
                x.Track.IsPlaying = true;
                _previousTrack    = x.Track;
            });

            return(await Task.FromResult(this));
        }
Esempio n. 2
0
        private static async Task PlayAsyncInner(TrackViewModel track)
        {
            var mpi = await CreateMediaPlaybackItemAsync(track);

            Player.Source = mpi;
            Player.Play();

            NewTrackPlayed.OnNext(new TrackMixed
            {
                Track        = track,
                PlaybackItem = mpi,
            });
            IsPlaying.OnNext(true);
        }
Esempio n. 3
0
        public static void Resume()
        {
            Player.Play();

            IsPlaying.OnNext(true);
        }
Esempio n. 4
0
        public static void Pause()
        {
            Player.Pause();

            IsPlaying.OnNext(false);
        }