Hi,
Recently, I’ve been trying to load the music file(.mp3 or .ogg) selected by user to play. With an android plugin, I can get the file path. Here comes my question, how can I use www with file path to locate audio file and attach it to a audio source to play? My code is described below.
public string url = “file://”;
public AudioSource song;
// filepath is something like /mnt/sdcard/123.mp3
void MyFunction()
{
url = url + filepath;
WWW www = new WWW(url);
song.clip = www.audioClip;
song.Play();
}
If someone has the answer, please give me some help with this. Thanks.
There is one more thing, is there any solution for me to jump to the certain point of music to play. For example, with a input time I would make audio play at the input time. I tried audio.PlayScheduled()… but it seems not helpful.
My guess is that you don’t use AudioSettings.dspTime, but just want to do some playback. So, what you do need, is the variable time of the AudioSource component, see AudioSource.time here. And just set it like this:
audioSrc.time = 10 // 10 seconds (allows double, no float)