Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 vasupol11 · Aug 18, 2017 at 10:58 AM · wwwaudioclipstream

How do I properly stream music with WWWAudioExtensions?

Here is my stream code

 IEnumerator musicStream(){
             using(WWW www = new WWW(Url)){
                 yield return www;
                 AudioClip f = WWWAudioExtensions.GetAudioClip(www, true, true, AudioType.MPEG);
                 AudioSource.clip = f;
             }
         }

I have been trying to stream music with the GetAudioClip method. Stream is set to true but having the yield function before the stream just basically mean I am waiting for the www to finish loading everything then play the clip.

 yield return www 
 AudioClip f = WWWAudioExtensions.GetAudioClip(www, true, true, AudioType.MPEG);


How do I properly use this, I cannot find any examples online.

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

1 Reply

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

Answer by vasupol11 · Aug 25, 2017 at 06:01 AM

To answer my own question again and for those who actually wonder if it is possible to stream music in unity, it is. Here is the code

  www = new WWW(url);
     while (www.progress < 0.01)
     {
         Debug.Log(www.progress);
         yield return new WaitForSeconds(.1f);
     }
     // yield return null;
     if (!string.IsNullOrEmpty(www.error))
     {
         Debug.Log(www.error);
     }
     else
     {
         clipa = WWWAudioExtensions.GetAudioClip(www, false, true, AudioType.MPEG);
         if (clipa.isReadyToPlay)
         {

             GetComponent<AudioSource>().clip = clipa;
             GetComponent<AudioSource>().Play();
         }
     }


Explanation: the .01 progress gets rid of a weird error that doesn't display anything. This error actually occurs because the file name still hasn't been downloaded. Waiting just till .01 is enough to get that information and allow it to stream. Remember to dispose of www somewhere, I did not include it in this code.

Comment
Add comment · Show 4 · 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 cspid · Dec 21, 2017 at 06:14 AM 0
Share

@vasupol11 I'm getting the blank console error when I try to use this code to stream OGGVORBIS. Any ideas why that would be?

Thanks

avatar image DVFrance cspid · Mar 23, 2018 at 02:18 PM 0
Share

As I understood OGGVORBIS may not be the right format for your platform: https://docs.unity3d.com/ScriptReference/WWW.GetAudioClip.html

avatar image unity_xrPBQ-2zcfd-DA · Mar 07, 2019 at 09:34 AM 0
Share

Hey, can you update your answer as WWWAudioExtensions.GetAudioClip is obsolete now.

avatar image willguest · Apr 14, 2020 at 02:29 PM 0
Share

a deprecated, but not obsolete alternative is www.GetAudioClip(false, true, AudioType.$$anonymous$$PEG). I am testing this for a WebGL build, where networking is not available and i want to stream from indexeddb.

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

76 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Endless Audio streaming (Radio)?! 3 Answers

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

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

WWW load mp3 GetAudioClip without stream,play only a part,then no sound. 0 Answers

Issues with WWW resource loading 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