forked from dkim0419/SoundRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added RecordingService to handle audio recording
- Loading branch information
Showing
16 changed files
with
113 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
148 changes: 0 additions & 148 deletions
148
app/src/main/java/com/danielkim/soundrecorder/MainActivity.java
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/danielkim/soundrecorder/RecordingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.danielkim.soundrecorder; | ||
|
||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.media.MediaRecorder; | ||
import android.os.Environment; | ||
import android.os.IBinder; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
/** | ||
* Created by Daniel on 12/28/2014. | ||
*/ | ||
public class RecordingService extends Service { | ||
|
||
private static final String LOG_TAG = "SoundRecorder_RecordFragment"; | ||
|
||
SimpleDateFormat formatter; | ||
Date now; | ||
private String mFileName = null; | ||
|
||
private MediaRecorder mRecorder = null; | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
startRecording(); | ||
return START_STICKY; | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
if (mRecorder != null) { | ||
stopRecording(); | ||
} | ||
|
||
super.onDestroy(); | ||
} | ||
|
||
public void startRecording() { | ||
formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); | ||
now = new Date(); | ||
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath(); | ||
mFileName += "/SoundRecorder/" + formatter.format(now) + "_soundrecorder.mp4"; | ||
|
||
mRecorder = new MediaRecorder(); | ||
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); | ||
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); | ||
mRecorder.setOutputFile(mFileName); | ||
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); | ||
|
||
try { | ||
mRecorder.prepare(); | ||
mRecorder.start(); | ||
|
||
} catch (IOException e) { | ||
Log.e(LOG_TAG, "prepare() failed"); | ||
} | ||
} | ||
|
||
public void stopRecording() { | ||
mRecorder.stop(); | ||
mRecorder.release(); | ||
Toast.makeText(this, "Recording saved to " + mFileName, Toast.LENGTH_LONG).show(); | ||
mRecorder = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Oops, something went wrong.