Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

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

$
0
0
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(); bgB = gameObject.AddComponent(); 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; } } ///////////////////////////////////////////////////////////

Viewing all articles
Browse latest Browse all 4709

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>