问题
I have a problem playing audio files. when i entered two words like 'hi tom', only last word is playing. But in my log cat it seems to pass first word song. is my code wrong ? or is there any solution to here first song and then here second song? any solution is ok for me for example it can be lag between these songs. thanks. i saw musicdroid code also about nextsong. but i am new to android and i couldnt integrate my code.musicdroid
public void function (String[][] word)
{
try{
for (int j=0;j<word.length;j++)
{
for(int i=0;i<word[j].length;i++)
{
System.out.println("word:"+word[j][i]);
if(word[j][i].equals("empty")==false)
{
mediaPlayer.reset();
mediaPlayer.setDataSource("/sdcard/voice/"+word[j][i]+".ogg");
mediaPlayer.prepare();
mediaPlayer.start();
System.out.println(word[j][i]+"-");
}
}
}
System.out.println("end");
}
catch(Exception e)
{
System.out.println("error:"+e.getMessage());
}
}
here its my log cat. it seems to take first voice but not play.
04-04 09:58:18.934: INFO/System.out(363):word:hi
04-04 09:58:18.944: INFO/StagefrightPlayer(34): setDataSource('/sdcard/voice/hi.ogg')
04-04 09:58:19.024: DEBUG/AudioSink(34): bufferCount (4) is too small and increased to 12
04-04 09:58:19.024: INFO/System.out(363): hi-
04-04 09:58:19.024: INFO/System.out(363): word:tom
04-04 09:58:19.034: INFO/StagefrightPlayer(34): setDataSource('/sdcard/voice/tom.ogg')
04-04 09:58:19.114: DEBUG/AudioSink(34): bufferCount (4) is too small and increased to 12
04-04 09:58:19.124: INFO/System.out(363): tom-
04-04 09:58:19.124: INFO/System.out(363): end
回答1:
You don't wait for the first sound to finish before you play the next one. Try adding a listener to the mediaplayer, and play the second word after the first one finishes.
Check out the setOnCompletionListener.
Also read the docs here: http://developer.android.com/reference/android/media/MediaPlayer.html
来源:https://stackoverflow.com/questions/5537164/android-playing-two-songs-problem