예제 #1
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            if (File.Exists(TbSongLyric.Text) == true)
            {
                try
                {
                    //di chuyen file loi bai hat vao database
                    string sourceFile      = TbSongLyric.Text;
                    string destinationFile = $@"{GeneralDataManagement.LyricFolderPath}\{System.IO.Path.GetFileName(sourceFile)}";
                    File.Copy(sourceFile, destinationFile, true);
                    SongToEdit.LyricPath = System.IO.Path.GetFileName(sourceFile);
                    SongDataAccess.UpdateSong(SongToEdit);
                    MyMusicControl.UserSongListHasUpdated();
                }
                catch (Exception)
                {
                    MessageBox.Show("Them bai hat that bai");
                }
            }
            else
            {
                SongToEdit.LyricPath = "";
                SongDataAccess.UpdateSong(SongToEdit);
            }

            this.Close();
        }
예제 #2
0
 private void BtnExit_Click(object sender, RoutedEventArgs e)
 {
     UpNextListModel.IsEditingLyric = false;
     MyMusicControl.UserSongListHasUpdated();
     MusicInPlaylistControl.UserSongListHasUpdated();
     ChangePage("MyMusic");
 }
예제 #3
0
        private void BtnChangeFolder_Click(object sender, RoutedEventArgs e)
        {
            ChooseMusicFolderForm form_choose_music_folder = new ChooseMusicFolderForm();

            form_choose_music_folder.UserPath = GeneralDataManagement.UserMusicFolderLocation;
            if (form_choose_music_folder.ShowDialog() == true)
            {
                //ghi đường dẫn thư mục vào file MusicLocation.txt;
                System.IO.File.WriteAllText(GeneralDataManagement.FileLinkMusicLocationPath, GeneralDataManagement.UserMusicFolderLocation);

                if (IndeeMusee.DataManager.GeneralDataManagement.IsHavingDatabaseInUserMusicFolder() == false)
                {
                    IndeeMusee.DataManager.GeneralDataManagement.InitializeDatabase();
                    IndeeMusee.DataManager.GeneralDataManagement.FindAndImportSongToDatabase();
                }

                IndeeMusee.DataManager.GeneralDataManagement.RemoveInvalidSongFromDatabase();

                MyMusicControl.UserSongListHasUpdated();

                ChangePage("MyMusic");
            }
            else
            //nếu không chọn thư mục mà tắt form đi
            {
            }
        }
예제 #4
0
 private void BtnExit_Click(object sender, RoutedEventArgs e)
 {
     if ((this.DataContext as LyricEditorVersion2ViewModel).SaveStatus == "SAVE*")
     {
         MessageBoxResult messageBoxResult = MessageBox.Show($@"Nội dung chưa được lưu, bạn có chắc chắn muốn thoát ?", "Thông báo", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
         if (messageBoxResult == MessageBoxResult.No)
         {
             return;
         }
     }
     UpNextListModel.IsEditingLyric = false;
     MyMusicControl.UserSongListHasUpdated();
     MusicInPlaylistControl.UserSongListHasUpdated();
     ChangePage("MyMusic");
 }
예제 #5
0
        public MyMusicViewModel()
        {
            PlayNowCommand = new RelayCommand <object>(
                (p) =>
            {
                return(NowPlayingSong.LoadSongStatus);
            },
                (p) =>
            {
                SongModel songSelected = p as SongModel;
                int index = CurrentSongList.FindIndex(e => (e.SongKey == songSelected.SongKey));
                PlayNowRequest(index);
            });

            FavoriteCommand = new RelayCommand <object>((p) => { return(true); },
                                                        (p) =>
            {
                SongModel songSelected = p as SongModel;
                int index = CurrentSongList.FindIndex(e => (e.SongKey == songSelected.SongKey));
                if (songSelected.IsFavorite == 1)
                {
                    //bỏ thích
                    SongDataAccess.RemoveSongFromFavorite(songSelected.SongKey);
                    ButtonFavoriteSongClick(index, 0);
                }
                else
                {
                    //thích
                    SongDataAccess.InsertSongToFavorite(songSelected.SongKey);
                    ButtonFavoriteSongClick(index, 1);
                }
            });

            MoreControlCommand = new RelayCommand <object>((p) => { return(true); },
                                                           (p) =>
            {
                SongModel songSelected = p as SongModel;
                MiniTool.SongDetail    = songSelected;
            });
            AddToPlayingQueueCommand = new RelayCommand <object>((p) => { return(true); },
                                                                 (p) =>
            {
                SongModel songSelected = p as SongModel;
                int index = CurrentSongList.FindIndex(e => (e.SongKey == songSelected.SongKey));
                AddToPlayingQueueRequest(index);
            });

            AddSongCommand = new RelayCommand <object>((p) => { return(true); }, (p) =>
            {
                System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
                openFileDialog.Filter           = "All Supported Audio | *.mp3; *.wma | MP3s | *.mp3 | WMAs | *.wma| WAVs | *.wav";
                openFileDialog.InitialDirectory = GeneralDataManagement.UserMusicFolderLocation;
                openFileDialog.Multiselect      = true;
                System.Windows.Forms.DialogResult dialogResult = openFileDialog.ShowDialog();
                if (dialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    // Read the files
                    foreach (String file in openFileDialog.FileNames)
                    {
                        try
                        {
                            SongModel newSong = new SongModel();

                            if (SongDataAccess.CheckSongExistInDatabase(Path.GetFileName(file)))
                            {
                                continue;
                            }

                            var tfile = TagLib.File.Create(file);

                            newSong.SongName = Path.GetFileName(file);

                            if (tfile.Tag.Title == null)
                            {
                                tfile.Tag.Title = newSong.SongName;
                            }
                            if (tfile.Tag.Title.Trim() == "")
                            {
                                tfile.Tag.Title = newSong.SongName;
                            }

                            newSong.Title = tfile.Tag.Title;

                            newSong.Album = tfile.Tag.Album;
                            if (tfile.Tag.Artists.Length != 0)
                            {
                                newSong.ContributingArtists = tfile.Tag.Artists[0];
                            }
                            else
                            {
                                newSong.ContributingArtists = "unknown";
                            }

                            if (tfile.Tag.Genres.Length != 0)
                            {
                                newSong.Genre = tfile.Tag.Genres[0];
                            }
                            else
                            {
                                newSong.Genre = "unknown";
                            }

                            TimeSpan songLength = TimeSpan.FromSeconds(tfile.Properties.Duration.TotalSeconds);
                            newSong.Length      = songLength.ToString(@"mm\:ss");

                            tfile.Tag.InitialKey = MyUtilites.MyFunction.GenerateCode();
                            newSong.SongKey      = tfile.Tag.InitialKey;

                            try
                            {
                                tfile.Save();
                                //di chuyển bài hát vào thư mục nhạc của người dùng
                                string sourceFile = file;
                                string destFile   = GeneralDataManagement.UserMusicFolderLocation + "/" + newSong.SongName;
                                System.IO.File.Copy(sourceFile, destFile, true);
                                newSong.SongLocation = destFile.Replace(GeneralDataManagement.UserMusicFolderLocation, "");
                                SongDataAccess.InsertSongToDatabase(newSong);
                            }
                            catch (Exception)
                            {
                                MessageBox.Show("Thêm bài hát thất bại");
                            }
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Thêm bài hát thất bại");
                        }
                    }
                }
                ;
                MyMusicControl.UserSongListHasUpdated();
                AddNewSongEvent();
            });
            PlayAllCommand       = new RelayCommand <object>((p) => { return(true); }, (p) => { PlayAllSongRequest(); });
            AddToPlaylistCommand = new RelayCommand <object>((p) => { return(true); }, (p) =>
            {
                SongModel songSelected = p as SongModel;
                int index = CurrentSongList.FindIndex(e => (e.SongKey == songSelected.SongKey));
                AddToPlayingQueueRequest(index);
            });

            MyMusicControl.CurrentSongListChange += MyMusicControl_CurrentSongListChange;

            MyMusicControl.FetchUserSongListData();
            currentSongList = MyMusicControl.CurrentSongList;
        }