private async void ReceiveSongFromSocket()
        {
            WriteMessageText("Receiving song data...\n");
            try
            {
                SongWriter sw = new SongWriter(_d, _MessageBlock);
                await sw.WriteSongFromSocketStream(_proximitySocket);

                //udpate GUI w/ song written
                _d.BeginInvoke(() =>
                {
                    _sd._haveSong     = true;
                    _sd._songFileName = sw._songFileName;
                    _sd._playFromURI  = false;

                    _SongTitleTextBox.Text   = sw._songTitle;
                    _ArtistTitleTextBox.Text = sw._artistTitle;
                });
            }
            catch (Exception e)
            {
                WriteMessageText("Error: " + e.Message + "\n");
                _proximitySocket.Dispose();
            }
        }
Example #2
0
        private void WebClientDownloadReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                // This gets tripped if we cancel download
                return;
            }

            if (_downloadCanceled)
            {
                return;
            }

            try
            {
                songData._songFileName = String.Format("{0}{1}.mp3", ArtistTextBox.Text, SongTitleTextBox.Text);
                if (!IsSpaceAvailable(e.Result.Length))
                {
                    MessageBox.Show("There's not enough free space on your phone to store this song.");
                    return;
                }
                var sw = new SongWriter(this.Dispatcher, StatusTextBlock);
                sw.WriteFileToIsoStoreFromHTTP(songData._songFileName, e.Result);
                sw.SaveToMediaLibrary(ArtistTextBox.Text, SongTitleTextBox.Text, songData._songFileName);

                DownloadSongButton.Content = DownloadNowText;

                DownloadProgressBar.Visibility = Visibility.Collapsed;
                StatusTextBlock.Text           = "The song has been added to your music library!";
                songData._haveSong             = true;
            }
            catch (Exception ex)
            {
                StatusTextBlock.Text = "Error Downloading: " + ex.Message;
            }

            MyProgressBar.Visibility      = Visibility.Collapsed;
            MyProgressBar.IsIndeterminate = false;

            _downloading = false;
        }