Android Media Recorder录音播放源代码
5063 点击·0 回帖
![]() | ![]() | |
![]() | View Code 1 package irdc.ex07_11; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.util.ArrayList; 6 7 import Android.app.Activity; 8 import Android.content.Intent; 9 import Android.media.MediaRecorder; 10 import Android.net.Uri; 11 import Android.os.Bundle; 12 import Android.os.Environment; 13 import Android.view.View; 14 import Android.widget.AdapterView; 15 import Android.widget.ArrayAdapter; 16 import Android.widget.CheckedTextView; 17 import Android.widget.ImageButton; 18 import Android.widget.ListView; 19 import Android.widget.TextView; 20 import Android.widget.Toast; 21 22 public class EX07_11 extends Activity 23 { 24 private ImageButton myButton1; 25 private ImageButton myButton2; 26 private ImageButton myButton3; 27 private ImageButton myButton4; 28 29 private ListView myListView1; 30 private String strTempFile = "ex07_11_"; 31 private File myRecAudioFile; 32 private File myRecAudioDir;// 得到Sd卡path 33 private File myPlayFile; 34 private MediaRecorder mMediaRecorder01; 35 36 private ArrayList<String> recordFiles; 37 private ArrayAdapter<String> adapter;// 用于ListView的适配器 38 private TextView myTextView1; 39 private boolean sdCardExit; 40 private boolean isStopRecord; 41 42 /** Called when the activity is first created. */ 43 @Override 44 public void onCreate(Bundle savedInstanceState) 45 { 46 super.onCreate(savedInstanceState); 47 setContentView(R.layout.main); 48 //主要是4个控制按钮(录制,停止,播放,删除) 49 myButton1 = (ImageButton) findViewById(R.id.ImageButton01); 50 myButton2 = (ImageButton) findViewById(R.id.ImageButton02); 51 myButton3 = (ImageButton) findViewById(R.id.ImageButton03); 52 myButton4 = (ImageButton) findViewById(R.id.ImageButton04); 53 //列表出指定文件夹中所有amr格式音频文件 54 myListView1 = (ListView) findViewById(R.id.ListView01); 55 myTextView1 = (TextView) findViewById(R.id.TextView01); 56 57 myButton2.setEnabled(false); 58 myButton3.setEnabled(false); 59 myButton4.setEnabled(false); 布局文件main.xml View Code 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android" 3 Android:orientation="vertical" Android:layout_width="fill_parent" 4 Android:layout_height="fill_parent" Android:background="@drawable/white"> 5 <LinearLayout Android:id="@+id/LinearLayout01" 6 Android:layout_width="wrap_content" Android:layout_height="wrap_content"> 7 <ImageButton Android:id="@+id/ImageButton01" 8 Android:layout_width="wrap_content" Android:layout_height="wrap_content" 9 Androidrc="@drawable/record"> 10 </ImageButton> 11 <ImageButton Android:id="@+id/ImageButton02" 12 Android:layout_width="wrap_content" Android:layout_height="wrap_content" 13 Androidrc="@drawable/stop"> 14 </ImageButton> 15 <ImageButton Android:id="@+id/ImageButton03" 16 Android:layout_width="wrap_content" Android:layout_height="wrap_content" 17 Androidrc="@drawable/play"> 18 </ImageButton> 19 <ImageButton Android:id="@+id/ImageButton04" 20 Android:layout_width="wrap_content" Android:layout_height="wrap_content" 21 Androidrc="@drawable/delete"> 22 </ImageButton> 23 </LinearLayout> 24 <TextView Android:id="@+id/TextView01" Android:layout_width="wrap_content" 25 Android:layout_height="wrap_content" Android:textColor="@drawable/black"> 26 </TextView> 27 <ListView Android:id="@+id/ListView01" Android:layout_width="wrap_content" 28 Android:layout_height="wrap_content" Android:background="@drawable/black"> 29 </ListView> 30 </LinearLayout> my_simple_list_item.xml文件 View Code 1 <?xml version="1.0" encoding="utf-8"?> 2 <CheckedTextView xmlns:Android="http://schemas.Android.com/apk/res/Android" 3 Android:id="@+id/myCheckedTextView1" Android:layout_width="fill_parent" 4 Android:layout_height="fill_parent" Android:textColor="@drawable/white" /> 权限设置 <uses-permission Android:name="Android.permission.RECORD_AUDIO" /> 摘自 myphoebe | |
![]() | ![]() |