/// <summary> /// Plays the currently loaded song in the NAudio drivers /// </summary> public void playCurrentSong() { if (playPause) { // Changes button image to pause pcbPlay.Image = Properties.Resources.pausetrack; // Change to pause playPause = false; // If not playing active track if (!isPlaying) { // Get the file path string songPath = getNextSong(); // Sets song to be played musicController.setSong(songPath); string trackDetails = "Now Playing: " + thisSong.getTrackName() + " by " + thisSong.getArtist(); lblPlayerStatus.Text = trackDetails; // Sets the length of the track trackLength = musicController.getTrackLength(); TimeSpan totalLength = TimeSpan.FromSeconds(trackLength); lblTimeTwo.Text = totalLength.ToString("mm':'ss"); // Sets upper threshold for track sliderValue = 0; isPlaying = true; } // Begins the timer tmrTracker.Enabled = true; // Updates playcount for particular song VoteModel voteModel = new VoteModel(); Song updSong = activePlaylist.getSongByID(playlistIndex); voteModel.updatePlayCount(thisSong.getSongID()); // Initiates playing of song musicController.playSong(); parent.newSong(updSong); } else { // Changes button image to play pcbPlay.Image = Properties.Resources.playtrack; // Sets up for paused playback tmrTracker.Enabled = false; playPause = true; // Pauses playback musicController.pauseSong(); } }
/// <summary> /// Updates the position of the slider based on the passed value /// </summary> /// <param name="value">The new value of the slider</param> private void SetValue(int value) { // Return if no track loaded if (!isPlaying) { return; } // Make sure the new value is within bounds. if (value < 0) value = 0; if (value > trackLength) value = trackLength; if (value >= trackLength) // End of the song { // Checks where to increment the index counter to (if not repeating) if (playlistIndex < activePlaylist.getPlaylistSize() && !rbnCurrent.Checked && !rbnOnce.Checked) { playlistIndex++; } // Checks repeat status if (rbnNone.Checked) { // Resets tracker bar value = 0; stopSong(); // If it is at the end of the playlist if (!(playlistIndex >= activePlaylist.getPlaylistSize() - 1)) { // Stops current song, and plays the next song playCurrentSong(); } } else if (rbnOnce.Checked) // Repeat Once { value = 0; musicController.updatePlayTime(TimeSpan.FromSeconds(0)); rbnNone.Checked = true; // Updates playcount for particular song VoteModel voteModel = new VoteModel(); Song updSong = activePlaylist.getSongByID(playlistIndex); voteModel.updatePlayCount(thisSong.getSongID()); } else if (rbnCurrent.Checked) // Repeat eternally { value = 0; musicController.updatePlayTime(TimeSpan.FromSeconds(0)); // Updates playcount for particular song VoteModel voteModel = new VoteModel(); Song updSong = activePlaylist.getSongByID(playlistIndex); voteModel.updatePlayCount(thisSong.getSongID()); } else if (rbnPlaylist.Checked) // Repeat playlist { value = 0; // If at the end of the playlist if (playlistIndex >= activePlaylist.getPlaylistSize()) { playlistIndex = 0; } // Stops the current song, and starts the next song stopSong(); playCurrentSong(); } } // See if the value has changed. if (sliderValue == value) return; // Save the new value. sliderValue = value; // Redraw to show the new value. pcbSliderBar.Refresh(); // Updates the time indicator TimeSpan currentTime = updateTimeIndicator(); // If tracking position if (mouseIsDown) { // Display the value tooltip. int tip_x = pcbSliderBar.Left + (int)ValueToX(sliderValue); int tip_y = pcbSliderBar.Top; ttpSliderIndicator.Show(currentTime.ToString("mm':'ss"), this, tip_x, tip_y, 3000); } }