1、语音播放直接用系统工具就好了,这个就不多说了,根据传入的路径(网络路径或本地路径均可)播放音频文件
/** * Created by zhb on 2017/1/16. * 音乐在线播放 */public class PlayManager { private Context mcontext; public PlayManager(Context context){ this.mcontext = context; } public void play(String song){ MediaPlayer mp = new MediaPlayer(); try {// 存储在SD卡或其他文件路径下的媒体文件// 例如:mp.setDataSource("/sdcard/test.mp3");// 网络上的媒体文件// 例如:mp.setDataSource("http://mand); process.waitFor(); ret = true; } catch (Exception e) { e.printStackTrace(); } finally { try { process.destroy(); } catch (Exception e) { e.printStackTrace(); } } return ret; } /**写入到raw文件*/ private void startBufferedWrite(final File file) { new Thread(new Runnable() { @Override public void run() { DataOutputStream output = null; try { output = new DataOutputStream(new BufferedOutputStream( new FileOutputStream(file))); while (isRecording) { int readSize = mRecorder.read(mBuffer, 0, mBuffer.length); for (int i = 0; i < readSize; i++) { output.writeShort(mBuffer[i]); } } } catch (IOException e) { e.printStackTrace(); } finally { if (output != null) { try { output.flush(); } catch (IOException e) { e.printStackTrace(); } finally { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } } } }).start(); }}5、最后在自己想调用的地方调用就好了,PathManger这个是我自己的路径管理工具,这里不贴了,反正自己直接放一个路径字符串进去就好了
/**初始化语音*/ private void initVoice() { //录音 RecordManager = new RecordManager( CallHelpActivity.this, String.valueOf(PathManger.getVoicePathToRaw()), String.valueOf(PathManger.getVoicePathToMp3())); callHelp_Voice_longclick.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch(event.getAction()){ case MotionEvent.ACTION_DOWN: RecordManager.start_mp3(); break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: RecordManager.stop_mp3(); break; } return false; } }); //语音播放 final PlayManager PlayManager = new PlayManager(this); callHelp_Voice_click.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PlayManager.play(String.valueOf(PathManger.getVoicePathToMp3())); } }); }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。