x


How To set the start time of an audiosource

Hey

I want my game to remember where the music left off if you quit the application. Can someone explain to me why the following doesn't seem to work and how to properly set the start time of an audio source:

var test : AudioSource;

function Start()
{
    test.time = 3.00;
    test.Play();
    print (test.time);
}

The print gives a number close to 0 like 0.27xxx I'm using an Mp3 for the music, and I'm working with unity iphone.

Thanks! you all rock!

Cheers

Vin

more ▼

asked Apr 04 '10 at 01:07 PM

Jaywalker gravatar image

Jaywalker
514 15 21 30

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I think with mp3 sounds, because of the method of compression where the sound data is split into discrete 'frames', there's a limit to the resolution at which you can specify any given time within the sound.

You might find that if you use uncompressed sound, you get a finer degree of accuracy, however this will of course inflate the filesize a lot.

more ▼

answered Apr 04 '10 at 01:26 PM

duck gravatar image

duck ♦♦
41k 92 148 415

Hey wow, thanks for the ultra fast reply! I don't need it to be super accurate, but if i change the value to say 40. It still starts a 0. it just doesn't change at all!

thanks again!

Apr 04 '10 at 01:30 PM Jaywalker

Hm, strange. Have you tried swapping the order around, so you call Play() first, then set the time on the next line?

Apr 04 '10 at 04:15 PM duck ♦♦

Thats it! starting the audio first makes it work! thanks a lot!

Apr 05 '10 at 06:48 AM Jaywalker

+1 and 10k @Duck :) happy moderating..!!!

Apr 05 '10 at 01:53 PM Lipis

@Duck - congrats, o Lord of Unity! :) Try to use your powers wisely...

Apr 05 '10 at 03:36 PM Cyclops
(comments are locked)
10|3000 characters needed characters left
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:

x5095
x573
x171

asked: Apr 04 '10 at 01:07 PM

Seen: 1869 times

Last Updated: Apr 04 '10 at 01:07 PM