Share via


SoundPlayer.Load 方法

定义

同步加载声音。

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

例外

加载所用的时间超出了 LoadTimeout 指定的时间(以毫秒为单位)。

找不到 SoundLocation 指定的文件。

示例

下面的代码示例演示如何使用 LoadAsync 方法将 .wav 文件附加到 类的 SoundPlayer 实例。 此代码示例是为 SoundPlayer 类提供的一个更大示例的一部分。

try
{
   
   // Assign the selected file's path to 
   // the SoundPlayer object.  
   player->SoundLocation = filepathTextbox->Text;
   
   // Load the .wav file.
   player->Load();
}
catch ( Exception^ ex ) 
{
   ReportStatus( ex->Message );
}
try
{
    // Assign the selected file's path to 
    // the SoundPlayer object.  
    player.SoundLocation = filepathTextbox.Text;

    // Load the .wav file.
    player.Load();
}
catch (Exception ex)
{
    ReportStatus(ex.Message);
}
Try
    ' Assign the selected file's path to the SoundPlayer object.
    player.SoundLocation = filepathTextbox.Text

    ' Load the .wav file.
    player.Load()
Catch ex As Exception
    ReportStatus(ex.Message)
End Try

注解

方法 Load 使用当前线程加载.wav文件,防止线程在加载完成之前处理其他消息。

注意

方法 Load 可能会在加载大型.wav文件时产生延迟。 此外,在加载完成之前,将阻止绘制和其他事件。 LoadAsync使用 方法异步加载声音,这允许调用线程继续而不会中断。

即使加载不成功,此方法也会 LoadCompleted 在加载完成时引发 事件。

适用于

另请参阅