Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Warenth · Apr 05, 2014 at 12:42 AM · androidsoundwav

Some sounds fail to play on Android

About half of my audio files are failing to play on Android. They do work on windows and in the Unity Environment. I'm playing all of the audio the same way--something along the lines of:

 go = new GameObject();
 go.AddComponent<AudioSource>();
 go.audio.clip = Resources.Load(somePath);        
 go.audio.volume = 1;        
 go.audio.Play();

  • The files are all coming from the same location.

  • They are all marked as 2D.

  • All of the failing sounds are .WAV, though I do have working .WAV as well.

  • **All of the failing .WAV are 89kbps bit rate. The working .WAVs are 352kbps.

  • They are all marked as Form: Native (WAV) - Load Type: Load into memory.

  • If I set them to Audio Format: Compressed (MPEG) they DO work, but I'd like to know why.

Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by RyanZimmerman87 · Apr 05, 2014 at 01:05 AM

I'm not an expert with Unity sounds, far from it but I have used them a lot without any significant problems like you are describing.

My first suggestion would be to just play the sounds differently. I'm not sure why you are creating a new Game Object and adding an Audio Source and then loading a clip from the resources every time you play a sound. That seems pretty excessive and I'm not sure why you would do it like that at run time. I'm assuming your Android device is having trouble doing all that fast enough for some of your files.

89KBPS is a very strange bitrate too. I've never seen that personally myself. Generally 128kbps seems to be the sweet spot for me when it comes to size vs quality. 352KBPS seems way too big especially for the way you are doing this on Android.

So I'm not sure how you are setting up these sounds like what objects they are attached too. But I think it's a good idea to have one script attached to your camera that plays all the general game-play sounds/music. And then all your separate objects like consumables or enemies can have their own sounds on their script.

But I do it a lot differently than how you set it up, I'm not 100% sure but it seems like the way you are doing it is not optimal for slower devices.

I would recommend trying something like this to play your sounds:

 //declare sound variables publicly
 //can set them up super easy this way
 //no need to create a new game object
 //no need to create new audio source
 //no need to load sounds so many times
 //That advice is not factual just what I am assuming
 
 //so you declare audio clip variable publicly
 //this Game Object should already have 1 Audio Source
 public AudioClip usePotionSound;
 
 //when you want to play audio
 //just call a function to play sound
 //you already have gameobject, audioclip, and audiosource ready to go
 
 public void usePotionSoundFunction()
 {
 audio.PlayOneShot(usePotionSound);
 }
 
 //If you want more control 
 //you can do something like this
 //to change settings on audio source
 //for different clips
 
 public AudioClip punchSound;
 
 public AudioSource playerSkillsAudioSource;
 
 public void playerPunchSoundFunction()
 {
 playerSkillsAudioSource.clip = punchSound;
 playerSkillsAudioSource.minDistance = 10;
 playerSkillsAudioSource.Play();
 }

So I'm not 100% sure if this way is better than what you are doing. But it seems like it would be a lot better for mobile devices especially if you have all the sounds ready to go and loaded into memory instead of having to create a new game object and create new audio source and then load the resource.

You should also look into your bitrates both 89KBPS and 352KBPS seem a bit odd to me.

If these are short sound clips my understanding is that you should use .wav. For longer sounds like music that's when you wanna use the compressed.

If you try my examples and it still doesn't work maybe your Android device is just super slow or is running out of memory?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Warenth · Apr 05, 2014 at 01:21 AM 0
Share

Unfortunately I'm running some of these sounds as you suggest and am still experiencing the issue. I do plan to refactor the discussed approach in the near future, thanks for your feedback there.

As for the bitrates, these are audio files I stole from Ultima Online to use as place holders. I will keep your recommendations in $$anonymous$$d when I generate my sounds. Right now I'm just trying to better understand how unity works (or doesn't in some cases). Overall, lots of good info, I will up vote as soon as Unity gives me enough reputation to. Thanks Ryan!

avatar image RyanZimmerman87 · Apr 05, 2014 at 01:33 AM 0
Share

What kind of Android device are you using? $$anonymous$$aybe you are just running out of memory or can't load the sounds fast enough?

avatar image Warenth · Apr 09, 2014 at 02:59 PM 0
Share

Nexus 5, Nexus 7, and Galaxy S3. All have the exact same behavior.

avatar image
0

Answer by hieudev · Apr 08, 2014 at 10:13 PM

.mp3 Lame encoding works fine for me.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Save sound in unity to ringtone ( Android ) 1 Answer

Android Sound Delay 0 Answers

How to turn off sound on Android Device? 1 Answer

Android Sound Crackling. 1 Answer

Sound Vibration 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges