Playing back from AudioSource.time seconds without a hiccup

I would like something as simple as this to work:

musicTime = audio.time;
audio.clip = //some other clip;
audio.Play();
audio.time = musicTime;

However, the beginning of the audio file plays for a moment before it plays from the proper point. What’s the cleanest way to do this?

I know that this post is very old but I’ve a really big problem with AudioSource.time property: IT DOESN’T SEEMS TO WORK IF YOU TRY TO ASSIGN IT A VALUE !!!

I’ve also tried to post in another topic of mine this problem but nobody has answered to me :cry:

In specific I’m trying to do:

	/// <summary>
	/// called to start the sound play
	/// </summary>
	private void playSound () {
		if (audio) {
			audio.time = 1.74f;
			Debug.Log ("audio time when started = " + audio.time);
			audio.Play ();
		} // if
	} // playSound

but it seems to start always at 0.0f !!!

Am I wrong, or there are some problems?

Please… let me know something about !!!

If you’re interested here you can find my other post about audio manipulation.

Try doing Play first, then set the time, not the other way around.

–Eric

Ok… it works !!
But wait a sec: if a need a precision of starting a sound at the order of 0.001 sec why I cannot have the possibility to seek the sound cursor BEFORE to play the sound? I mean, if I seek the cursor after playing the sound could it cause some lack of time? If I have to synchronize the sound with an animation this must be very annoying.

However… 10thousands thanks Eric !!! :smile:

I don’t think so…those lines of code are executing during the same frame. So you tell the sound to play, and then tell it what time, and it will start playing at that time.

–Eric

Yeah, you’d think. Except the point of this thread was that it doesn’t work! So if there is no actual way to make it work, I should file a bug.

In fact I’ve done some others tries but… there are a lot of strange behaviours about this property. have you noticed that this instruction will be executed 2 times each call?

If you’re making the call from inside OnGUI() – which you shouldn’t be :slight_smile: --, then 2 calls per frame is by design. OnGUI() always gets called twice per frame, once for layouting and once for rendering.

If you’re not making the call from inside OnGUI(), then two executions of an instruction is a bug and please report it using the Bug Reporter.

Load the _SingleFileScene scene and try.

It seems that the last function is called 2 times but it must be an Invoke issue and not a AudioSource.Time problem in itself !!!
Sorry to made a mess :stuck_out_tongue:

118316–4480–$test_sul_loop_dei_suoni_162.zip (1.69 MB)