资 源 简 介
android语音录制和播放,部分代码://播放
player.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
if (!playState) {
mediaPlayer = new MediaPlayer();
String url = "file:///sdcard/my/voice.amr";
try
{
//模拟器里播放传url,真机播放传getAmrPath()
mediaPlayer.setDataSource(url);
//mediaPlayer.setDataSource(getAmrPath());
mediaPlayer.prepare();
mediaPlayer.start();
player.setText("正在播放");
playState=true;
//设置播放结束时监听
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (playState) {
player.setText("播放声音");
playState=false;
}
}
});
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalStateException e)
{
// TODO