Play Audio x amount into the clip

I’m looking to set the time into an audio clip at which we start playing.

So I can use a ‘time progress bar’ to set the point into the audio we play from.

Like in a media player where you can skip ahead on a track.

Is there functionality with the unity audio classes that can accomplish this or is there a way it can be added.

OnSliderChange(float step)
audio.time = step * audio.clip.length;

I used something similar in my mini music editor. The step should be a float between 0 and 1.

I hope I could help you with this. :wink:

This is a bit of a disappointing answer, but through all my research into the matter it is impossible using the current unity system. However, not all is lost! The functions to do it exist in the unity engine but are not in a working state (they are new as of 3.5, latest build if I am correct) but how you would do the code would look something like this (once they get it working).

var AudioClipStart : AudioClip; //This is an audio file (compressed MP3 in this example) that we will modify.  This will be set using the unity editor.
private var AudioClipNew : AudioClip; //This is what the modified clip will be saved as, and we will then play it.

function Start() {
	var samples = new float[AudioClipStart.samples * AudioClipStart.channels];  //Build a list of all the sound data in the audio clip based on the original.
	var TimeReal : float = AudioClipStart.length; //The number we will use to offset the audioclip will not actually be in seconds, it will be in the segments the compression slices it into.
	var SegmentNumber : int = AudioClipStart.samples;  //This is the actual number of segments of the audio clip.
	var TimePerSegment = TimeReal/SegmentNumber;
	AudioClipStart.GetData(samples, 20 / TimePerSegment);  //Pull the data from the clip with an offset of 20 seconds.  We devide by the time per second to actually offset by a perfect 20 seconds instead of something shorter or longer.
	AudioClipNew.SetData(samples, 0); //We pulled the data from the original with an offset of 20 seconds, now we apply it to the new with no offset, making this audio clip 20 seconds ahead of the original.
	audio.clip = AudioClipNew; //Set the audio source's clip to the new audioclip.
	audio.Play(); //Play the audio and hear the effect.

Sadly this code doesn’t work because the key components of it (AudioClip.GetData(data : float,Offset : int) and AudioClip.SetData(data : float,Offset : int)) are non operational. I would recommend asking unity to fix this by the next version.

Best of luck to you in the future.

you could try something like:
function OnStart () {; }

Then in the inspector, add the script to the player, and add the audio clip you want to play to the script.