AudioPlayerApp.AudioPlayer.Play C# (CSharp) Метод

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

Plays the sound.
public Play ( ) : void
Результат void
        public void Play()
        {
            if (State != AudioPlayerState.Playing)
            {
                bool waitForFirstPlay = false;
                if (State == AudioPlayerState.Stopped)
                {
                    playCounter++;
                    waitForPlayToOutput.Reset();
                    waitForFirstPlay = true;
                }
                else
                {
                    // The song was paused
                    clock.Start();
                }

                State = AudioPlayerState.Playing;
                playEvent.Set();

                if (waitForFirstPlay)
                {
                    waitForPlayToOutput.WaitOne();
                }
            }
        }

Usage Example

Пример #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();
                }
            }
        }
All Usage Examples Of AudioPlayerApp.AudioPlayer::Play