編輯:Android開發實例
View Code
package irdc.ex07_11;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class EX07_11 extends Activity
{
private ImageButton myButton1;
private ImageButton myButton2;
private ImageButton myButton3;
private ImageButton myButton4;
private ListView myListView1;
private String strTempFile = "ex07_11_";
private File myRecAudioFile;
private File myRecAudioDir;// 得到Sd卡path
private File myPlayFile;
private MediaRecorder mMediaRecorder01;
private ArrayList<String> recordFiles;
private ArrayAdapter<String> adapter;// 用於ListView的適配器
private TextView myTextView1;
private boolean sdCardExit;
private boolean isStopRecord;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//主要是4個控制按鈕(錄制,停止,播放,刪除)
myButton1 = (ImageButton) findViewById(R.id.ImageButton01);
myButton2 = (ImageButton) findViewById(R.id.ImageButton02);
myButton3 = (ImageButton) findViewById(R.id.ImageButton03);
myButton4 = (ImageButton) findViewById(R.id.ImageButton04);
//列表出指定文件夾中所有amr格式音頻文件
myListView1 = (ListView) findViewById(R.id.ListView01);
myTextView1 = (TextView) findViewById(R.id.TextView01);
myButton2.setEnabled(false);
myButton3.setEnabled(false);
myButton4.setEnabled(false);
布局文件main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/white">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageButton android:id="@+id/ImageButton01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/record">
</ImageButton>
<ImageButton android:id="@+id/ImageButton02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/stop">
</ImageButton>
<ImageButton android:id="@+id/ImageButton03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/play">
</ImageButton>
<ImageButton android:id="@+id/ImageButton04"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/delete">
</ImageButton>
</LinearLayout>
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="@drawable/black">
</TextView>
<ListView android:id="@+id/ListView01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/black">
</ListView>
</LinearLayout>
my_simple_list_item.xml文件:
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" />
如上一節中所講的那樣創建了ApiDemo工程後,我們就可以進行每個示例代碼的分
Android提供了許多方法來控制播放的音頻/視頻文件和流。其中該方法是通過一類稱為MediaPlayer。Android是提供MediaPlayer類訪問內置的媒體播放
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用
Android應用程序可以在許多不同地區的許多設備上運行。為了使應用程序更具交互性,應用程序應該處理以適合應用程序將要使用的語言環境方面的文字,數字,文件等。在本章中,我