x


audio.Play() not always playing the entire AudioClip

I'm getting very inconsistent results from audio.Play(), audio.PlayOneShot and AudioSource.PlayClipAtPoint. Some times the clip will play through correctly, while other times it will only play a portion and sometimes not at all.

Context: This is for a very simple minigame where the user has to touch targets as they move across the screen. A raycast figures out what they touched and calls a function on the target that plays a Maraca-shake sound, adjusts the score, instantiates an effect popup and at the end, destroys the GameObject. Everything else works perfectly except for the sound. When it doesn't work, it plays such a short portion of the clip that it only sounds like a "tick".

Sometimes I can go an entire play session without an occurrence and other times the problem happens 50% of the attempts, so I know it's not a problem with a specific object/prefab/inspector setting. They're all using the same script with the same settings.

I've tried all three methods of playing the sound listed above and all have the same problem. I've disabled the Destroy command to see if the sound was getting cut off too early, but that didn't work either. I'm not sure what else to try at this point. This is in Unity iPhone 1.7 basic. The error occurs both in the editor and on the device(iPad and iPhone).

more ▼

asked Jul 07 '10 at 03:31 PM

defmech gravatar image

defmech
236 2 4 8

Just to make sure, the game objects that you destroy, they don't have the sound clip, do they?

Jul 08 '10 at 07:52 AM TaigaStudios

Nope, they just have a script that references the AudioClip. I get much better results with PlayClipAtPoint due to how it works compared to the others, but it still glitches at least once or twice in a level.

Jul 08 '10 at 05:14 PM defmech

i'm having the same problem, but in a web build. ~Matt

Aug 19 '10 at 10:43 PM Matt 11
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

If you aren't destroying the gameObject that holds the audio source (my first though), then it could be any of the following.

  1. You're using MP3's (someone else mentioned this).
  2. You're using Play, rather than PlayOneShot(audioClipName). Play one shot can be triggered many times at once, and it'll deal with it. Play can not.
  3. Can you confirm with a line of debug code that you aren't accidentally triggering it 30 times? That would also cause issues.
  4. Are you doing anything to audio anywhere else, such as having an audio listener on the wrong camera, etc?
more ▼

answered Aug 29 '10 at 02:59 AM

jtbentley gravatar image

jtbentley
579 3 4 16

(comments are locked)
10|3000 characters needed characters left

It may be that the audio buffer becomes full causing an error and cancelling the operation.

In other words the iphone can only play one compressed audio clip at a time, and all sound effects must be uncompressed (AIFF) audio to play simultaneously. The compressed audio is usually used for the background music as it would be larger.

If you try to play an additional audio clip that is compressed the audio processor will have insufficient memory bandwidth or capacity to fulfil the requested operation. Try to limit the number of uncompressed audio clips playing simultaneously to prevent a buffer overflow, and limit compressed audio to one clip only.

more ▼

answered Aug 26 '10 at 04:48 AM

BurningThumb gravatar image

BurningThumb
154 1 5 11

(comments are locked)
10|3000 characters needed characters left

I've only tested on the pc. I was able to solve the issue by rerecording the faulty sounds as wav. I'd prefer mp3 for filesize but the 6 letters as wav are doable. I noticed in other posts that it seems that mp3 files are a bit buggy. Is this true?

more ▼

answered Nov 21 '11 at 12:04 PM

s1niz7el2 gravatar image

s1niz7el2
1

(comments are locked)
10|3000 characters needed characters left

I am having the same problems in an ABC learning game. When the user clicks a button the sound of the letter is supposed to play. It works on most of the letters but not all of them. By changing the bitrate on one of the non-working letters, I was able to get it to work but this "fix" is not consistent. All of the sound files are mp3 and targeted for android devices but I test with PC. Please help.

more ▼

answered Nov 20 '11 at 10:12 AM

s1niz7el2 gravatar image

s1niz7el2
1

Are you having this problem in the PC or only when testing in the Android?

Nov 20 '11 at 10:53 AM aldonaletto
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2013
x1059
x30

asked: Jul 07 '10 at 03:31 PM

Seen: 3910 times

Last Updated: Nov 21 '11 at 12:04 PM