Android Media Recorder录音播放源代码
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 android:src="@drawable/record">
10 </ImageButton>
11 <ImageButton android:id="@+id/ImageButton02"
12 android:layout_width="wrap_content" android:layout_height="wrap_content"
13 android:src="@drawable/stop">
14 </ImageButton>
15 <ImageButton android:id="@+id/ImageButton03"
16 android:layout_width="wrap_content" android:layout_height="wrap_content"
17 android:src="@drawable/play">
18 </ImageButton>
19 <ImageButton android:id="@+id/ImageButton04"
20 android:layout_width="wrap_content" android:layout_height="wrap_content"
21 android:src="@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_易做图_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
补充:移动开发 , Android ,