SoundPlayer.PlaySync メソッド

定義

.wav ファイルを再生します。 .wav ファイルが読み込まれていない場合は、まずそのファイルを読み込みます。

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

例外

読み込み時の経過時間が、LoadTimeout で指定された時間 (ミリ秒単位) を超過しました。

SoundLocation で指定したファイルが見つかりません。

.wav ヘッダーが破損しています。SoundLocation で指定したファイルは、PCM .wav ファイルではありません。

次のコード例は、.wav ファイルを PlaySync 同期的に再生するメソッドの使用方法を示しています。

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

注釈

このメソッドは PlaySync 、現在のスレッドを使用して .wav ファイルを再生し、読み込みが完了するまでスレッドが他のメッセージを処理できないようにします。 またはLoadメソッドをLoadAsync使用して、.wav ファイルを事前にメモリに読み込むことができます。 .wav ファイルが URL から正常に読み込まれた Stream 後、サウンドのパスが変更されるまで、そのファイルの再生メソッド SoundPlayer の今後の呼び出しで .wav ファイルを再読み込みする必要はありません。

.wav ファイルが指定されていない場合、または読み込みに失敗した場合、メソッドは既定の PlaySync ビープ音を再生します。

適用対象

こちらもご覧ください