public PlayerTestWindow() { InitializeComponent(); _refreshTimer = new DispatcherTimer(TimeSpan.FromSeconds(0.1), DispatcherPriority.Background, (sender, args) => { var length = MeAudio.NaturalDuration.HasTimeSpan ? MeAudio.NaturalDuration.TimeSpan : (TimeSpan?)null; TbCurrentPosition.Text = MeAudio.Position.ToString(@"mm\:ss"); TbLength.Text = length?.ToString(@"mm\:ss") ?? "--:--"; PbProgress.Minimum = 0; PbProgress.Maximum = length?.TotalMilliseconds ?? 1; PbProgress.Value = MeAudio.Position.TotalMilliseconds; }, Dispatcher); Player = new Player(((App)Application.Current).Session); Player.CurrentChannelChanged += (sender, args) => TbCurrentChannel.Text = args.Object?.ToString(); Player.CurrentSongChanged += (sender, args) => { ImgCover.Source = args.Object != null ? new BitmapImage(new Uri(args.Object.PictureUrl)) : null; TbTitle.Text = args.Object?.Title; TbArtist.Text = args.Object?.Artist; TbAlbum.Text = args.Object?.AlbumTitle; TbCurrentSong.Text = args.Object != null?JsonConvert.SerializeObject(args.Object, Formatting.Indented) : null; MeAudio.Source = args.Object == null ? null : new Uri(args.Object.Url); MeAudio.Play(); _playing = true; }; Discovery = new Discovery(((App)Application.Current).Session); }
private void BtnPlay_Click(object sender, RoutedEventArgs e) { if (_playing) { MeAudio.Pause(); } else { MeAudio.Play(); } _playing = !_playing; }