SoundPlayer.PlaySync Metodo

Definizione

Riproduce il file wav e, se il file wav non è stato caricato, prima lo carica.

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

Eccezioni

Il tempo trascorso durante il caricamento supera il tempo, in millisecondi, specificato da LoadTimeout.

Non è possibile trovare il file specificato da SoundLocation.

L'intestazione wav è danneggiata. Il file specificato da SoundLocation non è un file wav PCM.

Esempio

Nell'esempio di codice seguente viene illustrato l'uso del PlaySync metodo per riprodurre in modo sincrono un file .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 == 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

Commenti

Il PlaySync metodo usa il thread corrente per riprodurre un file .wav, impedendo al thread di gestire altri messaggi fino al completamento del caricamento. È possibile usare il LoadAsync metodo o Load per caricare in anticipo il file di .wav in memoria. Dopo il caricamento di un file .wav da un Stream URL o , le chiamate future ai metodi di riproduzione per il SoundPlayer non dovranno ricaricare il file .wav finché il percorso del suono non cambia.

Se il file di .wav non è stato specificato o non è stato caricato, il PlaySync metodo riprodurrà il suono di segnale acustico predefinito.

Si applica a

Vedi anche