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
3
Question by Matt 11 · Dec 01, 2010 at 03:09 PM · audiostreamingclipping

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 ); }

Comment
Add comment · Show 5
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 Rennat · Dec 01, 2010 at 05:31 PM 0
Share

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

avatar image Matt 11 · Dec 01, 2010 at 06:46 PM 0
Share

when we want to play a strea$$anonymous$$g 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 );
 }
avatar image Matt 11 · Dec 01, 2010 at 06:49 PM 0
Share

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.

avatar image Rennat · Dec 02, 2010 at 06:02 AM 0
Share

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

avatar image Rennat · Dec 02, 2010 at 06:06 AM 0
Share

Everything I would check looks fine there to me, I now defer to stronger $$anonymous$$ds...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Flynn · Jan 17, 2011 at 10:54 AM

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

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 Waz · Feb 18, 2011 at 12:15 AM 0
Share

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

avatar image
0

Answer by Waz · Feb 18, 2011 at 12:41 AM

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(); }

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

No one has followed this question yet.

Related Questions

streaming local sound files on iOS 1 Answer

Audio Artefacts When Stopping/Destroying during play. 2 Answers

Get certain audio sources from unity as buffer? 0 Answers

Streaming audio from ffmpeg RTP into Unity 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