Пример #1
0
        private void Play_PlaySong_Execute(object sender, RoutedEventArgs e) /* Play the compiled WAV file */
        {
            /* Local Variables */
            string wavFileAddress;  /* Location of the WAV file                     */
            string outputMessage;   /* Message to display to the user after build   */

            /* / Local Variables */

            outputMessage = null;

            /* Make sure the file is saved */
            try
            {
                if (currentDirectory != null && savedFilename != null)
                {
                    wavFileAddress = Path.Combine(currentDirectory, Path.ChangeExtension(savedFilename, WAV_FILE_EXT));

                    /* Make sure the WAV file exists */
                    if (File.Exists(wavFileAddress))
                    {
                        songPlayer = new SongPlayer(currentDirectory, savedFilename);
                        songPlayer.PlayWAVFile();
                    }
                    else
                    {
                        outputMessage = "Must create a WAV file to play first!";
                    }
                }
                else
                {
                    outputMessage = "Please save the file before playing the song!";
                }
            }

            /* Handle any error playing the WAV music */
            catch
            {
                outputMessage = "Song Play Failed\n\nThere was a problem playing the WAV file. Please check if the WAV file is corrupted";
            }

            /* Show Ouput Message if it exists */
            finally
            {
                if (outputMessage != null)
                {
                    MessageBox.Show(outputMessage);
                }
            }
        }