SoundPlayer.PlaySync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Plays the .wav file and loads the .wav file first if it has not been loaded.
public:
void PlaySync();
public void PlaySync ();
member this.PlaySync : unit -> unit
Public Sub PlaySync ()
Exceptions
The elapsed time during loading exceeds the time, in milliseconds, specified by LoadTimeout.
The file specified by SoundLocation cannot be found.
The .wav header is corrupted; the file specified by SoundLocation is not a PCM .wav file.
Examples
The following code example demonstrates the use of the PlaySync method to synchronously play a .wav file.
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
Remarks
The PlaySync method uses the current thread to play a .wav file, preventing the thread from handling other messages until the load is complete. You can use the LoadAsync or Load method to load the .wav file to memory in advance. After a .wav file is successfully loaded from a Stream or URL, future calls to playback methods for the SoundPlayer will not need to reload the .wav file until the path for the sound changes.
If the .wav file has not been specified or it fails to load, the PlaySync method will play the default beep sound.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기