Audiokinetic's Community Q&A is the forum where users can ask and answer questions within the Wwise and Strata communities. If you would like to get an answer from Audiokinetic's Technical support team, make sure you use the Support Tickets page.

+1 vote
I always get AK_NotInitialized when call GetSourcePlayPosition after upgrading to Wwise 2022.1.3.

Is it a known issue? Thanks.
in General Discussion by Edward C. (130 points)
edited by Edward C.

1 Answer

0 votes

Not work in 2022.1.3-2022.1.6
I guess it is caused by the inconsistency of SoundEngine。AK::SoundEngine is not instanced, So,return AK_NotInitialized.
But, can do as this:

//used by Cpp/Blueprint

int32 UAkGameplayStatics::GetSourcePlayPosition(UAkAudioEvent* AkEvent, int32 PlayingID)
{
    if (AkEvent) {
        return AkEvent->GetSourcePlayPosition(PlayingID);
    }
    return -1;
}

//expand UAkAudioEvent

int32 UAkAudioEvent::GetSourcePlayPosition(int32 PlayingID)
{
    SCOPED_AKAUDIO_EVENT_2(TEXT("UAkAudioEvent::PostEvent"));
    auto* AudioDevice = FAkAudioDevice::Get();
    if (UNLIKELY(!AudioDevice))
    {
        UE_LOG(LogAkAudio, Verbose, TEXT("Failed to post AkAudioEvent '%s' without an Audio Device."), *GetName());
        return AK_INVALID_PLAYING_ID;
    }

    if (UNLIKELY(!AudioDevice->IsInitialized()))
    {
        UE_LOG(LogAkAudio, Verbose, TEXT("Failed to post AkAudioEvent '%s' with the Sound Engine uninitialized."), *GetName());
        return AK_INVALID_PLAYING_ID;
    }

    auto* SoundEngine = IWwiseSoundEngineAPI::Get();
    if (UNLIKELY(!SoundEngine))
    {
        UE_LOG(LogAkAudio, Warning, TEXT("Failed to post AkAudioEvent '%s' without a Sound Engine."), *GetName());
        return AK_INVALID_PLAYING_ID;
    }

    auto* ExternalSourceManager = IWwiseExternalSourceManager::Get();
    if (UNLIKELY(!ExternalSourceManager))
    {
        UE_LOG(LogAkAudio, Warning, TEXT("Failed to post AkAudioEvent '%s' without the External Source Manager."), *GetName());
        return AK_INVALID_PLAYING_ID;
    }

    AkTimeMs CurrentPosition = 0;
    auto Result = SoundEngine->GetSourcePlayPosition(PlayingID, &CurrentPosition);
    if (Result == AK_Success)
    {
        return CurrentPosition;
    }
    else
    {
        GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, TEXT("GetSourcePlayPosition FAILED!"), false);
        return -1;
    }
}

by Sico Y. (160 points)
...