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 事件,即使載入未成功也一樣。

適用於

另請參閱