x


streaming audio clipping with unity 3.X

While using unity2.6, we had this problem where the audio sound clip would cut out mid-way through playing towards the end of the clip. After upgrading to unity3.X we noticed this continued to happen. Is there any solution / workaround with the new version of unity?

Thanks.

(better code formatting...)

private IEnumerator PlayEffect( GameObject effect )
{ 
   while( !effect.audio.clip.isReadyToPlay ) 
   { 
      yield return( 1 ); 
   } 

   effect.audio.Play(); 
   yield return( new WaitForSeconds( effect.audio.clip.length ) ); 

   while( effect.audio.isPlaying ) 
   { 
      yield return( 1 ); 
   } 
   DestroyImmediate( effect.audio.clip ); 
   DestroyImmediate( effect ); 
}
more ▼

asked Dec 01 at 03:09 PM

Matt 11\'s gravatar image

Matt 11
101 3 3 11

are you checking AudioClip.isReadyToPlay before you start playing? ( http://unity3d.com/support/documentation/ScriptReference/AudioClip-isReadyToPlay.html )

Dec 01 at 05:31 PM Rennat

when we want to play a streaming audio clip, the following coroutine gets started...

private IEnumerator PlayEffect( GameObject effect )
{
        while( !effect.audio.clip.isReadyToPlay )
        {
            yield return( 1 );
        }

        effect.audio.Play();

        yield return( new WaitForSeconds( effect.audio.clip.length ) );

        while( effect.audio.isPlaying )
        {
            yield return( 1 );
        }

        DestroyImmediate( effect.audio.clip );
        DestroyImmediate( effect );
}
Dec 01 at 06:46 PM Matt 11

sorry for the poor formatting... as you can see, we are yielding for the audio clip's length, and then for good measure, yielding while the isPlaying flag is returning true on the audio component.

Dec 01 at 06:49 PM Matt 11

you can edit your question and put that code in it :)

Dec 02 at 06:02 AM Rennat

Everything I would check looks fine there to me, I now defer to stronger minds...

Dec 02 at 06:06 AM Rennat
(comments are locked)
10|3000 characters needed characters left
 moderation talk

2 answers:

Everything checks out with me too. In fact, I programmed something not-to-different and it worked fine.

Perhaps the issue is in your audio file? Unity might have troubles importing it off the net.

DISCLAIMER: These .ogg URLs are provided by the Xiph Open Source Community. http://www.vorbis.com/music/Epoq-Lepidoptera.ogg <-- Recommended. Starts up fast, loud audio. http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg <-- Shortest one http://www.vorbis.com/music/Lumme-Badloop.ogg http://www.vorbis.com/music/Mists_of_Time-4T.ogg http://www.vorbis.com/music/The_Abyss-4T.ogg

Source: http://www.vorbis.com/music/

I hope this helps. -- Flynn

more ▼

answered Jan 17 at 10:54 AM

Flynn\'s gravatar image

Flynn
898 9 15 27

Doesn't work at all with 3.2 on Windows. Nor does the code straight from the docs: http://unity3d.com/support/documentation/ScriptReference/WWW.GetAudioClip.html

Feb 18 at 12:15 AM Warwick Allison
(comments are locked)
10|3000 characters needed characters left
 moderation talk

Seems in 3.2 streaming does not work at all for OGG files: once you call WWW.audioClip, you've just got the samples for whatever OGG is so-far downloaded (not much when isReadyToPlay first becomes true!).

The best I've been able to do is this horrible hack (basically reconvert from OGG once the bit that was downloaded is almost finished playing):

var url = "http://www.vorbis.com/music/Epoq-Lepidoptera.ogg";

function Start () {
    var www = new WWW(url);
    audio.clip = www.audioClip;
    while (!www.isDone) {
        yield WaitForSeconds(1);
        if (audio.time > audio.clip.length-2) {
            audio.clip = www.audioClip;
        }
    }
}

function Update () {
    if(!audio.isPlaying && audio.clip.isReadyToPlay)
        audio.Play();
}    
more ▼

answered Feb 18 at 12:41 AM

Warwick Allison\'s gravatar image

Warwick Allison
5.6k 18 29 65

(comments are locked)
10|3000 characters needed characters left
 moderation talk
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x601
x66
x46

Asked: Dec 01 at 03:09 PM

Seen: 1428 times

Last Updated: Dec 03 at 03:30 PM

powered by Qato - Enterprise Q&A