SoundPlayer.PlaySync メソッド
アセンブリ: System (system.dll 内)



PlaySync メソッドは、現在のスレッドを使用して .wav ファイルを再生し、読み込みが完了するまでそのスレッドが他のメッセージを処理しないようにします。LoadAsync メソッドまたは Load メソッドを使用して、.wav ファイルをあらかじめメモリに読み込んでおくことができます。Stream または URL から .wav ファイルが正常に読み込まれると、SoundPlayer の再生メソッドの以降の呼び出しでは、サウンドのパスが変更になるまで .wav ファイルを再読み込する必要はありません。
.wav ファイルが指定されていないか、読み込みに失敗した場合、PlaySync メソッドは、既定のビープ音を再生します。

PlaySync メソッドを使用して、.wav ファイルを同期的に再生するコード例を次に示します。
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.Play() End If End Sub
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(); } }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SoundPlayer.PlaySync メソッドのページへのリンク