void PlayItem(MusicModel item) { CurrentPlayIndex = MusicSource.IndexOf(item); currentName.Text = "当前正在播放歌曲:" + item.Name; if (audioPlayer.GetPalyState()) { audioPlayer.Stop(); } audioPlayer.PlayNet(item.Url); audioPlayer.Completed += (sender, e) => { playImage.Source = new FileImageSource() { File = "play.png" }; PlayState = -1; CurrentPlayIndex = -1; currentName.Text = "当前无正在播放歌曲"; }; playImage.Source = new FileImageSource() { File = "pause.png" }; PlayState = 1; totalTime.Text = $"{ audioPlayer.GetTotalDuration() / 60:d2}:{audioPlayer.GetTotalDuration() % 60:d2}"; Device.StartTimer(new TimeSpan(1000), () => { progress.Progress = audioPlayer.GetCurrentDuration() * 1.0f / audioPlayer.GetTotalDuration(); currentTime.Text = $"{audioPlayer.GetCurrentDuration() / 60:d2}:{audioPlayer.GetCurrentDuration() % 60:d2}"; return(audioPlayer.GetPalyState()); }); }
void OnItemSelected(object sender, SelectedItemChangedEventArgs e) { if (e.SelectedItem != null) { (sender as ListView).SelectedItem = null; var model = e.SelectedItem as MusicModel; if (MusicSource.IndexOf(model) == CurrentPlayIndex) { return; } model.State = 1; PlayItem(model); } }