Getting Sound Duration at Runtime

In order to get a sound’s duration at runtime, an event to play that sound needs to be posted to the audio middleware first. Once it has been posted, the middleware will callback to the audio system with the duration information. If you are interested in this information, you can simply connect to the AudioTriggerNotificationBus by the ATL trigger Id that was used.

By overriding the ReportDurationInfo function, you will be notified with that information.

C++ Example: Getting a Sound’s Duration

class MyClass
    : protected AudioTriggerNotificationBus::Handler
{
public:
    MyClass()
    {
        m_triggerId = ...;
        AudioTriggerNotificationBus::Handler::BusConnect(m_triggerId);
 
        // execute the m_triggerId ...
    }
 
    ~MyClass()
    {
        AudioTriggerNotificationBus::Handler::BusDisconnect();
    }
 
protected:
    void ReportDurationInfo(TAudioEventID eventId, float duration, float estimatedDuration) override
    {
        // ...
    }
 
private:
    TAudioControlID m_triggerId;
};

Copyright © 2022 Open 3D Engine Contributors

Documentation Distributed under CC BY 4.0.
For our trademark, privacy and antitrust policies, code of conduct, and terms of use, please click the applicable link below or see https://www.lfprojects.org.


The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our Trademark Policy page.