SoundPlayer.PlaySync Método

Definición

Reproduce el archivo .wav y carga primero el archivo .wav si no se ha cargado.

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

Excepciones

El tiempo transcurrido durante la carga supera el tiempo, en milisegundos, especificado por LoadTimeout.

No se encuentra el archivo especificado por SoundLocation .

El encabezado .wav está dañado; el archivo especificado por SoundLocation no es un archivo pcM .wav.

Ejemplos

En el ejemplo de código siguiente se muestra el uso del PlaySync método para reproducir de forma sincrónica un archivo .wav.

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)
      {
         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

Comentarios

El PlaySync método usa el subproceso actual para reproducir un archivo .wav, lo que impide que el subproceso controle otros mensajes hasta que se complete la carga. Puede usar el LoadAsync método o Load para cargar el archivo .wav en memoria de antemano. Después de cargar correctamente un archivo de .wav desde una Stream dirección URL o , las llamadas futuras a los métodos de reproducción para el SoundPlayer no necesitarán volver a cargar el archivo .wav hasta que cambie la ruta de acceso para el sonido.

Si no se ha especificado el archivo .wav o no se puede cargar, el PlaySync método reproducirá el sonido de pitido predeterminado.

Se aplica a

Consulte también