Android Media Recorder source code

Source: Internet
Author: User

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; // obtain the SD card path
33 private File myPlayFile;
34 private MediaRecorder mMediaRecorder01;
35
36 private ArrayList <String> recordFiles;
37 private ArrayAdapter <String> adapter; // The adapter used for 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 // four control buttons (recording, stopping, playing, and deleting)
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 // list all audio files in amr format in the specified folder
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 );
 
Layout file 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_simple_list_item.xml File
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"/>
Permission settings
<Uses-permission android: name = "android. permission. RECORD_AUDIO"/>

 

From myphoebe

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.