Example #1
0
        public void AddToDefaultList()
        {
            if ("默认列表" == PlayerList.PreListTitle)
            {
                Toast.Show("添加失败!歌单相同!", Toast.InfoType.Error); return;
            }

            if (MusicInfos is null)
            {
                return;
            }
            //在默认列表数据库中加入音乐
            var dlm = new DefaultListManager();
            var mim = new MusicInfoManager();

            foreach (var item in MusicInfos)
            {
                dlm.Insert(new DefaultListModel(item.Id));
                mim.Insert(new MusicInfoModel(item));
            }

            //如果当前BasePage的DataGrid展示的是默认列表,进行刷新
            ViewModelManager.BasePageViewModel.RefreshShowList("默认列表");
            Toast.Show("添加成功!", Toast.InfoType.Success);
        }
        public void ClickScanFolderExecute()
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择扫描音乐文件夹";
            if (dialog.ShowDialog() != DialogResult.OK||dialog.SelectedPath==string.Empty)
            {
                return;
            }
            var files = Directory.GetFiles(dialog.SelectedPath);
            int amount = 0;
            foreach (var item in files)
            {
                if(Path.GetExtension(item)!=".mp3"&& Path.GetExtension(item) != ".wav") { continue; }
                TagLib.Tag tag = TagLib.File.Create(item).Tag;

                //获取艺术家
                string artists = string.Empty;
                foreach (var ar in tag.AlbumArtists)
                {
                    artists += "、" + ar;
                }
                if (artists != string.Empty) { artists = artists.Substring(1); }

                string id = BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(File.ReadAllBytes(item))).Replace("-", "");

                bool result = new MusicInfoManager().Insert(new MusicInfoModel
                {
                    Album = tag.Album==null?"":tag.Album,
                    Artists = artists,
                    Name = string.IsNullOrEmpty(tag.Title) ? Path.GetFileNameWithoutExtension(item) : tag.Title,
                    CoverId = string.Empty,
                    Origin = Enum.MusicSource.Local,
                    SourceName = "本地音乐",
                    Id = id
                });

                //检查id是否重复
                if (result)
                {
                    new LocalListManager().Insert(new LocalListModel
                    {
                        FilePath = item,
                        Id = id
                    });
                    amount++;
                }
            }

            Toast.Show($"共添加本地音乐{amount}首!", Toast.InfoType.Success);
            ViewModelManager.BasePageViewModel.ClickLocalMusicExecute();
        }
        public void ClickChooseMusicExecute()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Multiselect = false;
            dialog.Title = "请选择音乐文件";
            dialog.Filter = "mp3文件(*.mp3)|*.mp3|wav文件(*.wav)|*.wav";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string path = dialog.FileName;
                TagLib.Tag tag = TagLib.File.Create(path).Tag;

                //获取艺术家
                string artists = string.Empty;
                foreach (var item in tag.AlbumArtists)
                {
                    artists += "、" + item;
                }
                if (artists != string.Empty) { artists=artists.Substring(1); }

                string id = BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(File.ReadAllBytes(path))).Replace("-","");
                
                bool result=new MusicInfoManager().Insert(new MusicInfoModel
                {
                    Album = tag.Album,
                    Artists =artists,
                    Name = tag.Title==string.Empty?Path.GetFileNameWithoutExtension(path):tag.Title,
                    CoverId = string.Empty,
                    Origin = Enum.MusicSource.Local,
                    SourceName = "本地音乐",
                    Id = id
                });

                //检查id是否重复
                if (result)
                {
                    new LocalListManager().Insert(new LocalListModel
                    {
                        FilePath = path,
                        Id = id
                    });
                    Toast.Show("添加本地音乐成功!", Toast.InfoType.Success);
                    ViewModelManager.BasePageViewModel.ClickLocalMusicExecute();
                }
                else
                {
                    Toast.Show("本地音乐已存在相同音乐!", Toast.InfoType.Error);
                }
                
            }
        }
Example #4
0
        public void ClickLocalMusicExecute()
        {
            ListId = string.Empty;
            MusicInfos.Clear();
            var list = new LocalListManager().GetList();

            list.ForEach(item =>
            {
                var mim   = new MusicInfoManager();
                var music = mim.Find(item.Id);
                MusicInfos.Add(music.ToIMusic());
            });
            PlayerList.SetPreList(MusicInfos, "本地音乐");
            DataGridAnimation();
        }
Example #5
0
        public void DefaultListExecute()
        {
            ListId = string.Empty;
            var orm  = new DefaultListManager();
            var list = orm.GetList();

            MusicInfos.Clear();
            list.ForEach(item =>
            {
                var mif   = new MusicInfoManager();
                var music = mif.Find(item.Id);
                MusicInfos.Add(music.ToIMusic());
            });
            PlayerList.SetPreList(MusicInfos, "默认列表");
            DataGridAnimation();
        }
Example #6
0
        public void ClickCustomList(object parameter)
        {
            ListId = string.Empty;
            string title = parameter.ToString();
            var    ls    = new CustomListManager().GetList();

            MusicInfos.Clear();
            ls.ForEach(item =>
            {
                if (item.Title == title)
                {
                    var mim   = new MusicInfoManager();
                    var music = mim.Find(item.Id);
                    MusicInfos.Add(music.ToIMusic());
                }
            });
            PlayerList.SetPreList(MusicInfos, title);
            DataGridAnimation();
        }
Example #7
0
        public void ClickPlatformList(object parameter)
        {
            string id = parameter.ToString();

            ListId = id;
            var ls = new PlatformListManager().GetList();

            MusicInfos.Clear();
            ls.ForEach(item =>
            {
                if (item.PlatformId == id)
                {
                    var mim   = new MusicInfoManager();
                    var music = mim.Find(item.MusicId);
                    MusicInfos.Add(music.ToIMusic());
                }
            });
            PlayerList.SetPreList(MusicInfos, new PlatformInfoManager().Find(id).Title);
            DataGridAnimation();
        }
Example #8
0
        public void AddToCustomList(object parameter)
        {
            if (parameter.ToString() == PlayerList.PreListTitle)
            {
                Toast.Show("添加失败!歌单相同!", Toast.InfoType.Error); return;
            }
            if (menuParameter is null)
            {
                return;
            }
            //将音乐加入到自定义列表数据库
            var orm = new CustomListManager();

            orm.Insert(new CustomListModel(parameter.ToString(), (menuParameter as IMusic).Id));
            var mim = new MusicInfoManager();

            mim.Insert(new MusicInfoModel(menuParameter as IMusic));
            ViewModelManager.BasePageViewModel.RefreshShowList(parameter.ToString());
            Toast.Show("添加成功!", Toast.InfoType.Success);
        }
Example #9
0
 public void RefreshShowList(string title)
 {
     //如果当前BasePage的DataGrid展示的是默认列表,进行刷新
     if (PlayerList.PreListTitle != title)
     {
         return;
     }
     if (ListId == string.Empty)
     {
         if (title == "默认列表")
         {
             var orm  = new DefaultListManager();
             var list = orm.GetList();
             MusicInfos.Clear();
             list.ForEach(item =>
             {
                 var mif   = new MusicInfoManager();
                 var music = mif.Find(item.Id);
                 MusicInfos.Add(music.ToIMusic());
             });
         }
         else if (title == "本地音乐")
         {
             MusicInfos.Clear();
             var list = new LocalListManager().GetList();
             list.ForEach(item =>
             {
                 var mim   = new MusicInfoManager();
                 var music = mim.Find(item.Id);
                 MusicInfos.Add(music.ToIMusic());
             });
         }
         else
         {
             var ls = new CustomListManager().GetList();
             MusicInfos.Clear();
             ls.ForEach(item =>
             {
                 if (item.Title == title)
                 {
                     var mim   = new MusicInfoManager();
                     var music = mim.Find(item.Id);
                     MusicInfos.Add(music.ToIMusic());
                 }
             });
         }
     }
     else
     {
         var ls = new PlatformListManager().GetList();
         MusicInfos.Clear();
         ls.ForEach(item =>
         {
             if (item.PlatformId == ListId)
             {
                 var mim   = new MusicInfoManager();
                 var music = mim.Find(item.MusicId);
                 MusicInfos.Add(music.ToIMusic());
             }
         });
     }
 }