語言

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 觸發事件,即使載入未成功。

適用於

另請參閱