SoundPlayer.PlaySync Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Reproduz o ficheiro .wav e carrega primeiro o ficheiro .wav se este não tiver sido carregado.
public:
void PlaySync();
public void PlaySync();
member this.PlaySync : unit -> unit
Public Sub PlaySync ()
Exceções
O tempo decorrido durante o carregamento excede o tempo, em milissegundos, especificado por LoadTimeout.
O ficheiro especificado por SoundLocation não pode ser encontrado.
O cabeçalho .wav está corrompido; o ficheiro especificado por SoundLocation não é um ficheiro PCM .wav.
Exemplos
O exemplo de código seguinte demonstra a utilização do PlaySync método para reproduzir síncronicamente um ficheiro .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)
{
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
Observações
O PlaySync método utiliza a thread atual para reproduzir um ficheiro .wav, impedindo que a thread trate outras mensagens até que o carregamento esteja completo. Pode usar o LoadAsync método ou Load para carregar o ficheiro .wav na memória antecipadamente. Depois de um ficheiro .wav ser carregado com sucesso a partir de uma Stream URL de ou, futuras chamadas para métodos SoundPlayer de reprodução não precisarão de recarregar o ficheiro .wav até que o caminho do som mude.
Se o ficheiro .wav não tiver sido especificado ou não for carregado, o PlaySync método irá reproduzir o som de bip padrão.