protected async Task SelectedResourceItemChanged(TreeNode <ResourceItem> treeNode) { PlayListItems.Clear(); SelectedPlayListItem = null; if (treeNode.Item.Items == null) { Status = await _client.FetchChildResourcesAsync(treeNode.Item, CancellationToken.None, treeNode.Item.Level, treeNode.Item.Level); } if (Status == ResourceLoadStatus.Ok) { var filteredItems = treeNode.Item.Items.Where(r => IsAudioFile(r).Result).ToList(); Player.Items = filteredItems; PlayListItems = filteredItems .Where(resourceItem => !resourceItem.IsCollection) .Select((resourceItem, index) => new PlayListItem { Index = index, Item = resourceItem, Title = resourceItem.DisplayName, Bitrate = null, Size = resourceItem.ContentLength != null ? ByteSize.FromBytes(resourceItem.ContentLength.Value).ToString("0.00 MB") : string.Empty, Length = null }).ToList(); } }
private void AddItemToPlaylist(PlaylistMediaViewModel droppedVm, int droppedIndex) { if (droppedIndex > PlayListItems.Count()) { PlayListItems.Add(droppedVm); } else { PlayListItems.Insert(droppedIndex, droppedVm); } }
protected async Task Play() { if (SelectedPlayListItem == null) { SelectedPlayListItem = PlayListItems.FirstOrDefault(); } if (SelectedPlayListItem != null) { await Player.PlayAsync(SelectedPlayListItem.Index, CancellationToken.None); } }
private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs e) { CheckBox checkBox = (CheckBox)sender; var selectitem = checkBox.BindingContext.ToString(); item = selectitem; if (PlayListItems == null) { PlayListItems = new ObservableCollection <string>(); } if (checkBox.IsChecked == true) { PlayListItems.Add(item); } else if (checkBox.IsChecked == false) { PlayListItems.Remove(item); } }
private async void Button_Clicked(object sender, EventArgs e) { var listname = Listname.Text; string result = String.Join(",", PlayListItems.ToArray()); var documents = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)); var filename = System.IO.Path.Combine(documents, listname + ".rtf"); if (!File.Exists(filename)) { File.WriteAllText(filename, result); } else { File.WriteAllText(filename, result); } playlist.Listload(); await Navigation.PopAsync(); }
private async void getPlaylist() { //show progress indicator setProgressIndicator(true); SystemTray.ProgressIndicator.Text = "Getting your Tweet Mix"; try { //set an int as the id int id = 0; //build twitter url string url = twitter.getUrl(username, apiAttempt); //call twitter vaI base api class, we only want the response code at this point string apiResponse = await twitter.Call(url); //if the response did not come back null or contain an error code if (apiResponse != null || apiResponse.Contains("Error: ")) { //use json.net to turn json into an opject TwitterItems apiData = JsonConvert.DeserializeObject <TwitterItems>(apiResponse); //loop through and set everything to the list foreach (Status data in apiData.statuses) { PlayListItems items = new PlayListItems(); //add id to list items.ID = id.ToString(); //add twitter details to list items.Message = data.text; items.ProfileImage = data.user.profile_image_url; items.Username = data.user.name; //go spilt the message via the Song class Song song = spiltMessage(data.text); //add those values to the list items.ArtistName = song.Artist; items.SongName = song.Track; //now we need the artowrk so go get it from spotify as its more reliable SpotifyApi spotify = new SpotifyApi(); //build a url of the songname to go ask spotify for its details string spotifySearchUrl = spotify.BuildSearchUrl(song.Track); string response = await spotify.Call(spotifySearchUrl); //add in method so that calls can be used again if (response != null) { List <SpotifyItem> tracks = new List <SpotifyItem>(); SpotifyItem spotifyApiData = JsonConvert.DeserializeObject <SpotifyItem>(response); //call the spotify embed api to go get artwork string spotifyArtowrkUrl = spotify.buildEmbedUrl(spotifyApiData.tracks[0].href); string artworkResponse = await spotify.Call(spotifyArtowrkUrl); SpotifyImageItems imageData = JsonConvert.DeserializeObject <SpotifyImageItems>(artworkResponse); items.AlbumArtworkUrl = imageData.thumbnail_url; } Items.Add(items); id++; } } else if (apiResponse.Contains("Error: ")) { //lets go see what error it is int errorCode = twitter.getCorrectError(apiResponse); if (errorCode == 429 && apiAttempt < 3) { setProgressIndicator(false); //call again; callAgain(); } else { string errorMessage = twitter.ErrorMesssage(errorCode); showError(errorMessage); callAgain(); setProgressIndicator(false); } } setProgressIndicator(false); } catch (UnauthorizedAccessException) { MessageBox.Show("Wifi is disabled in phone settings"); } catch (Exception e) { MessageBox.Show(e.Message); setProgressIndicator(false); callAgain(); } setDataContext(); }