Эта ошибка уже подтверждена в эпических играх, однако есть ли какое-нибудь быстрое исправление для тех, кто уже сталкивался с такой же проблемой? это происходит только тогда, когда приложение загружается во второй раз. Я отлаживал его с помощью студии Android и обнаружил, что ошибка запуска AudioRecord () -38 срабатывает, когда приложение запускается во второй раз.
Вот ссылка на баг UE-62389
Вот мой .h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Runtime/Online/Voice/Public/VoiceModule.h"
#include "VolumeCapture.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT2_API UVolumeCapture : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UVolumeCapture();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
TSharedPtr<IVoiceCapture> VoiceCapture_V;
uint32 VoiceCaptureBytesAvailable;
TArray<uint8> VoiceCaptureBuffer;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float VoiceCaptureVolume;
};
И вот мой .cpp, я также добавил слишком много отладки в конце, чтобы быть уверенным, какое состояние захвата, и это всегда нормально, когда приложение запускается во второй раз.
// Fill out your copyright notice in the Description page of Project Settings.
#include "VolumeCapture.h"
#include "Platform.h"
// Sets default values for this component's properties
UVolumeCapture::UVolumeCapture()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UVolumeCapture::BeginPlay()
{
Super::BeginPlay();
VoiceCapture_V = FVoiceModule::Get().CreateVoiceCapture();
bool Success = VoiceCapture_V.IsValid(); //VoiceCapture->Start();
if (Success)
{
VoiceCapture_V->Start();
UE_LOG(LogTemp, Warning, TEXT("Voice capture started successfully"));
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Green, "Voice capture started successfully");
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Voice capture not started successfully"));
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Voice capture starting failed");
}
}
// Called every frame
void UVolumeCapture::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (!VoiceCapture_V.IsValid())
{
UE_LOG(LogTemp, Warning, TEXT("Voice capture is not valid; skipping the rest of voice capture tick"));
//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Red, "Voice Capture is not valid");
return;
}
else
{
//GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Green, "valid");
}
if (VoiceCapture_V->IsCapturing())
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Black, "Capturing data right now");
else
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Black, "Not Capturing");
EVoiceCaptureState::Type CaptureState = VoiceCapture_V->GetCaptureState(VoiceCaptureBytesAvailable);
UE_LOG(LogTemp, Warning, TEXT("Bytes available: %d\nCapture state: %s"), VoiceCaptureBytesAvailable, EVoiceCaptureState::ToString(CaptureState));
FString NewString = FString::FromInt(VoiceCaptureBytesAvailable);
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Black, NewString);
VoiceCaptureBuffer.Reset();
if (CaptureState == EVoiceCaptureState::Ok && VoiceCaptureBytesAvailable > 0)
{
int16_t VoiceCaptureSample;
uint32 VoiceCaptureReadBytes;
float VoiceCaptureTotalSquared = 0;
VoiceCaptureBuffer.SetNumUninitialized(VoiceCaptureBytesAvailable);
VoiceCapture_V->GetVoiceData(VoiceCaptureBuffer.GetData(), VoiceCaptureBytesAvailable, VoiceCaptureReadBytes);
for (int i = 0; i < VoiceCaptureBuffer.Num() / 2; i++)
{
VoiceCaptureSample = VoiceCaptureBuffer[i]; //(VoiceCaptureBuffer[i] << 8) | VoiceCaptureBuffer[i];
VoiceCaptureTotalSquared += ((float)VoiceCaptureSample * (float)VoiceCaptureSample);
}
float VoiceCaptureMeanSquare = (2 * (VoiceCaptureTotalSquared / VoiceCaptureBuffer.Num()));
float VoiceCaptureRms = FMath::Sqrt(VoiceCaptureMeanSquare);
float VoiceCaptureFinalVolume = ((VoiceCaptureMeanSquare / 32768.0) * 20.f);
VoiceCaptureVolume = VoiceCaptureFinalVolume;
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Blue, FString::Printf(TEXT("VoiceCaptureVolume: %f"), VoiceCaptureVolume));
}
if (CaptureState == EVoiceCaptureState::Error)
{
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Emerald, "ERROR");
}
if (CaptureState == EVoiceCaptureState::NoData)
{
GEngine->AddOnScreenDebugMessage(-1, 0.05f, FColor::Emerald, "NoData");
}
if (CaptureState == EVoiceCaptureState::NotCapturing)
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "NotCapturing");
}
if (CaptureState == EVoiceCaptureState::UnInitialized)
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "UnInitialized");
}
if (CaptureState == EVoiceCaptureState::Stopping)
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "Stopping");
}
if (CaptureState == EVoiceCaptureState::BufferTooSmall)
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Emerald, "BufferTooSmall");
}
}
Не могу сделать больше, любые советы будут отличными.
Благодарность
Обновлено: AndroidVoiceModule написан с использованием OpenSL ES, и он не может правильно завершить работу драйвера записи, когда я закрываю приложение. Даже когда я пытался закрыть все по порядку, как - Очистка буфера - Уничтожение записывающего объекта - Разрушающий двигатель
Все еще не работает.
хоть кто-нибудь подскажет как правильно закрыть аудиодрайвер внутри нереального движка.
Попробуйте задать этот вопрос на форумах, где с большей вероятностью встретятся эксперты по Unreal. Например, здесь или здесь.
Я уже спрашивал на нереальном форуме, но не в стеке разработки игр, спасибо, что сообщили мне
Опять же, я пока не могу найти никакого решения, даже спрашивая на этих форумах
Хорошо, я думаю, ваш лучший шанс - отправить этот вопрос нереальным экспертам. Попробуйте поискать в университетах.
Вверх, кто-нибудь может помочь с этим?