- Home /
Mp3 Streaming on android
Hello,
I'm trying to do a mp3 streaming from sdCard in android, but it is not working, it just work when i set streaming=false but there is a huge delay and when i try to load a second file the application stops. On editor it works perfectly, just on android it not.
Does anyone know how can i solve this? Thanks (Sorry about the english)
public AudioSource player1;
public AudioSource player2;
private AudioClip clip1;
private AudioClip clip2;
void Start() {
}
void Update() {
}
public void Play(string file){
if(!player1.isPlaying){
loadFile(file, 1);
if(player2.isPlaying)
DecreaseVolume(2);
while(!player1.clip.isReadyToPlay){
Debug.Log("waiting1...");
}
player1.Play();
IncreaseVolume(1);
}else{
loadFile(file, 2);
if(player1.isPlaying)
DecreaseVolume(1);
while(!player2.clip.isReadyToPlay){
Debug.Log("waiting2...");
}
player2.Play();
IncreaseVolume(2);
}
}
private void loadFile(string path, int player){
WWW www = new WWW("file://"+path);
AudioClip myAudioClip = www.GetAudioClip(false, true, AudioType.MPEG);
if(player == 1)
player1.clip = myAudioClip;
if(player == 2)
player2.clip = myAudioClip;
}
Answer by JeffreyD · Feb 27, 2014 at 03:21 PM
Hi, The following talks about how to avoid lag when using WWW etc.. but not on Android. It looks as if it would work thought.. Perhaps it will help. http://answers.unity3d.com/questions/22170/how-to-avoid-lag-when-using-www-class-to-download.html
Thanks for the reply But i need to load the files from a external storage
Everything I read says you can use WWW to read in an external audio file from storage as long as you know the data path. I've not tried it yet on Desktop or on $$anonymous$$obile yet. It's on my to-do list and I've only done some $$anonymous$$imal research, hence my draw to your question. Here is another thread discussion. On page 2 a few guys say they have it running. http://forum.unity3d.com/threads/140088-Importing-audio-files-at-runtime If you find anything useful in your own searching please attach a comment. I will do the same. Thanks.
Your answer
Follow this Question
Related Questions
can't load music (wav and mp3 ) on android but the code works fine in editor and window build 0 Answers
Specific Market to be allowed to play the game 0 Answers
Upgrade from 5.0.1 to 5.1.2f1, cannot build in android now, continued. 1 Answer
How to play a .mp4 video file in android game 7 Answers
Unity Remote is not working! 0 Answers