/// <summary>
        ///     Removes tracks from a play-list.
        /// </summary>
        /// <param name="playlist">The play-list.</param>
        /// <param name="tracks">The tracks to remove.</param>
        public static void RemoveTracksFromPlaylist(Playlist playlist, List<Track> tracks)
        {
            if (tracks == null || playlist == null) return;

            foreach (var track in tracks.Where(track => playlist.Tracks.Contains(track)))
            {
                playlist.Tracks.Remove(track);
            }
            SavePlaylist(playlist);
        }
        /// <summary>
        ///     Adds tracks to play-list.
        /// </summary>
        /// <param name="playlist">The play-list.</param>
        /// <param name="tracks">The tracks.</param>
        public static void AddTracksToPlaylist(Playlist playlist, List<Track> tracks)
        {
            if (tracks == null || playlist == null) return;

            foreach (var track in tracks.Where(track => !playlist.Tracks.Contains(track)))
            {
                playlist.Tracks.Add(track);
            }
            SavePlaylist(playlist);
        }
        /// <summary>
        ///     Saves the play-list.
        /// </summary>
        /// <param name="playlist">The play-list.</param>
        public static void SavePlaylist(Playlist playlist)
        {
            if (playlist == null) return;
            if (playlist.Tracks.Count == 0)
            {
                try
                {
                    File.Delete(playlist.Filename);
                }
                catch
                {
                    // ignored
                }
                return;
            }

            var content = new StringBuilder();
            content.AppendLine("#EXTM3U");
            foreach (var track in playlist.Tracks)
            {
                content.AppendLine("#EXTINF:" + track.FullLength.ToString("0") + "," + track.Artist + " - " +
                                   track.Title);

                content.AppendLine(track.Filename);
            }

            File.WriteAllText(playlist.Filename, content.ToString(), Encoding.UTF8);
        }
        /// <summary>
        ///     Creates the new play-list.
        /// </summary>
        /// <param name="playlistName">Name of the play-list.</param>
        /// <returns></returns>
        public static Playlist CreateNewPlaylist(string playlistName)
        {
            playlistName = FileSystemHelper.StripInvalidFileNameChars(playlistName.Trim());

            var playlist = Playlists.FirstOrDefault(p => p.Name.ToLower() == playlistName.ToLower());
            if (playlist != null) return playlist;

            playlist = new Playlist {Name = playlistName};
            playlist.Filename = Path.Combine(PlaylistFolder, playlist.Name) + ".m3u";
            playlist.Tracks = new List<Track>();

            Playlists.Add(playlist);

            return playlist;
        }
        /// <summary>
        /// Loads a play-list.
        /// </summary>
        /// <param name="playlistFile">The play-list file.</param>
        /// <param name="library">The library.</param>
        /// <returns>
        /// A play-list object
        /// </returns>
        public static Playlist LoadPlaylist(string playlistFile, Library library)
        {
            var playlist = new Playlist
            {
                Filename = playlistFile,
                Name = Path.GetFileNameWithoutExtension(playlistFile)
            };
            playlist.Name = StringHelper.TitleCase(playlist.Name);

            var tracks = from entry 
                         in AudioEngine.Helpers.PlaylistHelper.GetPlaylistEntries(playlistFile)
                         let entryTitle = entry.Title.ToLower()
                         let entryArtist = entry.Artist.ToLower()
                         select library.LoadTrack(entry.Path) ?? library.GetTrack(entryArtist, entryTitle, 0) 
                         into track
                         where track != null
                         select track;

            playlist.Tracks.AddRange(tracks);

            return playlist;
        }
Exemplo n.º 6
0
 public void SavePlaylist(Playlist playlist)
 {
     PlaylistHelper.SavePlaylist(playlist);
 }
Exemplo n.º 7
0
 public void RemoveTracksFromPlaylist(Playlist playlist, List<Track> tracks)
 {
     PlaylistHelper.RemoveTracksFromPlaylist(playlist, tracks);
 }
Exemplo n.º 8
0
 public void AddTracksToPlaylist(Playlist playlist, List<Track> tracks)
 {
     PlaylistHelper.AddTracksToPlaylist(playlist, tracks);
 }
 /// <summary>
 ///     Saves the play-list.
 /// </summary>
 /// <param name="playlistFile">The play-list file.</param>
 public void SavePlaylist(string playlistFile)
 {
     try
     {
         var playlist = new Playlist
         {
             Filename = playlistFile,
             Tracks = GetTracks()
         };
         Library.SavePlaylist(playlist);
         CurrentPlaylistFile = playlistFile;
     }
     catch (Exception e)
     {
         HandleException(e);
     }
 }
 /// <summary>
 ///     Queues a play-list.
 /// </summary>
 /// <param name="playlist">The play-list.</param>
 public void QueuePlaylist(Playlist playlist)
 {
     try
     {
         TrackModels.Clear();
         QueueTracks(playlist.Tracks);
     }
     catch (Exception e)
     {
         HandleException(e);
     }
 }