Back to project page android-qq.
The source code is released under:
Apache License
If you think the Android project android-qq listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.myandroid.util; //from www . j a va 2s .c o m import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import android.media.MediaPlayer; import android.media.MediaRecorder; import android.os.Environment; public class Media { // ????????? private MediaPlayer myPlayer; // ?? private MediaRecorder myRecorder; // ???????????? public String sendpath,receivepath;// path/xx.amr?????????? public String name;//?????? private File saveFilePath; public Media() { if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { try { sendpath = Environment.getExternalStorageDirectory() .getCanonicalPath().toString() + "/MessageMediaSend"; File files = new File(sendpath); if (!files.exists()) { files.mkdir(); } } catch (IOException e) { e.printStackTrace(); } } if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { try { receivepath = Environment.getExternalStorageDirectory() .getCanonicalPath().toString() + "/MessageMediaReceive"; File files = new File(receivepath); if (!files.exists()) { files.mkdir(); } } catch (IOException e) { e.printStackTrace(); } } } //????? public void startRecord() { myRecorder = new MediaRecorder(); // ????????????? myRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); // ?????????? myRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); // ???????? myRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); //?????? this.name="AND"+Tools.getRandomId() + new SimpleDateFormat( "yyyyMMddHHmmss").format(System .currentTimeMillis()) + ".amr"; String paths = sendpath+"/"+name; saveFilePath = new File(paths); myRecorder.setOutputFile(saveFilePath .getAbsolutePath()); try { saveFilePath.createNewFile(); myRecorder.prepare(); } catch (IOException e) { e.printStackTrace(); } // ????? myRecorder.start(); } //????????? public void stopRecord() { if (saveFilePath.exists() && saveFilePath != null) { myRecorder.stop(); myRecorder.release(); } } //??? public void destroy() { // ?????? if (myPlayer.isPlaying()) { myPlayer.stop(); myPlayer.release(); } myPlayer.release(); myRecorder.release(); } //??????? public void startPlay(String path0) { myPlayer = new MediaPlayer(); try { myPlayer.reset(); myPlayer.setDataSource(path0); if (!myPlayer.isPlaying()) { myPlayer.prepare(); myPlayer.start(); } else { myPlayer.pause(); } } catch (IOException e) { e.printStackTrace(); } } //?????? public void stopPlay() { if (myPlayer.isPlaying()) { myPlayer.stop(); } } }