Example #1
0
        /// <summary>
        /// Load information about playlist from file
        /// </summary>
        /// <param name="Path">Path to the file</param>
        /// <returns>Playlist</returns>
        public static Playlist LoadPlaylist(string Path)
        {
            try
            {
                FileStream fs = new FileStream(Path + ".plst", FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);

                string ID = br.ReadString();
                string Name = br.ReadString();
                int Count = br.ReadInt32();
                List<Song> Songs = new List<Song>();
                for (int i = 0; i < Count; i++)
                {
                    Songs.Add(LoadSong(br));
                }
                br.Close();
                fs.Close();
                Playlist playlist = new Playlist(ID, Name);
                foreach (Song song in Songs)
                    playlist.AddSong(song);
                return playlist;
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
Example #2
0
        /// <summary>
        /// Save playlist to the current path
        /// </summary>
        /// <param name="Path">Current path</param>
        /// <param name="playlist">Playlist</param>
        public static void SavePlaylist(string Path, Playlist playlist)
        {
            FileStream fs = new FileStream(Path + ".plst", FileMode.OpenOrCreate);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(playlist.ID);
            bw.Write(playlist.Name);

            bw.Write(playlist.Songs.Count);
            foreach (Song song in playlist.Songs)
            {
                SaveSong(bw, song);
            }

            bw.Close();
            fs.Close();
        }