public void RefreshPlaylist(Playlist playlist) { Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => { _playlist = playlist; listViewPlaylist.Items.Clear(); listViewPlaylistAlbumArt.Items.Clear(); string currentAlbum = string.Empty; int songCount = 0; foreach (var item in _playlist.Items) { // Add only one row per album (to do: expose row height in viewmodel) songCount++; string album = string.Format("{0}_{1}", item.AudioFile.ArtistName, item.AudioFile.AlbumTitle).ToUpper(); if (string.IsNullOrEmpty(currentAlbum)) { currentAlbum = album; } else if (album != currentAlbum) { //Console.WriteLine("PlaylistWindow - RefreshPlaylists - Album: {0} SongCount: {1}", album, songCount); var listViewItem = new ListViewItem(); listViewItem.Background = new LinearGradientBrush(Colors.HotPink, Colors.Yellow, 90); listViewItem.Height = (songCount - 1) * 24; listViewItem.Content = string.Format("{0}/{1}", (songCount - 1), currentAlbum); listViewPlaylistAlbumArt.Items.Add(listViewItem); currentAlbum = album; songCount = 1; } listViewPlaylist.Items.Add(item); } })); }
/// <summary> /// Loads a playlist (from any of the following formats: M3U, M3U8, PLS and XSPF). /// Note: long playlists may take a while to load using this method! /// </summary> /// <param name="filePath">Playlist file path</param> /// <returns>Playlist</returns> public static Playlist LoadPlaylist(string filePath) { var playlist = new Playlist(); var files = new List<string>(); if (filePath.ToUpper().Contains(".M3U")) { playlist.Format = PlaylistFileFormat.M3U; files = PlaylistHelper.LoadM3UPlaylist(filePath); } else if (filePath.ToUpper().Contains(".M3U8")) { playlist.Format = PlaylistFileFormat.M3U8; files = PlaylistHelper.LoadM3UPlaylist(filePath); } else if (filePath.ToUpper().Contains(".PLS")) { playlist.Format = PlaylistFileFormat.PLS; files = PlaylistHelper.LoadPLSPlaylist(filePath); } else if (filePath.ToUpper().Contains(".XSPF")) { playlist.Format = PlaylistFileFormat.XSPF; files = PlaylistHelper.LoadXSPFPlaylist(filePath); } else if (filePath.ToUpper().Contains(".ASX")) { playlist.Format = PlaylistFileFormat.ASX; } if (files == null || files.Count == 0) throw new Exception("Error: The playlist is empty or does not contain any valid audio file paths!"); playlist.Clear(); playlist.FilePath = filePath; playlist.AddItems(files); playlist.First(); return playlist; }
public void RefreshPlaylist(Playlist playlist) { RunOnUiThread(() => { }); }
public void ImportPlaylist(Playlist playlist) { _control.ImportPlaylist(playlist); }
public void RefreshPlaylist(Playlist playlist) { RunOnUiThread(() => { //_lblPlaylistCount.Text = string.Format("{0}/{1}", playlist.CurrentItemIndex+1, playlist.Items.Count); _lblPlaylistCount.Text = string.Format("{0} items", playlist.Items.Count); //ShowMiniPlaylist(); }); }
/// <summary> /// Saves a playlist to a specific path using the XSPF playlist format. /// </summary> /// <param name="playlistFilePath">Playlist file path</param> /// <param name="playlist">Playlist object</param> /// <param name="useRelativePaths">Use relative paths</param> public static void SaveXSPFPlaylist(string playlistFilePath, Playlist playlist, bool useRelativePaths) { XDocument doc = null; string playlistPath = Path.GetDirectoryName(playlistFilePath); try { doc = new XDocument(); XNamespace ns = "http://xspf.org/ns/0/"; // Create basic elements XElement elementPlaylist = new XElement(ns + "playlist"); XElement elementTrackList = new XElement(ns + "trackList"); // Set playlist attributes XAttribute attributePlaylistVersion = new XAttribute("version", 1); elementPlaylist.Add(attributePlaylistVersion); for (int a = 0; a < playlist.Items.Count; a++) { // Create elements XElement elementTrack = new XElement(ns + "track"); XElement elementTitle = new XElement(ns + "title", playlist.Items[a].AudioFile.Title); // Check if paths are relative XElement elementLocation = null; if (useRelativePaths) { // Write relative file path elementLocation = new XElement(ns + "location", "file:///" + playlist.Items[a].AudioFile.FilePath.Replace(playlistPath + "\\", "").Replace("\\","/")); } else { // Write absolute file path elementLocation = new XElement(ns + "location", "file:///" + playlist.Items[a].AudioFile.FilePath.Replace("\\", "/")); } // Add elements elementTrack.Add(elementTitle); elementTrack.Add(elementLocation); elementTrackList.Add(elementTrack); } // Add elements elementPlaylist.Add(elementTrackList); doc.Add(elementPlaylist); // Save playlist to file #if !PCL && !WINDOWSSTORE && !WINDOWS_PHONE doc.Save(playlistFilePath); #endif } catch (Exception ex) { throw new Exception("Error saving XSPF playlist!", ex); } finally { doc = null; } }
/// <summary> /// Saves a playlist to a specific path using the PLS playlist format. /// </summary> /// <param name="playlistFilePath">Playlist file path</param> /// <param name="playlist">Playlist object</param> /// <param name="useRelativePaths">Use relative paths</param> public static void SavePLSPlaylist(string playlistFilePath, Playlist playlist, bool useRelativePaths) { StreamWriter writer = null; #if WINDOWSSTORE #else try { string playlistPath = Path.GetDirectoryName(playlistFilePath); writer = new StreamWriter(playlistFilePath); // Write header writer.WriteLine("[playlist]"); writer.WriteLine(); for(int a = 0; a < playlist.Items.Count; a++) { if (useRelativePaths) writer.WriteLine("File" + (a + 1).ToString() + "=" + playlist.Items[a].AudioFile.FilePath.Replace(playlistPath + "\\", "")); else writer.WriteLine("File" + (a + 1).ToString() + "=" + playlist.Items[a].AudioFile.FilePath); // Write title writer.WriteLine("Title" + (a + 1).ToString() + "=" + playlist.Items[a].AudioFile.Title); // Write spacer writer.WriteLine(); } // Write fotter writer.WriteLine("NumberOfEntries=" + playlist.Items.Count.ToString()); writer.WriteLine("Version=2"); } catch (Exception ex) { throw new Exception("Error saving PLS playlist!", ex); } finally { if (writer != null) writer.Close(); } #endif }
/// <summary> /// Saves a playlist to a specific path using the M3U/M3U8 playlist format. /// </summary> /// <param name="playlistFilePath">Playlist file path</param> /// <param name="playlist">Playlist object</param> /// <param name="useUTF8Encoding">Use UTF8 encoding (instead of ASCII)</param> /// <param name="useRelativePaths">Use relative paths</param> public static void SaveM3UPlaylist(string playlistFilePath, Playlist playlist, bool useRelativePaths, bool useUTF8Encoding) { StreamWriter writer = null; #if WINDOWSSTORE #else try { string playlistPath = Path.GetDirectoryName(playlistFilePath); // Check for UTF8 if (useUTF8Encoding) writer = new StreamWriter(playlistFilePath, false, Encoding.UTF8); #if !PCL && !WINDOWSSTORE && !WINDOWS_PHONE else writer = new StreamWriter(playlistFilePath, false, Encoding.ASCII); #endif writer.WriteLine("#EXTM3U"); foreach (PlaylistItem item in playlist.Items) { if (useRelativePaths) writer.WriteLine(item.AudioFile.FilePath.Replace(playlistPath + "\\", "")); else writer.WriteLine(item.AudioFile.FilePath); } } catch (Exception ex) { throw new Exception("Error saving M3U playlist!", ex); } finally { if (writer != null) writer.Close(); } #endif }
protected virtual void PreparePlaylist() { Playlist = new Playlist(); for (int a = 0; a < Config.AudioFilePaths.Count; a++) Playlist.AddItem(new PlaylistItem(new AudioFile(Config.AudioFilePaths[a]))); }
public void RefreshPlaylist(Playlist playlist) { RunOnUiThread(() => { _playlist = playlist; _itemListAdapter.SetData(_playlist); }); }
/// <summary> /// Imports playlist items as SongGridViewItems. /// </summary> /// <param name="playlist">Playlist</param> public void ImportPlaylist(Playlist playlist) { _mode = SongGridViewMode.Playlist; _items = new List<SongGridViewItem>(); foreach (var playlistItem in playlist.Items) { var item = new SongGridViewItem(); item.AudioFile = playlistItem.AudioFile; item.PlaylistItemId = playlistItem.Id; _items.Add(item); } // Reset scrollbar position VerticalScrollBar.Value = 0; _songCache = null; OnInvalidateVisual(); }
public void RefreshPlaylist(Playlist playlist) { Console.WriteLine("PlaylistWindowController - RefreshPlaylist"); _playlist = playlist; InvokeOnMainThread(() => songGridView.ImportPlaylist(playlist)); }
public void RefreshPlaylist(Playlist playlist) { InvokeOnMainThread(() => { _playlist = playlist; tableView.ReloadData(); }); }
public void UpdatePlaylist(Playlist playlist) { _gateway.UpdatePlaylist(playlist); }
public void InsertPlaylist(Playlist playlist) { _gateway.InsertPlaylist(playlist); }