gtreshchev / RuntimeAudioImporter

Runtime Audio Importer plugin for Unreal Engine. Importing audio of various formats at runtime.
MIT License
336 stars 69 forks source link

how to get audio duration #45

Closed yixuanqi closed 1 year ago

gtreshchev commented 1 year ago

To obtain the duration of the sound wave, use the GetDuration function. You can find more information in the documentation.

yixuanqi commented 1 year ago

thanks for your reply, but what could i do via cpp? in the "importing Audio" i find a way to play sound, when i use the same way to get duration it doesn't work. here is my code RuntimeAudioImporter->OnResultNative.AddWeakLambda(this, [this](URuntimeAudioImporterLibrary* Importer, UImportedSoundWave* ImportedSoundWave, ERuntimeImportStatus Status) { if (Status == ERuntimeImportStatus::SuccessfulImport) { UE_LOG(LogTemp, Warning, TEXT("Successfully imported audio with sound wave %s"), *ImportedSoundWave->GetName()); //UGameplayStatics::PlaySound2D(GetWorld(), ImportedSoundWave); pAudioDuration->SetText(FText::FromString(FString::SanitizeFloat(ImportedSoundWave->GetDuration()) + FString("s"))); } else { UE_LOG(LogTemp, Error, TEXT("Failed to import audio")); } RuntimeAudioImporter = nullptr; }); it seems i can just use AddWeakLambda once to get ImportedSoundWave to play sound or get wave property.

gtreshchev commented 1 year ago

Please refer to the documentation for more information on how to import audio data. It includes a C++ example as well: https://github.com/gtreshchev/RuntimeAudioImporter/wiki/1.-Importing-Audio