• 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
Question by gvergidis · Apr 06, 2018 at 07:20 AM · strange ioc

Radio streaming

Hello to all.

I'm New to unity and I am trying to learn developing applications for mobile devices with 3d graphics. So, in my first application I am creating a driving simulation and I want the player to listen to live radio stations. But, from my research till now, I could not make it happen. Unity's www library with streaming=true audio clips don't seem to work. Can anyone help me or give me a tip?

Any help appreciated.

Ps: I prefer not to use plugins since I want to learn do it on my own. Thank you in advance.

Comment

People who like this

0 Show 0
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

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by gvergidis · Apr 06, 2018 at 09:12 AM

@PaulKevin Thank you for your answer Paul. I am really looking for a no-plugin way so I can code it on my own and learn unity this way. Thank you anyways again for your answer.

Ok. So I managed to make a url stream BUT there are glitches of ~0.5 seconds between clip plays and ofcour the result is not acceptable. Can anyone help me?

The interval is 3 and I call this method on update if play boolean is true. Any ideas?

     IEnumerator streeeam()
         {
             Debug.Log(timer + " INT : " + interval);
     
             timer = timer + 100 * Time.deltaTime; 
     
             if (timer >= interval)
             {             //if(timer%interval == 0){
                 if (www != null)
                 {
                     www.Dispose();
                     www = null;
                     played = false;
                     timer = 0;
                 }
             }
     
             if (www == null)
             {
                 PLOG("www is empty. Going to initialize www.");
                 //www = new WWW(url);
                 www = new WWW("http://dromos898.live24.gr/dromos898");
                 PLOG("Downloading...");
                 //wait for the download to build up a buffer
                 while (www.progress < 0.001f)
                     yield return null;
                 PLOG("We got www. Lets proceed.");
             }
             clip = www.GetAudioClip(false, true, AudioType.MPEG);
             yield return clip;
     
             if (clip != null)
             {
                 PLOG("Clip is not null. Trying to play clip");
                 if (clip.loadState == AudioDataLoadState.Loaded && !played)
                 {
                     PLOG("Clip loaded. Going to play?");
                     if (!audioSource.isPlaying)
                     {
                         PLOG("We are not playing. So lets move on...");
                         audioSource.clip = clip;
                         audioSource.Play();
                         played = true;
                         clip = new AudioClip();
                         
                     }
                 }
                 play = true;
             }
         }
 
Comment
OFFIS_sebastian

People who like this

1 Show 0 · 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

Answer by Ginxx009 · Apr 06, 2018 at 08:22 AM

I guess this might help

  1. Download bass and bass.net from http://bass.radio42.com

  2. Place the 64-bit bass.dll into your unity root project folder

  3. Place the Bass.Net.dll into the unity plugins directory

  4. Create a c# file

    using UnityEngine; using System.Collections; using System.Runtime.InteropServices; using System; using Un4seen.Bass;

    public class AudioStream : MonoBehaviour { public string url = "http://111.11.11.11:1111/Live";

      private int stream;
      
         // Use this for initialization
         void Start ()
         {
             Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PLAYLIST, 0);
      
             Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
      
             stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT,  null, IntPtr.Zero);
      
             PlayStream(url);
         }
      
         public void PlayStream(string url)
         {
             if(stream != 0)
             {
                 Bass.BASS_ChannelPlay(stream, false);
             }
             else
             {
                 Debug.Log ("BASS Error Code = " + Bass.BASS_ErrorGetCode());
             }
         }
      
         public void StopStream()
         {
             Bass.BASS_ChannelStop(stream);
         }
      
         // Get the Channel Information
         public string  GetChannelInfo()
         {
             BASS_CHANNELINFO info = new BASS_CHANNELINFO();
             Bass.BASS_ChannelGetInfo(stream, info);
             return info.ToString ();
         }
      
         public void SetVolume(float value)
         {
             Bass.BASS_SetVolume(value);
         }
      
         void OnApplicationQuit()
         {
                 // free the stream
                 Bass.BASS_StreamFree(stream);
                 // free BASS
                 Bass.BASS_Free();
         }
      
     }
    
    
    
  5. Registering BassdotNet

.

  void Awake()
  {
  BassNet.Registration("sample@gmail.com", "XXXXXXXXXXX");
  }

Hope this might help you achieve what you are trying to do.

Comment
OFFIS_sebastian

People who like this

1 Show 0 · 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

Answer by OFFIS_sebastian · Jul 09, 2020 at 02:08 PM

@Ginxx009 That helped me, thank you.

Any way I can use this in conjunction with Audio Source, for spatial sound?

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

All objects turned white...??!!! 0 Answers

Making AI stop walking through walls but still allow them to enter windows. 1 Answer

Set PSIZE in Surface shader 0 Answers

How to find player Location? 4 Answers

How to change an int in a void? 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