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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by CostelloNicho · Mar 20, 2014 at 04:24 PM · audiowwwaudiocliplength

www.getAudioClip() Bug: One Second being cut off MP3.

Disclaimer: There are a few of these posts lingering around but nothing concrete enough for me or my company to call definite. Most of the posts are regarding streaming audio from a server, here I am trying to do a full download

Problem: Urgent!

WWW.getAudioClip(false, false) is returning a playable mp3 from our servers with the wrong length. One second is being removed from each of our mp3's. When going directly through our RESTFUL resource ( going to the url of the mp3 in a web browser ) the mp3 plays at full length. This is a major issue as we are sending voice messages between users.

Here's an example of what we have tried. We are not looking to stream the audio, hence the second false, but rather do a full download before playing.

 public IEnumerator StartAudio(string url)
     {
         AudioClip clip;
         WWW www  = new WWW (url);
         clip = www.GetAudioClip(false, false);
         while(www.progress < 1.0f && !www.audioClip.isReadyToPlay){ yield return null; }
         audioSrc.clip = clip;
         audioSrc.Play();
         if(isWaitingforAudio){ StopAllCoroutines(); }
         StartCoroutine(WaitForAudioFinish( audio.clip.length ));
         www.Dispose();
     }


I cannot give our URLs or any resources due to them being property of a different party. If you require any more specific information let me know.

This has the same results:

     public IEnumerator StartAudio(string url)
     {
         AudioClip clip;
         WWW www  = new WWW (url);
         yield return www;
         clip = www.GetAudioClip(false, false);
         audioSrc.clip = clip;
         audioSrc.Play();
         if(isWaitingforAudio){ StopAllCoroutines(); }
         StartCoroutine(WaitForAudioFinish( audio.clip.length ));
         www.Dispose();
     }

Comment
Add comment · Show 1
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 Graham-Dunnett ♦♦ · Mar 21, 2014 at 11:44 PM 1
Share

How do you know that too few bytes have been fetched? Does WWW.bytesDownloaded consistently give you too few bytes? Do the AudioClip.length, samples and frequency look correct? I wonder if the playback is too slow and the length kicks in before the samples are used up. Could mean the frequency is wrong?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CostelloNicho · Mar 25, 2014 at 07:44 PM

For anyone curious I switched over to streaming and this solved my problem. I will not be marking this as the answer because it does not directly address the question, its more of how I worked around it.

 public IEnumerator StartAudio(string url)
     {
         www  = new WWW (url); // Make the www request
 
         while(!www.audioClip.isReadyToPlay) // Wait till we have enough of a buffer to play the audio consitently
             yield return null;
 
         audioSrc.clip = www.GetAudioClip(false, true, AudioType.MPEG);
         audioSrc.loop = false;
         audioSrc.Play(); 
         
         if(isWaitingforAudio){ StopAllCoroutines( ); }
         StartCoroutine(WaitForAudioFinish( audio.clip.length ));
     }

There are a few things I found important here:

  1. Do not dispose of www instance while streaming. I only call dispose if the object is destroyed.

  2. Do not assigned getAudioClip() to a cached local variable, this had some unexpected results.

  3. Assigned the audio source directly with the stream ( www.getAudioClip() )

  4. No need to wait for a specific progress (www.progress), just wait till the www.audioClipIsReady before you assigned the audio clip stream to the audio source.

After further experimentation I've realized the above doesn't work as it is still downloading the full audio clip. The current not perfect solution I'm using is this:

 /// <summary>
     /// Start Audio:
     ///     - Downloads an audio clip from the server and plays. 
     /// </summary>
     /// <param name="url">URL of the audio clip.</param>
     public IEnumerator StartAudio(string url)
     {
         sprite.color = loadingColor; 
         //Set the color of the audio icon
         www  = new WWW (url); // Make the www request
 
         while(www.progress < .15f)
         {
             yield return null;
         }// Wait till we have enough of a buffer to play the audio consitently
 
         audioSrc.clip = www.GetAudioClip(false, true, AudioType.MPEG);
         audioSrc.loop = false;
 
         if(!audioSrc.clip.isReadyToPlay)
         {
             yield return null;
         }
         audioSrc.Play(); 
         
     }

Notes:

  • Audio some times (mainly with large files ) only plays the first 3 seconds then cuts off for the rest of the duration. When having that audio source play again from what was cached from the last request it play the full audio.

  • A small amount of of the mp3 file is being cut off the front and back of the audio file.

Still looking for more input. Thanks for your time.

Comment
Add comment · Show 1 · 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 DWilliams · Aug 31, 2015 at 07:39 PM 0
Share

Thank you for your workaround. After converting a project from Unity 4 to 5, I started getting this problem with audio clips loaded from Strea$$anonymous$$gAssets getting cut off, thankfully the GetAudioClip with strea$$anonymous$$g set to true seems to work well enough.

avatar image
0

Answer by Fattie · Jan 21, 2016 at 08:47 PM

Has Unity ever bothered even to address this problem?

Two years later ..

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

22 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

Related Questions

How to have www streaming to work with a radio station? 1 Answer

WWW GetAudioClip not working correctly for Unity 4? 1 Answer

loading/streaming audioclip using www class [android] 0 Answers

How do i stream music from a server? 0 Answers

How to avoid lag when using WWW class to download sound 3 Answers


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