public PlayerViewController(PlayerViewModel viewModel) { View = new PlayerView(); viewModel.WhenAnyValue(vm => vm.CurrentTrack) .Where(track => track != null) .Subscribe(track => UpdateTrackInformation(track)); viewModel.WhenAnyValue(vm => vm.CurrentTrack) .Select(track => track != null) .BindTo(View.PlayerControls.PlayButton, button => button.Enabled); viewModel.WhenAnyValue(vm => vm.Playing) .Subscribe(playing => { if (playing) { View.PlayerControls.ShowPauseButton(); } else { View.PlayerControls.ShowPlayButton(); } }); var mutedObservable = viewModel.WhenAnyValue(vm => vm.Muted); viewModel.WhenAnyValue(vm => vm.Volume) .CombineLatest(mutedObservable, (volume, muted) => muted ? 0.0f : volume) .BindTo(View.SoundControl.VolumeSlider, slider => slider.FloatValue); mutedObservable.BindTo(View.SoundControl, sc => sc.Muted); View.PlayerControls.PlayButton.Activated += (sender, e) => viewModel.Play(viewModel.CurrentTrack); View.PlayerControls.PauseButton.Activated += (sender, e) => viewModel.Pause(); View.SoundControl.VolumeSlider.Activated += (sender, e) => viewModel.Volume = (sender as NSSlider).FloatValue; View.SoundControl.MuteButton.Activated += (sender, e) => viewModel.ToggleMute(); var progressObservable = View.Progress .WhenAnyValue(p => p.Progress); progressObservable .Where(_ => !View.Progress.IsDragging) .BindTo(viewModel, vm => vm.Progress); progressObservable .Where(_ => View.Progress.IsDragging) .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler) .Subscribe(progress => viewModel.Seek(progress)); viewModel.WhenAnyValue(vm => vm.Progress) .Where(_ => !View.Progress.IsDragging) .DistinctUntilChanged() .Subscribe(progress => View.Progress.Progress = progress); }
/// ------------------------------------------------------------------------------------ private bool InternalPlay() { string errorMessage = null; lock (_mediaFileQueue) { if (_mediaFileQueue.Count == 0) { return(false); } PlayerViewModel.PlaybackStarted -= HandleMediaPlayStarted; PlayerViewModel.PlaybackEnded -= HandleMediaPlaybackEnded; try { LoadFile(); } catch (Exception e) { _mediaFileQueue.Clear(); errorMessage = e.Message; } } if (errorMessage != null) { if (InvokeRequired) { Invoke((Action)(() => ErrorReport.NotifyUserOfProblem(errorMessage))); } else { ErrorReport.NotifyUserOfProblem(errorMessage); } return(false); } PlayerViewModel.PlaybackStarted += HandleMediaPlayStarted; PlayerViewModel.PlaybackEnded += HandleMediaPlaybackEnded; PlayerViewModel.PlaybackPositionChanged = HandleMediaPlaybackPositionChanged; //_paused = false; PlayerViewModel.Play(); PlaybackInProgress = true; return(true); }
void PlaySong(Track track) { playerViewModel.Play(track); }
/// <summary> /// The function plays the simualtor on play button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Play_Click(object sender, System.Windows.RoutedEventArgs e) { viewModel.Play(); }