# holding down button to play audio

**URL:** https://discussions.unity.com/t/holding-down-button-to-play-audio/414322
**Category:** Audio & Video
**Tags:** Scripting
**Created:** [May 22, 2010, 4:50pm UTC](https://discussions.unity.com/t/holding-down-button-to-play-audio/414322 "2010-05-22T16:50:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![anon\_62557724](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@anon\_62557724](https://discussions.unity.com/u/anon_62557724)
#### Post date: [May 22, 2010, 4:50pm UTC](https://discussions.unity.com/t/holding-down-button-to-play-audio/414322/1 "2010-05-22T16:50:27Z")

</div>

i know the function repeat button so it work as long you hold it down but here is my problem. I want to play and audio file as long you hold it down and the audio file loop. When is use repeat button and audio.play it only plays the first note of the audio file but not the audio. Any idea how to do this?

---

<div class="post-metadata">

### Author: ![User340](https://avatars.discourse-cdn.com/v4/letter/u/bbe5ce/32.png) [@User340](https://discussions.unity.com/u/User340)
#### Post date: [May 22, 2010, 4:58pm UTC](https://discussions.unity.com/t/holding-down-button-to-play-audio/414322/2 "2010-05-22T16:58:50Z")

</div>

Only play the sound if it’s not already playing. Something similar to this:

```auto
if (GUI.RepeatButton (Rect (10, 10, 10, 10), ""))
{
   if (!audio.isPlaying)
      audio.Play ();
}
else
{
   audio.Stop ();
}

```
