Share via


SoundPlayer.PlaySync Yöntem

Tanım

.wav dosyasını oynatır ve yüklenmemişse önce .wav dosyasını yükler.

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

Özel durumlar

Yükleme sırasında geçen süre, tarafından LoadTimeoutbelirtilen milisaniye cinsinden süreyi aşıyor.

tarafından SoundLocation belirtilen dosya bulunamıyor.

.wav üst bilgisi bozuk; tarafından SoundLocation belirtilen dosya bir PCM .wav dosyası değil.

Örnekler

Aşağıdaki kod örneği, .wav dosyasını zaman uyumlu bir şekilde yürütmek için yönteminin kullanımını PlaySync gösterir.

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

Açıklamalar

PlaySync yöntemi geçerli iş parçacığını kullanarak bir .wav dosyasını yürüterek iş parçacığının yük tamamlanana kadar diğer iletileri işlemesini engeller. .wav dosyasını belleğe önceden yüklemek için veya Load yöntemini kullanabilirsinizLoadAsync. bir .wav dosyası veya URL'sinden Stream başarıyla yüklendikten sonra, için kayıttan yürütme yöntemlerine yönelik gelecek çağrıların SoundPlayer , ses yolu değişene kadar .wav dosyasını yeniden yüklemesi gerekmez.

.wav dosyası belirtilmemişse veya yüklenemezse PlaySync , yöntem varsayılan bip sesini çalar.

Şunlara uygulanır

Ayrıca bkz.