- Home /
 
loading/streaming audioclip using www class [android]
Hi everyone, I am trying to make an android audio visualization app. To reduce the application size I tried using music already present on the phone using the www class. Fetching the music worked absolutely fine on the editor (even for mp3 files) but it gave (curl 7: can't connect to local host 80) and (fmod error: reached end while parsing, truncated essential data error) on the android build. Here is the main script that I am using for exporting music. Any suggestions or changes are welcome. If you have any sample project or code, fell free to reference it.
ps: I selected external mode in accessing data option in player settings d=for android path used for android /storage/0/download/music tested for windows in editor using D:\Downloads\music
[code=CSharp]using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using System.IO;
public class fetch : MonoBehaviour { public AudioSource ads; public string downloadString; public string musicString;
 List<string> mp3s=new List<string>();
 private void Start()
 {
     try
     {
         mp3s.AddRange(Directory.GetFiles(downloadString, "*.mp3"));
     }
     catch
     {
         Debug.Log("dir not found");
     }
     try
     {
         mp3s.AddRange(Directory.GetFiles(musicString, "*.mp3"));
     }
     catch
     {
         Debug.Log("dir not found");
     }
     foreach(string s in mp3s)
     {
         Debug.Log(s);
     }
 }
 int i = -1;
 public void nextTrack()
 {
     if (mp3s.Count > 0)
     {
         i = (i + 1) % mp3s.Count;
         StartCoroutine(LoadTrack(mp3s[i]));
     }
 }
 IEnumerator LoadTrack(string filename)
 {
     var www = new WWW(filename);
     //Wait for file finish loading
     while (!www.isDone)
     {
         //Debug.LogFormat("Progress loading {0}: {1}", filename, www.progress);
         yield return null;
     }
     var clip = www.GetAudioClip(false, true);
     ads.clip = clip;
     ads.Play();
 }
 
               } [/code]
Your answer
 
             Follow this Question
Related Questions
WWW.GetAudioClip Freeze 1 Answer
WWW.GetAudioClip hardware decoding? ( on iphone and android ) 1 Answer
Unable to import songs using NAudio 1 Answer
Unload audio from external source 1 Answer