Play audio when timer ends

Hi, I’m trying to get an audiofile to play after a certain amount of time / other inputs, for an instructional app. Is there any way to trigger the PlaySound from javascript? I’ve also found a little on the StreamingAudio api that was to be added, but can’t find any documentation…
Thanks!
Stefan

Hey Stefan,

For this, you should use UserEvent.

You could create an UserEvent inside the component which will need to raise the event. There are 2 ways you can raise events - in UX when a user clicks something or (just like you need) directly from JavaScript using .raise() method whenever you fancy.

For a PlaySound use case, here’s a small code example. Inside component MyComponent I created UserEvent and added some JavaScript that will raise this event after a delay. In UX I added OnUserEvent trigger inside of the class instance et voila!

<App>
    <Panel ux:Class="MyComponent">
        <JavaScript>
        setTimeout(function() {
            myEvent.raise();
        }, 3000);
        </JavaScript>
        <UserEvent ux:Name="myEvent" />
    </Panel>
    <MyComponent>
        <OnUserEvent EventName="myEvent">
            <DebugAction Message="PlaySound would happen here" />
            <!-- <PlaySound ... /> -->
        </OnUserEvent>
    </MyComponent>
</App>

Hope this helps!

Hey Arturs,
Thanks, it helped a lot!