# Detect end of sound (SOLVED)

**URL:** <https://forum.defold.com/t/detect-end-of-sound-solved/36558>\
**Category:** Feature requests (USE GITHUB)\
**Created:** [December 2, 2018, 8:21pm UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558 "2018-12-02T20:21:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![d954mas](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/d954mas/32/5401_2.png) [@d954mas](https://forum.defold.com/u/d954mas)\
**Post date:** [December 2, 2018, 8:21pm UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/1 "2018-12-02T20:21:17Z")

</div>

> [@How to detect end of sound? (SOLVED)](https://forum.defold.com/t/how-to-detect-end-of-sound/28764):
>
> Well, it’s in the title slight_smile More detail : I need to play musics that loop, but with an intro that doesn’t loop. So I have two sound object : one for the intro, and one for the loop. Only the loop has the “Looping” box checked, of course. My idea is to play the intro, and when it is finished playing, to play the loop. So I was hoping for a way of detecting that a sound has finished playing (like a message, for example), but I haven’t found anything. Can you help me ?

Get end sound in any way(message or callback)

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [December 2, 2018, 9:13pm UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/2 "2018-12-02T21:13:34Z")

</div>

You could always create a [timer](https://www.defold.com/ref/timer/) with the length of the intro and run in at the same time as the sound.

But maybe there’s a way to get the callback directly from the sound.

---

<div class="post-metadata">

**Author:** ![d954mas](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/d954mas/32/5401_2.png) [@d954mas](https://forum.defold.com/u/d954mas)\
**Post date:** [December 2, 2018, 9:28pm UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/3 "2018-12-02T21:28:08Z")

</div>

Yes i can, but for that i need to know sound lenght

---

<div class="post-metadata">

**Author:** ![Klear](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/klear/32/11577_2.png) [@Klear](https://forum.defold.com/u/Klear)\
**Post date:** [December 2, 2018, 9:33pm UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/4 "2018-12-02T21:33:42Z")

</div>

Don’t you?

---

<div class="post-metadata">

**Author:** ![Gmanicus](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gmanicus/32/10312_2.png) [@Gmanicus](https://forum.defold.com/u/Gmanicus)\
**Post date:** [December 3, 2018, 6:36am UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/5 "2018-12-03T06:36:18Z")

</div>

> [@Klear](#):
>
> You could always create a timer

I actually did this myself when making [Operator](https://gmanicus.itch.io/operator-extended).

It turned out beautifully, but at the same time, it did require some hacking together to make alarm timings that managed to loop sounds. That is made a bit easier now with an actual built-in alarm (I had made one myself).

I’m told that [FMOD](https://www.defold.com/community/projects/90809/) is the best, if not the only sound manager asset for Defold. That might have some sort of “get sound length” feature. I might experiment with this.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [December 3, 2018, 6:59am UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/6 "2018-12-03T06:59:57Z")

</div>

We will make several improvements to audio playback during 2019. Getting a callback when a sound is finished is among them.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [December 3, 2018, 7:28am UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/7 "2018-12-03T07:28:12Z")

</div>

If you use FMOD it’s really easy to tell when a sound is playing or not.

if sound:get\_playback\_state() == fmod.STUDIO\_PLAYBACK\_STOPPED …

 ![2018-12-02_10_09_31-FMOD_API_Documentation](https://forum-defold.b-cdn.net/uploads/default/original/2X/d/d6f061051e3c24943e26ee2d6ceb6e51d12c773c.png)

---

<div class="post-metadata">

**Author:** ![d954mas](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/d954mas/32/5401_2.png) [@d954mas](https://forum.defold.com/u/d954mas)\
**Post date:** [December 3, 2018, 7:38am UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/8 "2018-12-03T07:38:39Z")

</div>

I look at fmod. But not try it yet. It looks big and complex, for me.

---

<div class="post-metadata">

**Author:** ![Pkeod](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pkeod/32/606_2.png) [@Pkeod](https://forum.defold.com/u/Pkeod)\
**Post date:** [December 3, 2018, 9:06am UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/9 "2018-12-03T09:06:10Z")

</div>

It is pretty easy once you get it. If you have questions ask me and I can help.

---

<div class="post-metadata">

**Author:** ![AGulev](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/agulev/32/4541_2.png) [@AGulev](https://forum.defold.com/u/AGulev)\
**Post date:** [September 16, 2019, 12:35pm UTC](https://forum.defold.com/t/detect-end-of-sound-solved/36558/10 "2019-09-16T12:35:31Z")

</div>

Solved in [Defold 1.2.162 has been released](https://forum.defold.com/t/defold-1-2-162-has-been-released/62959)
