# How to retrieve a sound total time/length/duration?

**URL:** <https://qa.fmod.com/t/how-to-retrieve-a-sound-total-time-length-duration/19300>\
**Category:** Unity\
**Created:** [September 21, 2022, 7:28pm UTC](https://qa.fmod.com/t/how-to-retrieve-a-sound-total-time-length-duration/19300 "2022-09-21T19:28:06Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [September 27, 2022, 11:39pm UTC](https://qa.fmod.com/t/how-to-retrieve-a-sound-total-time-length-duration/19300/4 "2022-09-27T23:39:06Z")

</div>

If you want the length of a sound when it is played you can implement a callback on [`FMOD_STUDIO_EVENT_CALLBACK_SOUND_PLAYED`](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#fmod_studio_event_callback_type), which will give you the underlying `Sound` object, on which you can call [`Sound::getLength`](https://fmod.com/docs/2.02/api/core-api-sound.html#sound_getlength). We have an example of how to implement an event callback here: [Timeline Callbacks](https://fmod.com/docs/2.02/unity/examples-timeline-callbacks.html)  
You would need to add the `FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED` flag when calling `EventInstance::setCallback` and then the callback would be something like this:

```ruby
[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT SoundCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, System.IntPtr instancePtr, System.IntPtr parameterPtr)
{
	FMOD.RESULT result;
	FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
		
	switch (type)
	{
		case FMOD.Studio.EVENT_CALLBACK_TYPE.SOUND_PLAYED:
			{
				FMOD.Sound sound = new FMOD.Sound(parameterPtr);
				result = sound.getName(out string name, 256);
				if (result != FMOD.RESULT.OK)
					return result;

				result = sound.getLength(out uint length, FMOD.TIMEUNIT.MS);
				if(result == FMOD.RESULT.OK)
				    return result;

				Debug.Log("Sound Played. Name: " + name + " Length: " + length); 
				break; 
			}

	}
	return FMOD.RESULT.OK; 
}

```

---

_[View the full topic](https://qa.fmod.com/t/how-to-retrieve-a-sound-total-time-length-duration/19300)._
