Exemple #1
0
        /// <summary>
        /// 从数据库读取任一歌单内容,返回歌单内所有音乐信息
        /// </summary>
        /// <param name="musicList"></param>
        /// <returns></returns>
        public MusicList GetMusicList(MusicList musicList)
        {
            try
            {
                string          sql = "SELECT * FROM musiclistinfo WHERE user_id = '" + musicList.User_Id + "' and Listname = '" + musicList.ListName + "'";
                MySqlDataReader rd  = Read(sql);
                while (rd.Read())
                {
                    string filename    = rd["Fileurl"].ToString().Replace("/", "\\");
                    string musicname   = rd["musicname"].ToString();
                    string musicsinger = rd["musicsinger"].ToString();
                    string musicalbum  = rd["musicalbum"].ToString();
                    Music  music       = new Music(musicname, musicsinger, musicalbum, filename);
                    musicList.Add(music);
                }
                rd.Close();
                return(musicList);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);

                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// 从本地读取歌单
        /// </summary>
        /// <returns></returns>
        public MusicList GetLocalMusicList(MusicList musicList)
        {
            try
            {
                FileInfo myFile;
                if (musicList.ListName.ToString() == "本地与下载")
                {
                    myFile = new FileInfo("../local/local.txt");
                }
                else
                {
                    myFile = new FileInfo("../local/playing.txt");
                }
                StreamReader sR       = myFile.OpenText();
                string       filename = "";
                string       nextLine;
                while ((nextLine = sR.ReadLine()) != null)
                {
                    filename += nextLine.TrimEnd('】').TrimStart('【').TrimEnd('\n');
                    if (nextLine.Last() == '】')
                    {
                        Music music = ReadLocalMusic(filename);
                        musicList.Add(music);
                        filename = "";
                    }
                }
                sR.Close();
                return(musicList);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);

                return(new MusicList());
            }
        }