SoundPlayer.PlaySync Método

Definição

Executa o arquivo .wav e carrega o arquivo .wav primeiro se ele não tiver sido carregado.

public:
 void PlaySync();
public void PlaySync ();
member this.PlaySync : unit -> unit
Public Sub PlaySync ()

Exceções

O tempo decorrido durante o carregamento excede o tempo, em milissegundos, especificado por LoadTimeout.

O arquivo especificado por SoundLocation não foi encontrado.

O cabeçalho .wav está corrompido; o arquivo especificado por SoundLocation não é um arquivo .wav PCM.

Exemplos

O exemplo de código a seguir demonstra o uso do PlaySync método para reproduzir um arquivo .wav de forma síncrona.

private:
   SoundPlayer^ Player;

   void loadSoundAsync()
   {
      // Note: You may need to change the location specified based on
      // the location of the sound to be played.
      this->Player->SoundLocation = "http://www.tailspintoys.com/sounds/stop.wav";
      this->Player->LoadAsync();
   }

   void Player_LoadCompleted( Object^ /*sender*/, System::ComponentModel::AsyncCompletedEventArgs^ /*e*/ )
   {
      if (this->Player->IsLoadCompleted == true)
      {
         this->Player->PlaySync();
      }
   }
private SoundPlayer Player = new SoundPlayer();
private void loadSoundAsync()
{
    // Note: You may need to change the location specified based on
    // the location of the sound to be played.
    this.Player.SoundLocation = "http://www.tailspintoys.com/sounds/stop.wav";
    this.Player.LoadAsync();
}

private void Player_LoadCompleted (
    object sender, 
    System.ComponentModel.AsyncCompletedEventArgs e)
{
    if (this.Player.IsLoadCompleted)
    {
        this.Player.PlaySync();
    }
}
Private WithEvents Player As New SoundPlayer

Sub LoadSoundAsync()
    ' Note: You may need to change the location specified based on
    ' the location of the sound to be played.
    Me.Player.SoundLocation = "http://www.tailspintoys.com/sounds/stop.wav"
    Me.Player.LoadAsync ()
End Sub

Private Sub PlayWhenLoaded(ByVal sender As Object, ByVal e As _
    System.ComponentModel.AsyncCompletedEventArgs) Handles _
    Player.LoadCompleted
    If Me.Player.IsLoadCompleted = True Then
            Me.Player.PlaySync()
    End If
End Sub

Comentários

O PlaySync método usa o thread atual para reproduzir um arquivo .wav, impedindo que o thread manuseie outras mensagens até que a carga seja concluída. Você pode usar o LoadAsync método ou Load carregar o arquivo .wav na memória com antecedência. Depois que um arquivo .wav for carregado com êxito de um Stream ou URL, chamadas futuras para métodos de reprodução não SoundPlayer precisarão recarregar o arquivo .wav até que o caminho do som seja alterado.

Se o arquivo .wav não tiver sido especificado ou não tiver sido carregado, o PlaySync método reproduzirá o som de bipe padrão.

Aplica-se a

Confira também