Exemple #1
0
 internal void Unload()
 {
     if (_client != null)
     {
         _client.DeviceLost -= Client_DeviceLost;
         _client.MediaPlayer.PlayStateChanged       -= PlayStateChanged;
         _client.MediaPlayer.PlaylistChanged        -= MediaPlayer_PlaylistChanged;
         _client.MediaPlayer.ShuffleModeChanged     -= MediaPlayer_ShuffleModeChanged;
         _client.MediaPlayer.LoopModeChanged        -= MediaPlayer_LoopModeChanged;
         _client.MediaPlayer.InterruptibleChanged   -= MediaPlayer_InterruptibleChanged;
         _client.MediaPlayer.EnabledControlsChanged -= MediaPlayer_EnabledControlsChanged;
         _client.MediaPlayer.EndOfPlayback          -= MediaPlayer_EndOfPlayback;
         if (_client.Volume != null)
         {
             _client.Volume.VolumeChanged  -= Volume_VolumeChanged;
             _client.Volume.MuteChanged    -= Volume_MuteChanged;
             _client.Volume.EnabledChanged -= Volume_EnabledChanged;
         }
         _lastKnownState = null;
         _playerInfo     = null;
         _client         = null;
     }
 }
Exemple #2
0
        public MediaPlayerVM(AllPlayClient client)
        {
            _client             = client;
            _client.DeviceLost += Client_DeviceLost;
            _positionTimer      = new Windows.UI.Xaml.DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _positionTimer.Tick += PositionTimer_Tick;
            client.MediaPlayer.PlayStateChanged       += PlayStateChanged;
            client.MediaPlayer.PlaylistChanged        += MediaPlayer_PlaylistChanged;
            client.MediaPlayer.ShuffleModeChanged     += MediaPlayer_ShuffleModeChanged;
            client.MediaPlayer.LoopModeChanged        += MediaPlayer_LoopModeChanged;
            client.MediaPlayer.InterruptibleChanged   += MediaPlayer_InterruptibleChanged;
            client.MediaPlayer.EnabledControlsChanged += MediaPlayer_EnabledControlsChanged;
            client.MediaPlayer.EndOfPlayback          += MediaPlayer_EndOfPlayback;
            client.MediaPlayer.GetPlayerInfoAsync().ContinueWith((state) =>
            {
                if (!state.IsFaulted && !state.IsCanceled)
                {
                    _playerInfo = state.Result;
                }
            });

            client.MediaPlayer.GetPlayStateAsync().ContinueWith((state) =>
            {
                if (!state.IsFaulted && !state.IsCanceled)
                {
                    UpdateMediaState(state.Result);
                }
            });
            client.MediaPlayer.GetEnabledControlsAsync().ContinueWith((state) =>
            {
                if (!state.IsFaulted && !state.IsCanceled)
                {
                    UpdateEnabledControls(state.Result);
                }
            });
            client.MediaPlayer.GetPlaylistAsync().ContinueWith((state) =>
            {
                if (!state.IsFaulted && !state.IsCanceled)
                {
                    UpdatePlaylist(state.Result);
                }
            });
            client.MediaPlayer.GetLoopModeAsync().ContinueWith((state) =>
            {
                if (!state.IsFaulted && !state.IsCanceled)
                {
                    LoopMode = state.Result;
                    OnPropertyChanged(nameof(LoopMode));
                }
                ;
            });
            client.MediaPlayer.GetShuffleModeAsync().ContinueWith((state) =>
            {
                if (!state.IsFaulted && !state.IsCanceled)
                {
                    ShuffleMode = state.Result;
                    OnPropertyChanged(nameof(ShuffleMode));
                }
                ;
            });
            client.MediaPlayer.GetInterruptibleAsync().ContinueWith((state) =>
            {
                if (!state.IsFaulted && !state.IsCanceled)
                {
                    IsInterruptible = state.Result;
                    OnPropertyChanged(nameof(IsInterruptible));
                }
                ;
            });
            if (client.Volume != null)
            {
                client.Volume.VolumeChanged  += Volume_VolumeChanged;
                client.Volume.MuteChanged    += Volume_MuteChanged;
                client.Volume.EnabledChanged += Volume_EnabledChanged;
                client.Volume.GetVolumeAsync().ContinueWith((state) =>
                {
                    if (!state.IsFaulted && !state.IsCanceled)
                    {
                        Volume = state.Result;
                        OnPropertyChanged(nameof(Volume));
                    }
                    ;
                });
                client.Volume.GetVolumeEnabledAsync().ContinueWith((state) =>
                {
                    if (!state.IsFaulted && !state.IsCanceled)
                    {
                        Volume_EnabledChanged(client.Volume, state.Result);
                    }
                    ;
                });
                client.Volume.GetMuteAsync().ContinueWith((state) =>
                {
                    if (!state.IsFaulted && !state.IsCanceled)
                    {
                        Volume_MuteChanged(client.Volume, state.Result);
                    }
                    ;
                });
            }

            nextCommand     = new GenericCommand((o) => { _client.MediaPlayer.NextAsync(); }, (o) => { return(_enabledControls == null ? false : _enabledControls.Next); });
            previousCommand = new GenericCommand((o) => { _client.MediaPlayer.PreviousAsync(); }, (o) => { return(_enabledControls == null ? false : _enabledControls.Previous); });
            stopCommand     = new GenericCommand((o) => { _client.MediaPlayer.StopAsync(); });
            resumeCommand   = new GenericCommand((o) => { _client.MediaPlayer.ResumeAsync(); });

            volumeUpCommand   = new GenericCommand((o) => { _client.Volume.AdjustVolumeAsync(2); }, (o) => { return(IsVolumeEnabled); });
            volumeDownCommand = new GenericCommand((o) => { _client.Volume.AdjustVolumeAsync(-2); }, (o) => { return(IsVolumeEnabled); });
        }