SoundPlayer.Load 方法

定义

同步加载声音。

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

例外

加载过程中的用时超过时间(以毫秒为单位)指定的 LoadTimeout时间。

找不到由 <a0/a0> 指定的文件。

示例

下面的代码示例演示如何使用 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文件,防止线程处理其他消息,直到加载完成。

Caution

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

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

适用于

另请参阅