private void button1_Click(object sender, EventArgs e)
        {
            msgbox msgbox;
            if (listView1.SelectedItems.Count == 1)
            {
                if(account == null) {
                    msgbox = new msgbox(false, "Please confirm your credentials above by visiting the 'Account Stuffs' tab and log in with your Twitch account.");
                    msgbox.Show();
                } else {
                    if (MessageBox.Show("You are about to send a soundbyte.  Please confirm you wish to send it by clicking 'Yes' below.", "Send Soundbyte Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        int announce;
                        int sbID = -1;
                        if (checkBox2.Checked == true)
                        {
                            announce = 1;
                        }
                        else
                        {
                            announce = 0;
                        }
                        int.TryParse(listView1.SelectedItems[0].Tag.ToString(), out sbID);
                        if(sbID > -1) {
                            CallResponse resp = calls.sendAudioByte(account.Username, account.AppCode, sbID, announce);
                            switch (resp.Response)
                            {
                                case CallResponse.responseType.SUCCESS:
                                    msgbox = new msgbox(true, "Your soundbyte has been successfully sent to BurkeBlack's stream!");
                                    msgbox.Show();
                                    break;

                                case CallResponse.responseType.FAILURE:
                                    msgbox = new msgbox(false, resp.ErrorData);
                                    msgbox.Show();
                                    break;
                            }
                            updateCreditsAndCooldown();
                        } else {
                            msgbox = new msgbox(false, "Unable to find validated soundbyte ID. Unknown reason.");
                            msgbox.Show();
                        }
                    }
                }

            }
            else
            {
                msgbox = new msgbox(false, "You must select a soundbyte to send before clicking this button!");
                msgbox.Show();
            }
        }
        private void updateGenresAndSoundbytes()
        {
            msgbox msgbox;
            CallResponse callGenres = calls.getGenres();
            CallResponse callSoundbytes = calls.getSoundbytes();

            switch (callSoundbytes.Response)
            {
                case CallResponse.responseType.SUCCESS:
                    if (callSoundbytes.SatteliteData is soundbyte[])
                    {
                        listView1.Items.Clear();
                        soundbytes = (soundbyte[])callSoundbytes.SatteliteData;
                        foreach (soundbyte sb in soundbytes)
                        {
                            ListViewItem lvi = new ListViewItem();
                            lvi.Tag = sb.ID;
                            lvi.Text = sb.Name;
                            lvi.SubItems.Add(sb.GenreName);
                            switch (sb.HorrorNightType)
                            {
                                case soundbyte.HorrorNightTypes.AVAILABLE_ALL_THE_TIME:
                                    lvi.SubItems.Add("Always");
                                    break;

                                case soundbyte.HorrorNightTypes.AVAILABLE_ONLY_ON_HORROR_NIGHT:
                                    lvi.SubItems.Add("Only");
                                    break;

                                case soundbyte.HorrorNightTypes.NOT_AVAILBLE_ON_HORROR_NIGHT:
                                    lvi.SubItems.Add("Blocked");
                                    break;
                            }
                            lvi.SubItems.Add(sb.UploadedBy);
                            ListViewItem lvi2 = (ListViewItem)lvi.Clone();
                            listView1.Items.Add(lvi);
                        }
                    }
                    break;

                case CallResponse.responseType.FAILURE:
                    msgbox = new msgbox(false, callGenres.ErrorData);
                    msgbox.Show();
                    break;
            }

            switch (callGenres.Response)
            {
                case CallResponse.responseType.SUCCESS:
                    if (callGenres.SatteliteData is genre[])
                    {
                        comboBox1.Items.Clear();
                        comboBox1.Items.Add("All");
                        comboBox1.Items.Add("Horror Night");
                        genres = (genre[])callGenres.SatteliteData;
                        foreach (genre genre in genres)
                        {
                            comboBox1.Items.Add(char.ToUpper(genre.Name[0]) + genre.Name.Substring(1));
                        }
                        comboBox1.SelectedIndex = 0;
                    }
                    break;

                case CallResponse.responseType.FAILURE:
                    msgbox = new msgbox(false, callGenres.ErrorData);
                    msgbox.Show();
                    break;
            }
        }
        private bool updateCreditsAndCooldown()
        {
            msgbox msgbox;
            if (account != null)
            {
                CallResponse resp = calls.getAccountSoundbyteData(account.Username, account.AppCode);
                switch (resp.Response)
                {
                    case CallResponse.responseType.SUCCESS:
                        if (resp.SatteliteData is account)
                        {
                            account = (account)resp.SatteliteData;
                            textBox3.Text = account.Credits.ToString();
                            if (account.LastSubmission == "0")
                            {
                                textBox4.Text = "Ready for submission!";
                            }
                            else
                            {
                                textBox4.Text = account.LastSubmission;
                            }
                        }
                        return true;

                    case CallResponse.responseType.FAILURE:
                        msgbox = new msgbox(false, resp.ErrorData);
                        msgbox.Show();
                        return false;

                    default:
                        return false;
                }
            }
            else
            {
                msgbox = new msgbox(false, "Invalid Twitch name or app code.  Twitch name must be larger than 1 character and app code must be numeric.");
                msgbox.Show();
                return false;
            }
        }
 private void playSelectedSoundByte()
 {
     msgbox msgbox;
     if (listView1.SelectedItems.Count == 1 && currentlyPlayingSB == false)
     {
         soundbyte candidate = null;
         foreach (soundbyte sb in soundbytes)
         {
             if (sb.ID == (int)listView1.SelectedItems[0].Tag)
             {
                 candidate = sb;
             }
         }
         if (candidate != null)
         {
             button9.Enabled = false;
             currentlyPlayingSB = true;
             System.Threading.Thread playThread = new System.Threading.Thread(() => PlayMp3FromUrl(candidate.AudioLocation));
             playThread.Start();
         }
         else
         {
             msgbox = new msgbox(false, "The selected soundbyte could not be found in the inernal soundbyte cache! Try refreshing soundbyte and genre listings!");
             msgbox.Show();
         }
     }
     else
     {
         msgbox = new msgbox(false, "You must select a soundbyte to send before clicking this button!\nThere also must not be another soundbyte playing.");
         msgbox.Show();
     }
 }
        //Sourced from: http://stackoverflow.com/questions/184683/play-audio-from-a-stream-using-c-sharp
        private void PlayMp3FromUrl(string url)
        {
            try
            {
                //Poor practice
                CheckForIllegalCrossThreadCalls = false;

                using (Stream ms = new MemoryStream())
                {
                    using (Stream stream = WebRequest.Create(url)
                        .GetResponse().GetResponseStream())
                    {
                        byte[] buffer = new byte[32768];
                        int read;
                        while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            ms.Write(buffer, 0, read);
                        }
                    }

                    ms.Position = 0;
                    using (NAudio.Wave.WaveStream blockAlignedStream =
                        new NAudio.Wave.BlockAlignReductionStream(
                            NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(
                                new NAudio.Wave.Mp3FileReader(ms))))
                    {
                        using (NAudio.Wave.WaveOut waveOut = new NAudio.Wave.WaveOut(NAudio.Wave.WaveCallbackInfo.FunctionCallback()))
                        {
                            waveOut.Init(blockAlignedStream);
                            waveOut.Play();
                            while (waveOut.PlaybackState == NAudio.Wave.PlaybackState.Playing)
                            {
                                System.Threading.Thread.Sleep(100);
                            }
                        }
                    }
                }
            }
            catch
            {
                msgbox msgbox = new msgbox(false, "An error has happened whilst attempting to play the soundbyte.");
                msgbox.Show();
            }
            button9.Enabled = true;
            currentlyPlayingSB = false;
        }
 private void getMyMostPlayed()
 {
     CallResponse resp = calls.fetchMyMostPlayed(account.Username, account.AppCode);
     if (resp.Response == CallResponse.responseType.SUCCESS)
     {
         if (resp.SatteliteData is myMostPlayedListings[])
         {
             listView4.Items.Clear();
             foreach (myMostPlayedListings listing in (myMostPlayedListings[])resp.SatteliteData)
             {
                 ListViewItem lvi = new ListViewItem();
                 lvi.Text = listing.Name;
                 lvi.SubItems.Add(listing.Genre);
                 lvi.SubItems.Add(listing.HorrorStatus);
                 lvi.SubItems.Add(listing.UploadedBy);
                 lvi.SubItems.Add(listing.Plays.ToString());
                 listView4.Items.Add(lvi);
             }
         }
         else
         {
             msgbox msgbox = new msgbox(false, "Unknown returned object.");
             msgbox.Show();
         }
     }
     else
     {
         msgbox msgbox = new msgbox(false, resp.ErrorData);
         msgbox.Show();
     }
 }
        private void button8_Click(object sender, EventArgs e)
        {
            CallResponse resp = calls.fetchSoundbytePlayLeaderboard();
            switch (resp.Response)
            {
                case CallResponse.responseType.SUCCESS:
                    listView3.Items.Clear();
                    object[] leaderboardAndTotalPlays = (object[])resp.SatteliteData;
                    sbLeaderboardListing[] sbLeaderboardListings = (sbLeaderboardListing[])leaderboardAndTotalPlays[0];
                    string totalPlays = (string)leaderboardAndTotalPlays[1];
                    foreach (sbLeaderboardListing listing in sbLeaderboardListings)
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = listing.Name;
                        lvi.SubItems.Add(listing.Genre);
                        lvi.SubItems.Add(listing.UploadedBy);
                        lvi.SubItems.Add(listing.Plays.ToString());
                        lvi.SubItems.Add(listing.LastPlayedBy);
                        listView3.Items.Add(lvi);
                    }
                    textBox6.Text = listView3.Items.Count.ToString();
                    textBox7.Text = totalPlays;
                    break;

                case CallResponse.responseType.FAILURE:
                    msgbox msgbox = new msgbox(false, resp.ErrorData);
                    msgbox.Show();
                    break;
            }
        }