WWW www = new WWW("file:///c://Test.ogg");
AudioSource audio = GetComponent<AudioSource>();
audio.clip = www.GetAudioClip(false,false,AudioType.OGGVORBIS);
audio.Play();
I’m not familiar with playing audio using this method, but you might have to give a little more background than just the code, depending on whether it’s correct or not.
I fixed it but when I load a xml file the audio won’t play\load.
using UnityEngine;
using System.Collections;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
public class main : MonoBehaviour {
private AudioSource source;
private string strm;
private string rootpath = "file:///C:/Data/";
void Start () {
LoadSceneData(rootpath+"Scenes/lvl0.map");
StartCoroutine(LoadTrack(rootpath+"Music/BG.ogg"));
}
IEnumerator LoadMusicTrack(string filename)
{
WWW www = new WWW(filename);
yield return null;
source = GetComponent<AudioSource>();
source.clip = www.GetAudioClip(false, true, AudioType.OGGVORBIS);
source.Play();
}
void LoadSceneData(string filename) {
XmlDocument xmlDoc= new XmlDocument(); // Create an XML document object
xmlDoc.Load(filename); // Load the XML document from the specified file
//Background Music Data
XmlNodeList StrmList = xmlDoc.SelectNodes("//Bgm");
foreach (XmlNode xn in StrmList)
{
strm = xn["Stream"].InnerText;
}
}
}