/// <summary> /// Populates the library listbox from the current playlist /// </summary> private void populateMP3() { Music.Clear(); SQLHandler.selectQuery("SELECT * FROM MP3 ORDER BY artist ASC"); if (SQLHandler.read.HasRows) { MP3 song = new MP3(); while (SQLHandler.read.Read()) { song = new MP3(); song.MP3_ID = Convert.ToInt16(SQLHandler.read[0]); song.Title = SQLHandler.read[1].ToString(); song.Artist = SQLHandler.read[2].ToString(); song.Album = SQLHandler.read[3].ToString(); song.Location = SQLHandler.read[6].ToString(); song.Genre = SQLHandler.read[7].ToString(); try { string[] results = SQLHandler.read[4].ToString().Split(':'); int[] result = new int[] { Convert.ToInt16(results[0]), Convert.ToInt16(results[1]), Convert.ToInt16(results[2]) }; song.Duration = new TimeSpan(result[0], result[1], result[2]); } catch (Exception) { } try { song.Plays = Convert.ToInt16(SQLHandler.read[5]); } catch (Exception) { } Music.Add(song); } } MP3_Listbox.ItemsSource = Music; }
public MainWindow() { InitializeComponent(); populateMP3(); populateMP4(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += Timer_Tick; timer.Start(); currentPlaylist = new Playlist("Library"); SQLHandler.selectQuery("SELECT * FROM MP3"); if (SQLHandler.read.HasRows) { MP3 song = new MP3(); while (SQLHandler.read.Read()) { song = new MP3(); song.MP3_ID = Convert.ToInt16(SQLHandler.read[0]); song.Title = SQLHandler.read[1].ToString(); song.Artist = SQLHandler.read[2].ToString(); song.Album = SQLHandler.read[3].ToString(); song.Location = SQLHandler.read[6].ToString(); song.Genre = SQLHandler.read[7].ToString(); try { string[] results = SQLHandler.read[4].ToString().Split(':'); int[] result = new int[] { Convert.ToInt16(results[0]), Convert.ToInt16(results[1]), Convert.ToInt16(results[2]) }; song.Duration = new TimeSpan(result[0], result[1], result[2]); } catch (Exception) { } try { song.Plays = Convert.ToInt16(SQLHandler.read[5]); } catch (Exception) { } currentPlaylist.add(song); } } Playlists.Add(currentPlaylist); PlaylistListBox.ItemsSource = Playlists; }
private void MP3_Listbox_SelectionChanged(object sender, RoutedEventArgs e) { try { if (!Edit && MP3) { currentMP3 = (MP3)MP3_Listbox.SelectedItem; maxTimeLabel.Content = currentMP3.Duration.ToString().Split(':')[1] + ":" + currentMP3.Duration.ToString().Split(':')[2].Split('.')[0]; DisplayArtistLabel.Content = currentMP3.Artist; DisplayTitleLabel.Content = currentMP3.Title; int index = currentMP3.MP3_ID; SQLHandler.selectQuery("SELECT location FROM MP3 WHERE MP3_id='" + index + "'"); if (SQLHandler.read.HasRows) { while (SQLHandler.read.Read()) { player.Open(new Uri(SQLHandler.read[0].ToString())); player.Play(); playing = true; } } } else if (Edit) { MP3 song = (MP3)MP3_Listbox.SelectedItem; MessageBox.Show(song.ToString()); Edit_MP3 next = new Edit_MP3(); next.ID = song; next.ShowDialog(); } else { MP3 = true; } } catch (Exception) { } }
public void add(MP3 Song) { music.Add(Song); }