private void initWithStartingSong(Track t) { int trackIndex = unshuffledPlaylist.Songs.IndexOf(t); unrepeatedPlaylistLength = unshuffledPlaylist.Count(); currentIndex = 0; //create and initialize array with number of elements equal to items in the playlist int[] shuffledPlaylistIndexes = new int[unrepeatedPlaylistLength]; shuffledPlaylistIndexes[0] = trackIndex; for (int counter = 1; counter < unrepeatedPlaylistLength; counter++) { if (counter != trackIndex) shuffledPlaylistIndexes[counter] = counter; } // To shuffle an array a of n elements (indices 0..n-1): for (int i = unrepeatedPlaylistLength - 1; i >= 1; i--) { Random r = new Random(); int j = r.Next(1, i); int num1 = shuffledPlaylistIndexes[j]; int num2 = shuffledPlaylistIndexes[i]; shuffledPlaylistIndexes[j] = num2; shuffledPlaylistIndexes[i] = num1; } shuffledPlaylist = new Playlist(); for (int counter = 0; counter < shuffledPlaylistIndexes.Length; counter++) shuffledPlaylist.AddSong(unshuffledPlaylist.ElementAt(shuffledPlaylistIndexes[counter])); }
/// <summary> /// Initialize a shuffler but with a specific starting track. /// </summary> /// <param name="playlist"></param> /// <param name="startingTrack"></param> public Shuffler(Playlist playlist, Track startingTrack) { unshuffledPlaylist = playlist; initWithStartingSong(startingTrack); }
public Track GetSongById(long id) { SQLiteConnection dbConnection = new SQLiteConnection(sqlConnectionString); Track result = null; string sql = "select * from track where id = " + id; dbConnection.Open(); SQLiteCommand command = new SQLiteCommand(sql, dbConnection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) result = new Track((long)reader["id"], reader["title"].ToString(), reader["album_artist"].ToString(), reader["composer"].ToString(), reader["album"].ToString(), reader["genre"].ToString(), (short)((long)reader["track_number"]), (short)((long)reader["year"]), (short)((long)reader["disc"]), reader["file_path"].ToString()); dbConnection.Close(); return result; }
public void RemoveTrackFromShuffler(Track t) { shuffledPlaylist.RemoveSong(t); }
private void setLabels(Track t) { lblTitleContent.Content = t.Title; lblArtistContent.Content = t.Artist; lblAlbumContent.Content = t.Album; if (t.Year != 0) lblYearContent.Content = + t.Year; else lblYearContent.Content = ""; lblGenreContent.Content = t.Genre; //lblBitDepthContent.Content = musicEngine.BitDepth; lblSampleRateContent.Content = musicEngine.SampleRate; //album art try { //string imageFile = selectedLibrary.GetAlbumArtPathByAlbumName(t.Album); string imageFile = selectedLibrary.GetAlbumArtPathBySongID(t.Id); if (imageFile != "") { albumImage.StretchDirection = StretchDirection.DownOnly; albumImage.Source = new BitmapImage(new Uri(imageFile)); //ImageBrush background = new ImageBrush(); //background.ImageSource = new BitmapImage( new Uri(imageFile)); //playerMainGrid.Background = background; } else { albumImage.Source = null; } } catch (Exception) { albumImage.Source = null; Console.WriteLine("Trapped exception loading album art"); } }
private void PlayTrack(Track t) { if (isPlaying) musicEngine.Stop(); currentTrack = t; //this.Dispatcher.BeginInvoke(new Action(() => // { // musicEngine.Play(((Track)lstNowPlaying.SelectedItem).FilePath, selectedOutput); // })); try { musicEngine.Play(((Track)lstNowPlaying.SelectedItem).FilePath, selectedOutput); } catch (InvalidOutputDeviceException e) { string messageBoxText = "The selected output device: \n" + e.Output.DeviceName + "\nis not working properly. Make\nsure the device is turned on."; string caption = "Output Device Problem"; MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.Warning; MessageBox.Show(messageBoxText, caption, button, icon); return; } setLabels(t); SetButtons(ButtonClicked.Play); Properties.Settings.Default.CurrentTrack = currentTrack; Properties.Settings.Default.Save(); }
public string RemoveTrackFromPlaylist(Track song) { currentPlaylist.RemoveSong(song); lstNowPlaying.Items.Remove(song); return GetCurrentPlaylistJSON(); }
public string AddTrackToPlaylist(Track song) { currentPlaylist.Add(song); lstNowPlaying.Items.Add(song); return GetCurrentPlaylistJSON(); }
public SongChangedEventArgs(Track song) { t = song; }