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
1
Question by WIL993 · Oct 30, 2013 at 11:28 PM · audiowwwaudioclipstreamingstream

Endless Audio streaming (Radio)?!

Hi,

I am new to unity and playing around trying to create a music visualizer for a university project, I would like to pull in a web based radio stream... say from Capital or Radio 1 and create visualizations based on what is playing. I have the visualization part working fine with just a sound clip, however cannot for the life of me get a stream to work.

I have bits of code:

 #pragma strict
 var url = "http://icy-e-05.sharp-stream.com:80/kiss100.mp3";
 function Start () {
     var www : WWW = new WWW (url);
  
     audio.clip = www.GetAudioClip(false,true);
 }
 function Update () {
     if(!audio.isPlaying && audio.clip.isReadyToPlay)
         audio.Play();
 }

But this will not work, i have tried both mp3 and ogg stream types with no luck, I believe probably because of the fact the radio stations are infinite streams.

I have read a little about NAudio however and too much of a n00b to be able to get my head round how this might work?

Is what I am trying to do possible?

Any help would be much appreciated! Thanks, Will

Comment
Add comment · Show 2
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 alee26 · May 19, 2014 at 09:18 PM -1
Share

Hi i am working on a similar code. I will post it but later becaue i am on a mobile device. did you solvez it ?

avatar image WIL993 alee26 · May 20, 2014 at 12:35 AM 0
Share

Hey nope I didn't find a solution to this, decided it was beyond my capabilities at the time and altered the project haha! Good luck though!

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by z2m · Feb 16, 2015 at 09:49 AM

Hi all. A work around for streaming audio is to dispose and reload the url while using the PlayOneShot function. My c# example isn't perfect but it should give you an idea of what to do.

 public class GetStream : MonoBehaviour {
 
     AudioClip clipa;
     AudioClip clipb;
     bool played;
     WWW www;
     float timer;
 
     public string url = "http://localhost:8080/stream.ogg";
     public int interval = 300;
 
     void Start(){
         clipa=null;
         played = false;
         timer=0;
 
     }
 
     void Update() {
         Debug.Log(timer);
 
         timer = timer+1*Time.deltaTime; //Mathf.FloorToInt(Time.timeSinceLevelLoad*10); 
                                         //Time.frameCount; 
 
         if(timer>=interval){             //if(timer%interval == 0){
             if(www != null){
                 www.Dispose();
                 www=null;
                 played = false;
                 timer=0;
             }
         }else{
             if(www == null){
                 www = new WWW(url);
             }
         }
         if(clipa==null){
             if(www != null){
                 clipa = www.GetAudioClip(false,true);
             }
         }
 
         if( clipa != null ){
             if( clipa.isReadyToPlay && played == false ){
                 audio.PlayOneShot(clipa);
                 played = true;
                 clipa=null;
             }
         }
     }
 }



Just attach the script to an object with an audiosource and enter the url of your choice. Hope that helps.

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 z2m · Feb 16, 2015 at 07:23 AM 0
Share

the interval works well around 30 for me.

avatar image alee26 · Feb 16, 2015 at 08:22 PM 0
Share

Thanks a lot for the code. I'll check it out as soon as possible. Regards

avatar image alee26 · Feb 21, 2015 at 07:30 PM 0
Share

z2m, I have checked it. This is working very well. I think it still needs some hand. Thanks a lot man.

avatar image
0

Answer by benoitlub · Apr 15, 2015 at 07:44 PM

This is working fine even with mp3, but I've got a problem with my test. If I put an interval at 10, the music restart every 10 sec and play over the previous one. And if i try at 9999 the first sound start only after 9999. I need to start as soon as possible and not to restart every n sec. How can I fix that. Do I need this interval? For streaming. I'd like to use something like a trigger to launch the stream, so if I push a second trigger I need to stop or pause the first music, any ideas?

I'm french graphic designer but less developper and I use unity5.

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 Adeola · Nov 09, 2015 at 05:51 PM 0
Share

Hi, Set the interval to a small number (so that it starts quickly). Then ins$$anonymous$$d of:

  if( clipa.isReadyToPlay && played == false ){
                  audio.PlayOneShot(clipa);
                  played = true;
                  clipa=null;
              }

use:

  if( clipa.isReadyToPlay && played == false ){
      if(!audio.isPlaying)
      {
            audio.clip = clipa; 
            audio.Play ();
            played = true;
            clipa=null;
      }
 }

This solves the problem you described.

avatar image
0

Answer by amirgame197 · Sep 16, 2020 at 07:53 PM

@z2m hi im used this code and i have error he saying cant stream MP3 sounds how to fix this problem? im not finded any no MP3 radio stations. how to stream MP3 radios?

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

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

How do i stream audio? 0 Answers

AudioClip "Stream from disc" does not work in standalone apps 0 Answers

Why does loading music files at runtime in android using www class takes a lot of time? 0 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