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.
I guess this might help
-
Download bass and bass.net from http://bass.radio42.com
-
Place the 64-bit bass.dll into your unity root project folder
-
Place the Bass.Net.dll into the unity plugins directory
-
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();
}
}
-
Registering BassdotNet
.
void Awake()
{
BassNet.Registration("sample@gmail.com", "XXXXXXXXXXX");
}
Hope this might help you achieve what you are trying to do.
@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;
}
}
@Ginxx009 That helped me, thank you.
Any way I can use this in conjunction with Audio Source, for spatial sound?