오디오 재생
기본 재생
가져온 사운드 웨이브를 재생하려면 일반 사운드와 동일한 함수를 사용하세요. 예를 들어, Sound Cue와 같은 오디오 컴포넌트에서 PlaySound2D
또는 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);
UE 4.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();
메모리를 수동으로 해제하는 것은 가비지 컬렉터를 비활성화했거나 특정 메모리 관리 요구 사항이 있는 경우가 아니라면 권장되지 않습니다.