Exemplo n.º 1
0
        //Method to perform an upvote
        private void doUpvote(object sender, EventArgs e)
        {
            PictureBox theLabel = (PictureBox)sender;
            String[] tag = theLabel.Tag.ToString().Split(',');

            int x = int.Parse(tag[0]);
            int y = int.Parse(tag[1]);

            String songName = songLabelsName[x][y].Text;

            Guid songId = new Guid();
            int index = -1;

            for (int i = 0; i < songs.Count; i++)
            {
                if (songs[i].getTrackName().Equals(songName))
                {
                    songId = songs[i].getSongID();
                    index = i;
                    break;
                }
            }

            if (index > -1)
            {
                VoteModel vm = new VoteModel();
                if (upvoteButtons[x][y].Name.Equals("up"))
                {
                    vm.removeAVote(this.currentUser.getUsername(), songs[index].getSongID(), 1);
                    upvoteButtons[x][y].Name = "none";
                    //change image
                    upvoteButtons[x][y].BackgroundImage = Properties.Resources.upvote;
                }
                else
                {
                    if (downvoteButtons[x][y].Name.Equals("down"))
                    {
                        vm.updateVote(this.currentUser.getUsername(), songs[index].getSongID(), -1);
                        downvoteButtons[x][y].Name = "none";
                        upvoteButtons[x][y].Name = "up";
                        upvoteButtons[x][y].BackgroundImage = Properties.Resources.upvoted;
                        downvoteButtons[x][y].BackgroundImage = Properties.Resources.downvote;
                    }
                    else {
                        vm.doUpVote(songId, currentUser.getUsername());
                        //change image
                        upvoteButtons[x][y].Name = "up";
                        upvoteButtons[x][y].BackgroundImage = Properties.Resources.upvoted;
                    }

                }

                createVotePercentage(voteDisplay[x][y], index);
            }
        }
Exemplo n.º 2
0
        /// <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();
            }
        }
Exemplo n.º 3
0
        //Method to display up/downvote ratio in coloured picturebox
        private PictureBox createVotePercentage(PictureBox voteDisplayBox, int j)
        {
            //Create a new votemodel and get that track's votes
            VoteModel vm = new VoteModel();
            Vote vote = vm.getVotesForTrack(songs[j].getSongID());

            //Calculate pecentage downvotes
            int ups = vote.getUpVotes();
            int downs = vote.getDownVotes();
            float percent = (float)downs / ((float)ups + (float)downs) * 100;

            //If the float is actually a number...
            if (!float.IsNaN(percent))
            {
                // Do the popularity label thing here
                // **********************************

                //Create vote box with red and green

                int pbUnit = voteDisplayBox.Width / 100;

                Bitmap bmp = new Bitmap(voteDisplayBox.Width, voteDisplayBox.Height);
                Graphics g;
                g = Graphics.FromImage(bmp);
                g.Clear(Color.Green);
                g.FillRectangle(Brushes.Red, new Rectangle(0, 0, (int)(percent * pbUnit), (int)voteDisplayBox.Height));

                voteDisplayBox.Image = bmp;
                g.Dispose();
            }
            else
            {
                //If there's no votes, just draw a gray rectangle

                Bitmap bmp = new Bitmap(voteDisplayBox.Width, voteDisplayBox.Height);
                Graphics g;
                g = Graphics.FromImage(bmp);
                g.Clear(Color.Gray);

                voteDisplayBox.Image = bmp;
                g.Dispose();
            }

            return voteDisplayBox;
        }
Exemplo n.º 4
0
        /// <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);
            }
        }