package com.mchron.icube.record;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Time;
import java.util.ArrayList;
import com.mchron.icube.data.AmbientSoundCode;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class AmbientSound extends Activity {
// /// Massage for Timer Handler
private static final int GUI_STOP = 0x111;
private static final int GUI_THREADING = 0x112;
// /// Massage for Refresh Audio File ListView
private static final int GUI_LIST_VIEW_REFRESH = 0x113;
// /// Massage for Record
private static final int MSG_FOR_RECORD_DURATION = 0x114;
// /// TAG for Exception
public static final String TAG = "SoundEx";
// /// buttons for record
private ImageButton mImageButtonRecord;
private ImageButton mImageButtonStop;
private ImageButton mImageButtonSetting;
// /// list view for displaying recorded audio files
private ListView mListViewRecordedFile;
// /// record progress
private ProgressBar mProgressBarRecord;
// /// record time
private TextView mTextViewRecordTime;
// /// recorded audio folder
private File mFileRecAudioDir;
// /// recorded audio file
private File mFileRecAudio;
// ///
private Uri mUriCurrentRecord;
private int mClipCount;
private int mClipTotal;
// /// instance of recorder
private MediaRecorder mMediaRecorder = null;
// /// instance of player
public MediaPlayer mMediaplayer = new MediaPlayer();
// /// recorded audio temp name
private String strTempFileName = "mChron_SoundEx_Ambient_Sound";
// /// adapter for display recorded audio files
private ArrayAdapter<String> mArrayAdapter;
// for recorded audio files
private ArrayList<String> mArrayListRecordedFiles;
// /// Handler for timer
private Handler mHandler;
// /// sdcard exists or not
private boolean mSdcardExists = false;
// /// second, minutes and hours for record
private int mSecond;
private int mMinute;
private int mHour;
private int mRecordTotalSeconds;
private int mRecordDuration = 0;
private int mRecordInterval = 0;
// /// progress current value
private int mProgessCurrentValue = 0;
// /// progress bar position
private int mProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ambient_sound);
// ////// initial buttons
initialControls();
// ///// set response function for record button
setOnClickFunctionForImageButtons(this);
// /// justify whether sdcard exists
mSdcardExists = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
// /// if sd card exists
if (mSdcardExists == true) {
// get the folder for store recorded audio files
mFileRecAudioDir = Environment.getExternalStorageDirectory();
// get all audio files
getRecordedAudioFiles();
// display the audio files in list view
mArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mArrayListRecordedFiles);
// // 将ArrayAdater添加ListView对象中
mListViewRecordedFile.setAdapter(mArrayAdapter);
}
// /// media player
if (mMediaplayer == null) {
try {
mMediaplayer = new MediaPlayer();
} catch (IllegalStateException e) {
e.printStackTrace();
Log.i(TAG, e.toString());
}
}
// /// set hanlder for timer
initialHanlderForTimer();
}
private void initialControls() {
mImageButtonRecord = (ImageButton) findViewById(R.id.icon_record);
mImageButtonStop = (ImageButton) findViewById(R.id.icon_stop);
mImageButtonSetting = (ImageButton) findViewById(R.id.icon_setting);
mProgressBarRecord = (ProgressBar) findViewById(R.id.progress_bar_record);
mTextViewRecordTime = (TextView) findViewById(R.id.text_view_time);
mListViewRecordedFile = (ListView) findViewById(R.id.list_view_record);
mImageButtonStop.setEnabled(false);
String strTotal = getString(R.string.ambient_sound_parameters_total_time_pre_set);
String strDuration = getString(R.string.ambient_sound_parameters_record_duration_pre_set);
String strInterval = getString(R.string.ambient_sound_parameters_record_interval_preset);
mRecordTotalSeconds = new Integer(strTotal);
mRecordDuration = new Integer(strDuration);
mRecordInterval = new Integer(strInterval);
}
private void setOnClickFunctionForImageButtons(Context context) {
if (mImageButtonSetting != null) {
mImageButtonSetting.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = getLayoutInflater();
final View layout = inflater.inflate(R.layout.ambient_sound_setting_dialog, null);
new AlertDialog.Builder(AmbientSound.this).setTitle(R.string.ambient_sound_parameters_setting)
.setView(layout)
.setPositiveButton(R.string.ambient_sound_dialog_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
try {
EditText mEditTextTotalTime = (EditText) layout
.findViewById(R.id.edit_text_total_time_parameter);
EditText mEditTextDuration = (EditText) layout
.findViewById(R.id.edit_text_record_duration);
EditText mEditTextInterval = (EditText) layout
.findViewById(R.id.edit_text_record_interval);
String strTotal = mEditTextTotalTime.getText().toString();
String strDuration = mEditTextDuration.getText().toString();
String strInterval = mEditTextInterval.getText().toString();
mRecordTotalSeconds = new Integer(strTotal);
mRecordDuration = new Integer(strDuration);
mRecordInterval = new Integer(strInterval);
TextView textViewTotalTime = (TextView) findViewById(R.id.text_view_total_time);
String strDisplayTotalTime = getString(R.string.ambient_sound_parameters_total_time);
strDisplayTotalTime += strTotal;
strDisplayTotalTime += " " + getString(R.string.ambient_sound_parameters_unit);
textViewTotalTime.setText(strDisplayTotalTime);
} catch (Exception e) {
e.printStackTrace();
Log.i(VoiceAnnotation.TAG, e.toString());
mRecordTotalSeconds = 0;
mRecordDuration = 0;
mRecordInterval = 0;
}
}
}).setNegativeButton(R.string.ambient_sound_dialog_cacel, null).show();
}
});
}
if (mImageButtonRecord != null) {
mImageButtonRecord.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mSdcardExists == false) {
String strWarningNoSDCard = AmbientSound.this.getResources().getString(
R.string.warning_for_no_sd_card);
Toast.makeText(AmbientSound.this, strWarningNoSDCard, Toast.L
没有合适的资源?快使用搜索试试~ 我知道了~
Android 录音播放示例
共85个文件
class:37个
png:18个
xml:13个
4星 · 超过85%的资源 需积分: 9 83 下载量 6 浏览量
2011-11-15
14:31:06
上传
评论
收藏 297KB RAR 举报
温馨提示
基于Android开发平台的声音录制接播放软件(单击播放)。用到了Android SQLite和ContentProvider等相关机制
资源推荐
资源详情
资源评论
收起资源包目录
SoundEx.rar (85个子文件)
SoundEx
bin
classes.dex 45KB
SoundEx.apk 83KB
com
mchron
icube
data
SoundExDBHelper.class 2KB
VoiceAnnotationCode.class 1KB
AmbientSoundCode.class 1KB
AmbientSoundContentProvider.class 5KB
VoiceAnnotationContentProvider.class 6KB
record
AmbientSound$5.class 1KB
VoiceAnnotation$3$1.class 2KB
AmbientSound$4.class 4KB
VoiceAnnotation$7.class 1KB
R$layout.class 538B
R$id.class 991B
R$drawable.class 1KB
VoiceAnnotation$8.class 3KB
AmbientSound$1.class 2KB
VoiceAnnotation$5.class 1KB
VoiceAnnotation.class 11KB
AmbientSound$2$1.class 3KB
VoiceAnnotation$2$1.class 4KB
VoiceAnnotation$6.class 1KB
VoiceAnnotation$2.class 2KB
AmbientSound$4$1.class 2KB
R$attr.class 355B
VoiceAnnotation$1.class 3KB
AmbientSound.class 13KB
AmbientSound$2.class 3KB
AmbientSound$1$1.class 3KB
VoiceAnnotation$2$2.class 2KB
R.class 619B
R$array.class 438B
VoiceAnnotation$1$1.class 2KB
R$string.class 1KB
AmbientSound$6.class 3KB
VoiceAnnotation$4.class 1KB
VoiceAnnotation$3.class 3KB
AmbientSound$3.class 2KB
SoundExActivity.class 2KB
adapter
DefinedArrayAdapter.class 2KB
resources.ap_ 60KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon_record_unable.png 6KB
icon_setting.png 7KB
ic_tab_artists_grey.png 791B
background.png 6KB
icon_play_play.png 6KB
ic_tab_artists_white.png 1KB
icon_stop_enable.png 6KB
icon_play_pause_enable.png 3KB
icon.png 5KB
icon_forward_enable.png 6KB
icon_forward_unable.png 6KB
icon_next_unable.png 6KB
icon_play_pause_unable.png 4KB
icon_record_enable.png 6KB
icon_next_enable.png 6KB
icon_stop_unable.png 6KB
drawable
icon_selector_forward.xml 303B
style_list_view_audio_file.xml 613B
icon_selector_stop.xml 291B
icon_tab_sound.xml 290B
icon_selector_record.xml 295B
icon_selector_play_pause.xml 307B
icon_selector_next.xml 291B
values
strings.xml 1KB
drawable-mdpi
icon.png 3KB
layout
voice_annotation.xml 2KB
ambient_sound.xml 3KB
ambient_sound_setting_dialog.xml 4KB
main.xml 790B
assets
default.properties 362B
gen
com
mchron
icube
record
R.java 4KB
proguard.cfg 1KB
src
com
mchron
icube
data
SoundExDBHelper.java 2KB
VoiceAnnotationCode.java 1KB
VoiceAnnotationContentProvider.java 4KB
AmbientSoundContentProvider.java 4KB
AmbientSoundCode.java 1KB
record
VoiceAnnotation.java 17KB
SoundExActivity.java 1KB
AmbientSound.java 22KB
adapter
DefinedArrayAdapter.java 1KB
.project 843B
.classpath 280B
AndroidManifest.xml 1KB
共 85 条
- 1
zxj081115
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页