/// <inheritdoc /> public bool PlayIndex(int index) { var success = false; _api.NowPlayingList_QueryFilesEx(null, out var tracks); if (index >= 0 || index < tracks.Length) { success = _api.NowPlayingList_PlayNow(tracks[index - 1]); } return(success); }
private ObservableCollection <Song> GetNowPlayingList() { ObservableCollection <Song> instance = new ObservableCollection <Song>(); string[] fileUrls = new string[0]; mbApiInterface.NowPlayingList_QueryFilesEx(null, ref fileUrls); foreach (var url in fileUrls) { Song song = new Song(); song.Url = url; song.Name = mbApiInterface.Library_GetFileTag(url, MetaDataType.TrackTitle); instance.Add(song); } return(new ObservableCollection <Song>(instance.OrderBy(x => x.Name))); }
public async Task LoadSong(string hashed, string songFileExt) { string filetype = mbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.Kind).Replace(" audio file", ""); string samplerate = mbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.SampleRate); string bitrate = mbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.Bitrate); string channels = mbApiInterface.NowPlaying_GetFileProperty(FilePropertyType.Channels); string properties = ""; string nextSong = mbApiInterface.NowPlayingList_GetFileTag(mbApiInterface.NowPlayingList_GetNextIndex(1), MetaDataType.TrackTitle) + " by " + mbApiInterface.NowPlayingList_GetFileTag(mbApiInterface.NowPlayingList_GetNextIndex(1), MetaDataType.Artist); nextSong = nextSong == " by " || nextSong == null ? "End of List" : nextSong; if (filetype == "FLAC") { using (FlacFile file = new FlacFile(mbApiInterface.NowPlaying_GetFileUrl())) { properties = filetype + " " + file.StreamInfo.BitsPerSample.ToString() + " bit, " + samplerate + ", " + bitrate + ", " + channels; } } else { properties = filetype + " " + samplerate + ", " + bitrate + ", " + channels; } string[] temp = null; mbApiInterface.NowPlayingList_QueryFilesEx("", ref temp); int size = temp.Count(); try { await mediaChannel.LoadAsync( new MediaInformation() { ContentId = HttpUtility.UrlPathEncode(mediaContentURL + hashed + songFileExt), StreamType = StreamType.Buffered, Duration = mbApiInterface.NowPlaying_GetDuration() / 1000, Metadata = new MusicTrackMediaMetadata { Artist = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Artist), Title = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.TrackTitle), AlbumName = mbApiInterface.NowPlaying_GetFileTag(MetaDataType.Album), Images = new[] { new GoogleCast.Models.Image { Url = mediaContentURL + hashed + ".jpg" } }, }, CustomData = new Dictionary <string, string>() { { "Properties", properties }, { "Position", (mbApiInterface.NowPlayingList_GetCurrentIndex() + 1).ToString() + " / " + size.ToString() }, { "Next", nextSong } } }); filenameStack.Push(hashed.ToString()); } catch (OperationCanceledException) { Debug.WriteLine("Requested to close"); } catch (Exception e) { Debug.WriteLine(e.Message); } }