Android的播放两首歌曲的问题 [英] android playing two songs problem
问题描述
我有播放音频文件的问题。当我进入这两个词像'你好Tom',只有最后一个字打。但是,在我的日志猫似乎通过第一个字的歌曲。是我的code错了吗?或者是有什么解决办法到这里的第一首歌曲,然后在这里的第二首歌曲?任何解决方案是确定对我来说,例如它可以是这些歌曲之间的滞后。谢谢。
只见musicdroid code也即将nextsong。但我是新来的Android和我想不出我的集成code。的 musicdroid
公共无效函数(字符串[] []字)
{尝试{
对于(INT J = 0; J< word.length; J ++)
{
的for(int i = 0; I<字[J]。长度;我+ +)
{
的System.out.println(词:+字[J] [I]);
如果(字[J] [I] .equals(空)== FALSE)
{
mediaPlayer.reset();
mediaPlayer.setDataSource(/ SD卡/语音/+字[J] [I] +奥格);
媒体播放器prepare()。
mediaPlayer.start();
的System.out.println(字[J] [I] + - );
}
}
}
的System.out.println(结束);}
赶上(例外五)
{
的System.out.println(错误:+ e.getMessage());
}
}
在这里的我的日志猫。它似乎采取第一个声音,但不能播放。
9月4日至四日:58:18.934:信息/的System.out(363):字:喜九月四日至四日:58:18.944:信息/ StagefrightPlayer(34):的setDataSource('/ SD卡/语音/ hi.ogg')04-04 09:58:19.024:调试/ AudioSink(34):bufferCount(4)太小而增加到12九月四日至四日:58:19.024:信息/的System.out(363):您好,九月四日至四日:58:19.024:信息/的System.out(363):字:汤姆
九月四日至四日:58:19.034:信息/ StagefrightPlayer(34):的setDataSource('/ SD卡/语音/ tom.ogg')04-04 09:58:19.114:调试/ AudioSink(34):bufferCount(4)太小而增加到12九月四日至四日:58:19.124:信息/的System.out(363):tom-九月四日至四日:58:19.124:信息/的System.out(363):结束
您不要等到你玩在下单前第一个声音来完成。
尝试添加一个监听到媒体播放器,并播放第二个单词的第一个结束后。
退房setOnCompletionListener。
另外阅读文档在这里: http://developer.android.com/参考/安卓/媒体/ MediaPlayer.html
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
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
这篇关于Android的播放两首歌曲的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!