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(); }
private void PlaylistImage_MouseDown(object sender, MouseButtonEventArgs e) { System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog(); // image filters open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp"; if (open.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // display image in picture box string sourceFile = open.FileName; string destFile = $@"{GeneralDataManagement.ImageFolderPath}\{System.IO.Path.GetFileName(sourceFile)}"; try { PlaylistImage.Source = new BitmapImage(new Uri(open.FileName)); PlaylistModel playlistToEdit = (this.DataContext as PlaylistInfoViewModel).PlaylistDetail; if (File.Exists(destFile) == false) { System.IO.File.Copy(sourceFile, destFile, true); } playlistToEdit.ImagePath = destFile.Replace($@"{GeneralDataManagement.ImageFolderPath}\", ""); SongDataAccess.UpdatePlaylist(playlistToEdit); playlistToEdit.ImagePath = System.IO.Path.GetFileName(open.FileName); } catch (Exception) { MessageBox.Show("Chỉnh sửa thất bại"); } } }
public PlaylistView() { InitializeComponent(); BtnAddPlaylist.ButtonClick += AddPlaylistButton_ButtonClick; WrapPanelListOfPlayList.Children.Add(BtnAddPlaylist); ListPlaylists = SongDataAccess.GetAllPlaylist(); UpdatePlaylistCard(); }
public static void AddNewSong(string song_path) { SongModel newSong = new SongModel(); var tfile = TagLib.File.Create(song_path); newSong.SongName = Path.GetFileName(song_path); newSong.SongLocation = song_path; 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; try { newSong.ContributingArtists = tfile.Tag.Artists[0]; } catch (Exception) { newSong.ContributingArtists = "unknow"; } 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(); newSong.SongLocation = newSong.SongLocation.Replace($@"{UserMusicFolderLocation}\", ""); SongDataAccess.InsertSongToDatabase(newSong); } catch (Exception) { } }
public static void RemoveInvalidSongFromDatabase() { List <SongModel> ListSong = SongDataAccess.GetAllUserSongList(); foreach (SongModel song in ListSong) { if (File.Exists($@"{GeneralDataManagement.UserMusicFolderLocation}\{song.SongLocation}") == false) { SongDataAccess.DeleteSongFromDatabase(song.SongKey); } } }
private void AddPlaylistButton_ButtonClick() { CreatePlaylistForm DialogAddNewPlaylist = new CreatePlaylistForm(); DialogAddNewPlaylist.ShowDialog(); switch (DialogAddNewPlaylist.DialogResult) { case true: PlaylistModel newPlaylist = new PlaylistModel(); newPlaylist.PlaylistKey = "PL" + MyUtilites.MyFunction.GenerateCode(); newPlaylist.PlaylistName = DialogAddNewPlaylist.PlaylistName; //di chuyển hình ảnh playlist của người dùng string ImageFilePath = DialogAddNewPlaylist.ImagePath; if (File.Exists(ImageFilePath)) { string sourceFile = ImageFilePath; string destFile = $@"{GeneralDataManagement.ImageFolderPath}\{System.IO.Path.GetFileName(sourceFile)}"; try { if (File.Exists(destFile) == false) { System.IO.File.Copy(sourceFile, destFile, true); } newPlaylist.ImagePath = destFile.Replace($@"{GeneralDataManagement.ImageFolderPath}\", ""); } catch (Exception) { } } SongDataAccess.InsertNewPlaylistToDatabase(newPlaylist); ListPlaylists.Add(newPlaylist); UpdatePlaylistCard(); break; case false: break; default: break; } }
public static List <SongModel> GetUpNextList() { List <SongModel> song_list = new List <SongModel>(); song_list = SongDataAccess.GetAllUserSongList(); //String Folder = @"C:\Users\19520\Music\NovapoMusee"; //String FileType = "*.mp3"; //DirectoryInfo dinfo = new DirectoryInfo(Folder); //FileInfo[] Files = dinfo.GetFiles(FileType); //foreach (FileInfo file in Files) //{ // //ListAudio.Items.Add(file.Name); // song_list.Add(new SongModel(file.FullName,file.Name,file.Name)); //} Console.WriteLine(); return(song_list); }
private void BtnSave_Click(object sender, RoutedEventArgs e) { TextRange range; FileStream fStream; if (File.Exists(LyricFilePath + ".lrc") == true) { fStream = new FileStream(LyricFilePath + ".lrc", FileMode.OpenOrCreate); range = new TextRange(RichTBLyricContent.Document.ContentStart, RichTBLyricContent.Document.ContentEnd); range.Save(fStream, DataFormats.Text); fStream.Close(); //save file format fStream = new FileStream(LyricFilePath + ".txt", FileMode.OpenOrCreate); range.Save(fStream, DataFormats.XamlPackage); fStream.Close(); } else { //save file text LyricFilePath = $@"{GeneralDataManagement.DatabaseFolderPath}\{songToUpdateLyric.Title}_lyric_{MyUtilites.MyFunction.GenerateCode()}"; fStream = new FileStream(LyricFilePath + ".lrc", FileMode.OpenOrCreate); range = new TextRange(RichTBLyricContent.Document.ContentStart, RichTBLyricContent.Document.ContentEnd); range.Save(fStream, DataFormats.Text); songToUpdateLyric.LyricPath = LyricFilePath.Replace($@"{GeneralDataManagement.DatabaseFolderPath}\", "") + ".lrc"; SongDataAccess.UpdateSong(songToUpdateLyric); fStream.Close(); //save file format fStream = new FileStream(LyricFilePath + ".txt", FileMode.OpenOrCreate); range.Save(fStream, DataFormats.XamlPackage); fStream.Close(); } }
public static void InitializeDatabase() { if (!Directory.Exists(UserMusicFolderLocation)) { return; } //MessageBox.Show("Tạo Database"); DatabaseFolderPath = $@"{UserMusicFolderLocation}\{DatabaseFolderName}"; DatabaseFilePath = $@"{UserMusicFolderLocation}\{DatabaseFolderName}\{DatabaseFileName}"; ImageFolderPath = $@"{UserMusicFolderLocation}\{DatabaseFolderName}\Image"; LyricFolderPath = $@"{UserMusicFolderLocation}\{DatabaseFolderName}\Lyric"; //tạo thư mục hình ảnh, lyric trong thư mục nhạc của người dùng Directory.CreateDirectory(LyricFolderPath); Directory.CreateDirectory(ImageFolderPath); //đưa hình ảnh favorite song vào folder image string sourceFile = $@"{ProjectDirectoryPath}\Assets\FavoriteSongImage.jpg"; string destFile = $@"{GeneralDataManagement.ImageFolderPath}\{System.IO.Path.GetFileName(sourceFile)}"; System.IO.File.Copy(sourceFile, destFile, true); //tạo thư mục database trong thư mục âm nhạc của người dùng Directory.CreateDirectory(DatabaseFolderPath); DirectoryInfo di = Directory.CreateDirectory(DatabaseFolderPath); di.Attributes = FileAttributes.Directory | FileAttributes.Hidden; //tạo database SQLiteConnection.CreateFile($@"{DatabaseFilePath}"); SongDataAccess.CreateRequiredTable(); }
public async Task<Song> CreateAsync(SongUpdateModel song) { await AlbumGetService.ValidateAsync(song); return await SongDataAccess.InsertAsync(song); }
public async Task <Song> UpdateAsync(SongUpdateModel song) { await AlbumGetService.ValidateAsync(song); return(await SongDataAccess.UpdateAsync(song)); }
public ListMusicDialogViewModel(string PLKey) { playlistKey = PLKey; allUserSongList = SongDataAccess.GetAllSongListWithPlaylistInfo(playlistKey); foreach (SongModel song in allUserSongList) { if (song.PlaylistKey != null) { song.IsInPlaylist = true; ListSongExistedInPlaylist.Add(song.SongKey); } } ListMusic = allUserSongList; SearchKeyword = ""; CheckToChooseSongCommand = new RelayCommand <object>( (p) => { return(true); }, (p) => { SongModel songToAddToPlaylist = p as SongModel; string songToAddToPlaylistKey = (p as SongModel).SongKey; //tìm xem trong check mới hay bỏ check int index = ListSongToAddPlaylist.FindIndex(e => (e == songToAddToPlaylistKey)); //trường hợp mới check if (index == -1) { ListSongToAddPlaylist.Add(songToAddToPlaylistKey); } //trường hợp bỏ check else { ListSongToAddPlaylist.RemoveAt(index); } }); SaveCommand = new RelayCommand <object>( (p) => { return(true); }, (p) => { foreach (string songKey in ListSongToAddPlaylist) { //nếu đã có trong data base thì bỏ ra khỏi database if (ListSongExistedInPlaylist.Exists(e => e == songKey)) { if (playlistKey == "FAVORITE_PLAYLIST") { SongDataAccess.RemoveSongFromFavorite(songKey); } else { SongDataAccess.DeleteSongFromPlaylist(songKey, playlistKey); } } else { if (playlistKey == "FAVORITE_PLAYLIST") { SongDataAccess.InsertSongToFavorite(songKey); } else { SongDataAccess.InsertSongToPlaylist(songKey, playlistKey); } } } MusicInPlaylistControl.UserSongListHasUpdated(); }); }
public ListMusicInPlaylistViewModel() { PlayAllCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { PlayAllSongRequest(); }); AddToPlaylistCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { }); MusicInPlaylistControl.CurrentSongListChange += MyMusicControl_CurrentSongListChange; 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); if (PlaylistInfoViewModel.currentPlaylistKey == "FAVORITE_PLAYLIST") { MusicInPlaylistControl.UserSongListHasUpdated(); } else { ButtonFavoriteSongClick(index, 0); } } else { //thích SongDataAccess.InsertSongToFavorite(songSelected.SongKey); if (PlaylistInfoViewModel.currentPlaylistKey == "FAVORITE_PLAYLIST") { MusicInPlaylistControl.UserSongListHasUpdated(); } else { ButtonFavoriteSongClick(index, 1); } } }); PlayNowCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { SongModel songSelected = p as SongModel; int index = CurrentSongList.FindIndex(e => (e.SongKey == songSelected.SongKey)); PlayNowRequest(index); }); 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); }); }
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; }