private void PauseButton_Click(object sender, RoutedEventArgs e) { PauseButton.Visibility = Visibility.Collapsed; PlayButton.Visibility = Visibility.Visible; PlayingSongMedia.Pause(); isPause = true; }
private async void SetMediaSource() { ProgressSlider.IsEnabled = false; PlayButton.Visibility = Visibility.Collapsed; PauseButton.Visibility = Visibility.Visible; if (PlayingBarVm.CurrentPlayingSong.Url == " ") { string content = await httpService.GetJsonStringAsync(APIUrlReference.GetPlayingSongUrl + PlayingBarVm.CurrentPlayingSong.Id); PlayingSongUrlJsonObject model = jsonSerializer.Deserialize <PlayingSongUrlJsonObject>(new JsonTextReader(new StringReader(content))); HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.GetAsync(new Uri(model.data[0].url)); IBuffer buffer = await response.Content.ReadAsBufferAsync(); StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFolder folder = null; if (localFolder.GetFolderAsync("PlayCache") == null) { folder = await localFolder.CreateFolderAsync("PlayCache", CreationCollisionOption.ReplaceExisting); } else { folder = await localFolder.CreateFolderAsync("PlayCache", CreationCollisionOption.OpenIfExists); } string name = getSongName(model.data[0].url); string type = getSongType(name); StorageFile file = await folder.CreateFileAsync(name, CreationCollisionOption.ReplaceExisting); StorageFile storageFile = await folder.GetFileAsync(name); await FileIO.WriteBufferAsync(storageFile, buffer);//从缓冲写入文件 IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); ((PlayingSongForSqlModel)PlayingBarVm.PlayingList[PlayingBarVm.CurIndex]).Url = name; PlayingBarVm.CurrentPlayingSong.Url = name; dBService.UpdatePlayList(PlayingBarVm.CurrentPlayingSong.Id, name); PlayingSongMedia.SetSource(fileStream, file.FileType); } else { StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFolder folder = await localFolder.CreateFolderAsync("PlayCache", CreationCollisionOption.OpenIfExists); StorageFile file = await folder.CreateFileAsync(PlayingBarVm.CurrentPlayingSong.Url, CreationCollisionOption.OpenIfExists); IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); PlayingSongMedia.SetSource(fileStream, file.FileType); } UpdateControl(); }
private void PlayButton_Click(object sender, RoutedEventArgs e) { PlayButton.Visibility = Visibility.Collapsed; PauseButton.Visibility = Visibility.Visible; if (isPause) { PlayingSongMedia.Play(); } else { SetMediaSource(); } }
private void Next_Click(object sender, RoutedEventArgs e) { string nextSongId = PlayingBarVm.getNextSongIdAuto(); if (nextSongId != "Done") { SetMediaSource(); } else { PlayingSongMedia.Play(); } PlayButton.Visibility = Visibility.Collapsed; PauseButton.Visibility = Visibility.Visible; }
private void PlayingSong_MediaEnded(object sender, RoutedEventArgs e) { if (PlayingBarVm.Type == PLAYTYPE.RepeatOne) { PlayingSongMedia.Play(); } else { string nextSongId = PlayingBarVm.getNextSongIdAuto(); if (nextSongId != "Done") { SetMediaSource(); } } }