- Home /
Streaming music
Is it possible to play audio streams in Unity 3D?
Thanks for the answer Sven. That is the approach I was taking as I am currently on Indie. Any idea where I am going wrong?
var url : String = "http://91.121.72.50:9106/";
function Start () {
var www : WWW = new WWW (url); // start a download of the given URL
audio.clip = www.GetAudioClip(false, true); // 2D, strea$$anonymous$$g
audio.Play();
}
you should check the audio.clip.IsReadyToPlay() is true before playing
The audio clip will not have an end though as it is a live stream
IsReadyToPlay will return true after it has enough data to play (~2k depending on the format). Beware you'll end up running out of memory if you stream in endless stream. Unless you destroy the AudioClip once in awhile though.
when I run this code it always reports that IsReadyToPlay is false.
var url : String = "http://radio.108.pl:8006/ambient.ogg";
function Start () {
var www : WWW = new WWW (url); // start a download of the given URL
audio.clip = www.GetAudioClip(false, true); // 2D, strea$$anonymous$$g
}
function Update() {
if (!audio.isPlaying && audio.clip.isReadyToPlay)
{
audio.Play();
}
else
{
Debug.Log("waiting - isplaying : " + audio.isPlaying + " isreadyToPlay : " + audio.clip.isReadyToPlay);
}
}
Answer by J3-Gaming · Sep 26, 2011 at 09:35 PM
Yes you can:
http://unity3d.com/support/documentation/ScriptReference/MovieTexture.html
If no movie is needed, just leave it blank, you can still access the audioClip property.
Mobile phone solution: http://unity3d.com/support/documentation/ScriptReference/iPhoneUtils.html
You have to script the assignment, gameObject.audioClip = downloaded$$anonymous$$ovieTexture.audioClip;
and then play the audio from the stream
I've deleted my answer as I was mistaken. Just wondering, is this also working on Indie version? There is no $$anonymous$$oviePlayback on the free version as I recall, so I was wondering if the strea$$anonymous$$g will work or not?
oh right, sorry to say I know of this solution as "Pro Only"
$$anonymous$$aybe the other answer with WWW would work, I think both could get you to the same goal. This one is more if you wanted video with audio, and I think WWW would be audio only.
Answer by Sren Christiansen · Sep 26, 2011 at 09:43 PM
Yes, use the WWW class and the function: function GetAudioClip (threeD : boolean, stream : boolean) : AudioClip and specify the 'stream' parameter to true.
Answer by FWCorey · Aug 03, 2012 at 06:20 AM
You can also put it on a single GameObject in an otherwise empty Scene then use Application.LoadLevelAdditiveAsync to stream it if this is for a WebPlayer build. I've used this method myself and it works fine.
Your answer
Follow this Question
Related Questions
Building a browserbased venue with streaming audio 0 Answers
Stream music in Unity mobile 0 Answers
Streaming Music from Disk 1 Answer
Background Music 3 Answers
Music Zones play music with tags? 0 Answers