AudioPlayerApp.AudioPlayer.Close C# (CSharp) Method

Close() public method

Close this audio player.
This is similar to call Stop(), Dispose(), Wait().
public Close ( ) : void
return void
        public void Close()
        {
            Stop();
            Dispose();
            Wait();
            State = AudioPlayerState.Closed;
        }

Usage Example

Beispiel #1
0
        private void EjectButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog {
                Title = "Select an audio file (wma, mp3, ...etc.) or video file..."
            };

            if (dialog.ShowDialog() == true)
            {
                lock (lockAudio)
                {
                    if (audioPlayer != null)
                    {
                        audioPlayer.Close();
                        audioPlayer = null;
                    }

                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }

                    // Ask the user for a video or audio file to play
                    fileStream = new NativeFileStream(dialog.FileName, NativeFileMode.Open, NativeFileAccess.Read);

                    audioPlayer = new AudioPlayer(xaudio2, fileStream);

                    FilePathTextBox.Text     = dialog.FileName;
                    SoundProgressBar.Maximum = audioPlayer.Duration.TotalSeconds;
                    SoundProgressBar.Value   = 0;

                    // Auto-play
                    audioPlayer.Play();
                }
            }
        }