So, this seems like a very rudimentary thing but it doesn’t seem to be working properly for me 100% of the time.
I have a level playing a song and when the level is restarted, I want to capture the Audio.time, store it in a persistent variable, then once the new scene is loaded, play the song STARTING at the time I stored. Simple.
I’m getting intermittent results on both the iPhone and in editor.
As you can imagine, the playerprefs SetFloat is called before launching the new scene. The number is being stored properly and its also being recalled properly but audio.time seems to be bugged.
In the editor, this results in about 1/2 a second of playing the song from time 0, then it finally shifts to the point in the song where it is supposed to be playing from. This is WAY too much of a lag and 1/2 a second is really really noticable. If you call audio.time before play(), it does absolutely nothing, as far as I can see.
On the iPhone, on the other hand, the time gap is MUCH less small and is actually usable except for a new bug that rears its head. A strange loud clicking sound is heard, repeating the length of the song, what sounds to be a short blip once an update frame, and no, I’m not setting Play or audio.time in the update loop.
We had this problem too, and ended up using the plugin feature - play music through objective C classes, the delay is a lot smaller - less than 0.2(?) seconds or so.
Hope this helps
Hrm… Yeah, gonna scrap that and just submit today. Maybe I’ll fix it up for v2. Does anyone have specific instructions on creating an objC class to call music (iPhone Advanced) and communicating back, for an objC noob?
actually audio.time on a compressed audio track does not reflect the actual time in the track
Compressed audio is represented as a set of so-called packets. The length of a packet depends on the compression settings and can quite often be 2-3 seconds pr. packet. Essentially we just give those packets to the iPhone/Mac audio API and tell it to play. So far it is not possible to queue the API for where exactly inside the packet it is playing now. Unity reports the time of the start of currently playing packet as audio.time for compressed tracks.
Good to hear that Of course, it could be a nice idea to have a (moderated) comments option to the (online) docs as well, as is done the PHP docs. Just an idea
If anyone is eager to make addition, comment, fix, whatever to docs - please use bugreporter. We really appreciate people helping us to make documentation even better.
I’m jumping in on this thread because it’s audio related and was curious if anyone had a thought about pops at the beginning of every audio track I play…
The excellent tutorials and documentation is one of the major reasons I switched from iTGB to Unity. So keep up the great work, it’s definitely bringing you new customers.
Hey guys, have you tried the new commands that come with the new 2.6 edition ?
I just downloaded the 2.6 free, and I’m astonished how my abandoned project now is working just fine with this command:
audio.timeSamples
EG: to access the property of an audio source clip attached as component to a generic gameObject, I used:
transform.audio.timeSamples = storedTime;
To retrieve the current time:
storedTime = transform.audio.timeSamples;
is one of the new commands available in this version, I tried with success.
I know that actually this will not work on the iphone/ipod, but just to notify it to you.
By the way, I would like more control with Unity iPhone, on the mp3 stream (being able of setting precise timing on mp3 AAC compressed) COMING FROM MY iTUNES LIBRARY!
There is no point to include cool music (which I cannot include for copyright reasons) when you could directly access the iTunes library !
I’m a PC (linux/windows) guy, so I don’t know objective-c.
Has anybody coded something to access the ipod’s iTunes library which will work with Unity iPhone ?