Example #1
0
 public static async Task DownloadAudio(AudioResponse composition, String path, ProgressBar ProgressBar)
 {
     try
     {
         if (path[path.Length - 1] != '\\')
         {
             path = path + "\\";
         }
         var fileName = composition.Artist + " – " + composition.AudioTitle;
         if (fileName.Length > 40)
         {
             fileName = fileName.Substring(0, 40);
         }
         fileName = fileName.Replace(":", "").Replace("\\", "").Replace("/", "").Replace("*", "").Replace("?", "").Replace("\"", "");
         using (var client = new WebClient())
         {
             client.DownloadProgressChanged += (o, args) =>
             {
                 ProgressBar.Value = args.ProgressPercentage;
             };
             client.DownloadFileCompleted += (o, args) =>
             {
                 ProgressBar.Value = 0;
             };
             await client.DownloadFileTaskAsync(new Uri(composition.AudioUrl), path + fileName + ".mp3");
         }
     }
     catch (Exception)
     {
     }
 }
Example #2
0
 private void PlayAudio(object sender, MouseButtonEventArgs e)
 {
     try
     {
         AudioResponse selected = (AudioResponse)Compositions.SelectedItem;
         if (selected != null)
         {
             WMP.URL = selected.AudioUrl;
             WMP.controls.play();
             PlayingStatus.Text = "Playing:";
             PlayingAudio.Text  = String.Format(selected.Artist + " – " + selected.AudioTitle);
         }
     }
     catch (Exception) { }
 }
    public void ChangeAudioState(AudioResponse response)
    {
        if(!responded) {
            if(isACircle) {
                switch(response){
                case AudioResponse.Yes:
                    this.circles.StartYes ();
                    return;
                case AudioResponse.No:
                this.circles.StartNo ();
                    return;
                case AudioResponse.Spit:
                this.circles.StartSpit ();
                break;
                }
            } else {
                switch (response) {
                case AudioResponse.Yes:
                    if(!currentAudioState.audioSource.isPlaying) {
                        this.responded = true;
                    }
                    this.currentAudioState.StartYes ();
                    if(!currentAudioState.audioSource.isPlaying) {
                        this.responded = true;
                    }
                    break;
                case AudioResponse.No:
                    if(!currentAudioState.audioSource.isPlaying) {
                        this.responded = true;
                    }
                    this.currentAudioState.StartNo ();
                    if(!currentAudioState.audioSource.isPlaying) {
                        this.responded = true;
                    }
                    break;
                case AudioResponse.Spit:
                    this.currentAudioState.StartSpit ();
                    this.responded = true;
                    break;
                }

            }
        }
    }