오디오 재생
불러온 사운드 웨이브를 재생하려면 일반적인 사운드와 동일한 기능을 사용하십시오. 예를 들어, 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
함수를 사용하여 음파 재생을 중지할 수 있습니다. 음파 재생 중지는 외부 수단(예: 오디오 컴포넌트에서 Stop 호출)을 통해 수행하는 것이 권장되며, 외부 수단이 사용 불가능한 경우에만 이 함수를 사용하시기 바랍니다.
또한 이 함수는 MetaSounds에서의 재생에는 작동하지 않는다는 점을 유의하십시오.
- Blueprint
- C++
// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object
// Stop the playback of the sound wave
ImportedSoundWave->StopPlayback();
오디오 재생 종료를 추적하려면 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
함수를 사용하여 오디오 데이터를 수동으로 지울 수 있습니다. 수동으로 실행하는 것은 권장되지 않지만, garbage collector를 비활성화한 경우 유용할 수 있습니다.
- Blueprint
- C++
// Release memory of the sound wave
ImportedSoundWave->ReleaseMemory();