- Home /
It is possible to start a streaming AudioClip not from the beginning ?
For exemple, i got a music in my HDD, i load it into streaming (because i need to), is there a way to start the song from 0:30 for example and not from the beginning, or says "go to 0:30" ?
Answer by skalev · Sep 11, 2012 at 03:48 AM
The documentation clearly states that AudioSource.timeSamples won't work with streaming clips. You have to load it into memory if you want to be able to use this feature. (I know, I wished this was different too).
EDIT - Was able to get this to work, please see comments.
Yep, i see that, but the question is : can be resolve this with an other way ? Is it possible ? Or is there absolutly NO way to do this ?
Not to the best of my knowledge. It open up a can of worms to allow such a thing, so I guess that is why it was designed this way.
What are you trying to achieve? you can potentially just cut up the files into smaller chunks and stream the parts you want, and manage the transitions between files manually.
What about making two strea$$anonymous$$g audio clips for each song? One strea$$anonymous$$g clip is the entire song, and the other is a section cut out from the song. Then just stream that one when someone wants to listen to the preview.
Ok. So I guess I was mistaken. I remembered seeing this before, but was unable to find the doc about it again. So I wrote a quick test, and found that it does actually work, meaning that you CAN skip ahead in the clip. Sorry for the wrong information, I can't for the life of me remember now where I saw it, but this actually helps me in my project too :)
Just to clarify, in order to get the clip to start at the position you want it too, set the timeSamples variable of the AudioSource BEFORE you call Play(). This will ensure it will start at the correct position.
I managed to get that to work. I think the trick is that you have to load enough of it before you skip forward. I was going to run a test today to see if I can query the file to make sure it loaded to the point I want to play... will keep you posted.