public PhilipsHueBridgeVM(DevicePlugins.PhilipsHueDSB client) : base(client) { LinkCommand = new GenericCommand(async(obj) => { LinkResult = ""; //clear last result OnPropertyChanged(nameof(LinkResult)); LinkResult = await Client.LinkAsync(); //link hub OnPropertyChanged(nameof(LinkResult)); IsLinked = await Client.GetIsLinkedAsync(); //update islinked property OnPropertyChanged(nameof(IsLinked)); }); }
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); }); }