package kr.co.company.audiorecord2;
import java.io.File;import java.io.IOException;import android.app.Activity;import android.media.MediaPlayer;import android.media.MediaRecorder;import android.os.Bundle;import android.os.Environment;import android.util.Log;import android.view.View;import android.widget.Button;public class AudioRecord2Activity extends Activity { private static final String LOG_TAG = "AudioRecorderTest"; private static String filename = null; Button play, record; private MediaRecorder recorder = null; private MediaPlayer player = null; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); filename = Environment.getExternalStorageDirectory().getAbsolutePath(); filename += "/test.3gp"; play = (Button) findViewById(R.id.play); record = (Button) findViewById(R.id.record); play.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { if (player == null) { player = new MediaPlayer(); try { player.setDataSource(filename); player.prepare(); player.start(); } catch (IOException e) { Log.e(LOG_TAG, "prepare() failed"); } play.setText("재생 중지"); } else { player.release(); player = null; play.setText("재생 시작"); } } }); record.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { if (recorder == null) { recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setOutputFile(filename); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); try { recorder.prepare(); } catch (IOException e) { Log.e(LOG_TAG, "prepare() failed"); } recorder.start(); record.setText("녹음 중지"); } else { recorder.stop(); recorder.release(); recorder = null; record.setText("녹음 시작"); } } }); } @Override public void onPause() { super.onPause(); if (recorder != null) { recorder.release(); recorder = null; } if (player != null) { player.release(); player = null; } }}
-------------------------------------------------------------------
위 소스는 AudioRecordActivity.java의 소스코드이며
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="kr.co.company.audiorecord2" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="kr.co.company.audiorecord2.AudioRecord2Activity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
--------------------------------------------------
위 소스는 매니페스트 파일 소스코드이고...
<?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">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="15pt"
android:autoText="false"
android:gravity="center_horizontal" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="녹음 관리"
android:textSize="30pt"
android:autoText="false"
android:gravity="center_horizontal" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="15pt"
android:autoText="false"
android:gravity="center_horizontal" />
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/record"
android:text="녹음 시작" ></Button>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="15pt"
android:autoText="false"
android:gravity="center_horizontal" />
<Button android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/play"
android:text="재생 시작" ></Button>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textSize="10pt"
android:autoText="false"
android:gravity="center_horizontal" />
</LinearLayout>
--------------------------------------------------------------------
main 레이아웃의 xml코드입니다..
java쪽은 생 초짜입니다만...
학교에서 안드로이드 앱 개발 프로젝트가 있어서 염치불구하고 질문글 올립니다.
책에서 소스코드를 가져왔으며
1-1. 여기서 저장되는 파일은 어떤 경로로 저장이 되는가?
1-2. sd카드로 저장을 각각 하고싶은데 어떤방법을 취하여야 하는가?
1-3. 파일명은 20151111_xxxxx.xxx같이 언제 녹음했는지 알수있게끔 하는 방법
에 대해 책만보고 무작정 따라하기엔 답이 안나와서 어찌해야할지 방법을 모르겠습니다
방법만이라도 알려주시면 감사하겠습니다 ㅠㅠ