オーディオ再生
基本的な再生
インポートされたサウンドウェーブを再生するには、通常のサウンドウェーブと同じ関数を使用します。例えば、PlaySound2D 関数や、Sound Cue などのオーディオコンポーネントの Play 関数を使用します。

再生の制御
再生時間の巻き戻し
サウンドウェーブの再生時間を巻き戻すには、RewindPlaybackTime 関数を使用します。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
// Rewind playback time of the sound wave for 12.5 seconds
ImportedSoundWave->RewindPlaybackTime(12.5f);
UE4.27までのバージョンでは、0より大きい特定の時間から再生を開始したい場合、事前に RewindPlaybackTime 関数を使用する必要があるかもしれません。そうしないと、プロシージャルウェーブの内部エンジン処理の問題により、音声が正しく再生されない可能性があります。この問題は、エンジンバージョン5.0以降で解決されています。
再生情報の取得
サウンドウェーブの現在の再生時間を取得するには、GetPlaybackTime または GetPlaybackPercentage 関数を使用します。また、GetDuration 関数を使用してサウンドウェーブの長さを取得することもできます。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
// Get the current playback time of the sound wave
float PlaybackTime = ImportedSoundWave->GetPlaybackTime();
// Get the current playback percentage of the sound wave
float PlaybackPercentage = ImportedSoundWave->GetPlaybackPercentage();
// Get the duration of the sound wave
float Duration = ImportedSoundWave->GetDuration();
再生状態の確認
現在再生中かどうか
サウンドウェーブが現在再生中かどうかを判断するには、IsPlaying 関数を使用できます。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
// Check if the sound wave is currently playing
bool bIsPlaying = ImportedSoundWave->IsPlaying();
再生は完了しましたか
サウンドウェーブの再生が完了したかどうかを確認するには、IsPlaybackFinished 関数を使用できます。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
// Check if the sound wave has finished playback
bool bIsFinished = ImportedSoundWave->IsPlaybackFinished();
再生の停止
サウンドウェーブの再生は、StopPlayback 関数を使用して停止できます。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
// Stop the playback of the sound wave
ImportedSoundWave->StopPlayback();
外部手段(例:オーディオコンポーネントのStopを呼び出す)でサウンドウェーブの再生を停止することを一般的に推奨します。外部手段が利用できない場合にこの関数を使用してください。また、この関数はMetaSoundsからの再生には機能しないことに注意してください。
イベント処理
再生完了の追跡
オーディオ再生の終了を追跡するには、OnAudioPlaybackFinished デリゲートにバインドします。
- Blueprint
- C++

UCLASS()
class AMyAudioPlayer : public AActor
{
GENERATED_BODY()
public:
UFUNCTION()
void OnAudioFinished()
{
// Handle the end of audio playback
}
void BindAudioDelegate(UImportedSoundWave* ImportedSoundWave)
{
// Bind to the OnAudioPlaybackFinished delegate
ImportedSoundWave->OnAudioPlaybackFinished.AddDynamic(this, &AMyAudioPlayer::OnAudioFinished);
}
};
メモリ管理
メモリの解放
ReleaseMemory 関数を使用して、オーディオデータを手動でクリアできます。
- Blueprint
- C++

// Release memory of the sound wave
ImportedSoundWave->ReleaseMemory();
手動でのメモリ解放は、特定のメモリ管理要件がある場合やガベージコレクタを無効にしている場合を除き、推奨されません。