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
1
Question by simpson45711 · Dec 02, 2014 at 07:23 PM · c#iosaudio

Audio: how do I immediately play a new audioclip without delay(code included)?

I currently have 2 Background music audio clips which I want to play immediately one after another (intro followed by a loop when the intro is done playing).

However, no matter what I try, there seems to me a noticeable gap when transitioning from one track to an other... Is there any way around this (other than crossfading)

Below is what I have come up with so far:::

 ///////////////////////////////////////////////////////////
 private static bool loopStarted = false;
 public AudioClip backGroundMusic_Intro;
 public AudioClip backGroundMusic_Loop;

     //--Separate audio sources to try and avoid loading delays
 private AudioSource bgA;
 private AudioSource bgB;    


 void Awake(){
     
     bgA = gameObject.AddComponent<AudioSource>();
     bgB = gameObject.AddComponent<AudioSource>();
     
     bgA.clip = backGroundMusic_Intro;
     bgB.clip = backGroundMusic_Loop;

     bgA.loop = false;
     bgB.loop = true;
     
     bgA.Play ();
 }

 // Fixed Update called multiple times per frame
 void FixedUpdate () {
     if(loopStarted == false && !(bgA.isPlaying)){
         bgB.Play();
         Destroy (bgA);
         loopStarted = true;
     }
 }
 ///////////////////////////////////////////////////////////

Comment
Add comment · Show 1
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 gamegirl1984 · Dec 02, 2014 at 08:05 PM 0
Share

I'm a noob but thought I would throw my 2 cents in. You may have to use a different type of script though. Have your 2nd audio clip set up on "yeild waitforseconds() and put in exactly how many seconds your first one is?? so the 2nd clip would start playing right after the first one?? Add play one shot on first clip and loop on 2nd?? Not sure if that would work but you could try somthing like that??

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JoeStrout · Jun 26, 2016 at 07:36 PM

It is your script, actually. You can't use Play to stitch together audio clips seamlessly like this. You need to instead use PlayScheduled.

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

Answer by 5argon · Oct 29, 2017 at 12:43 PM

I have build a solution called Introloop (http://exceed7.com/introloop/). It uses various Scheduled methods together with multiple AudioSources to achieve seamless transition from intro to looping part.

If you want to build it yourself, in that website I have also explained my approach. You can get the rough idea if you are new to audio scripting.

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

30 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to have two audio listeners...splitscreen 4 Answers

Multiple Tiled GPU warning: RenderTexture color surface errors? 0 Answers

How to Name Individual Buttons Within a List 2 Answers

C# Check If Scripted Gameobject goes Past Variable Gameobject 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