Play() публичный Метод

Plays the sound.
public Play ( ) : void
Результат void
Пример #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();
                }
            }
        }
Пример #2
0
 private void PlayPauseButton_Click(object sender, RoutedEventArgs e)
 {
     lock (lockAudio)
     {
         if (audioPlayer != null)
         {
             if (audioPlayer.State == AudioPlayerState.Playing)
             {
                 audioPlayer.Pause();
             }
             else
             {
                 audioPlayer.Play();
             }
         }
     }
 }
Пример #3
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();
                }
            }
        }