Example usage for android.media MediaRecorder release

List of usage examples for android.media MediaRecorder release

Introduction

In this page you can find the example usage for android.media MediaRecorder release.

Prototype

public native void release();

Source Link

Document

Releases resources associated with this MediaRecorder object.

Usage

From source file:Main.java

/**
 * task: pause recording/*from  w  ww. j a v a  2  s.c  om*/
 * @param mediaRecorder   object to operator
 */
public static void pauseRecording(MediaRecorder mediaRecorder) {
    mediaRecorder.stop(); // stop recording
    mediaRecorder.release(); // release the resource
}

From source file:Main.java

public static void stopRecordAction(MediaRecorder recorder) {
    if (recorder != null) {
        recorder.stop();/*w  w w  .j ava 2s  .c o  m*/
        recorder.release();
        recorder = null;
    }
}

From source file:Main.java

public static void stopRecording(MediaRecorder mRecorder) {
    if (mRecorder != null) {
        mRecorder.stop();//from w  ww . ja v  a 2s  .c o  m
        mRecorder.release();
    }
}

From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java

public String getMicrophoneSample() {
    String out = "";
    String fileName = "microphone.3gp";

    MediaRecorder recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    recorder.setOutputFile(MyApp.context.getFilesDir() + "/" + fileName);

    try {/* w  w  w.java2  s .c  o  m*/
        recorder.prepare();
        recorder.start();
        Thread.sleep(5000);
        recorder.stop();
        recorder.release();

        File f = new File(MyApp.context.getFilesDir() + "/" + fileName);
        FileInputStream fileIn = MyApp.context.openFileInput(fileName);
        InputStreamReader isr = new InputStreamReader(fileIn);

        char[] tmpBuf = new char[(int) f.length()];
        isr.read(tmpBuf);
        out = new String(tmpBuf);

    } catch (Exception e) {
        e.printStackTrace();
    }

    return out;
}

From source file:me.ziccard.secureit.async.AudioRecorderTask.java

@Override
public void run() {

    MicrophoneTaskFactory.pauseSampling();

    while (MicrophoneTaskFactory.isSampling()) {
        try {//w w  w. j  ava2s. c o  m
            Thread.sleep(50);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    recording = true;
    final MediaRecorder recorder = new MediaRecorder();

    ContentValues values = new ContentValues(3);
    values.put(MediaStore.MediaColumns.TITLE, filename);

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

    String audioPath = Environment.getExternalStorageDirectory().getPath() + filename + ".m4a";

    recorder.setOutputFile(audioPath);
    try {
        recorder.prepare();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    Log.i("AudioRecorderTask", "Start recording");
    recorder.start();
    try {
        Thread.sleep(prefs.getAudioLenght());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    recorder.stop();
    Log.i("AudioRecorderTask", "Stopped recording");
    recorder.release();
    recording = false;

    MicrophoneTaskFactory.restartSampling();

    /*
     * Uploading the audio 
     */
    Log.i("AudioRecorderTask", "Trying to upload");
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost request = new HttpPost(Remote.HOST + Remote.PHONES + "/" + phoneId + Remote.UPLOAD_AUDIO);

    Log.i("AudioRecorderTask", "URI: " + Remote.HOST + Remote.PHONES + "/" + phoneId + Remote.UPLOAD_AUDIO);
    /*
     * Getting the audio from the file system
     */
    MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    File audio = new File(audioPath);
    reqEntity.addPart("audio", new FileBody(audio, "audio/mp3"));
    request.setEntity(reqEntity);

    /*
     * Authentication token
     */
    request.setHeader("access_token", accessToken);

    try {
        HttpResponse response = httpclient.execute(request);

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        StringBuilder builder = new StringBuilder();
        for (String line = null; (line = reader.readLine()) != null;) {
            builder.append(line).append("\n");
        }

        Log.i("AudioRecorderTask", "Response:\n" + builder.toString());

        if (response.getStatusLine().getStatusCode() != 200) {
            Log.i("AudioRecorderTask", "Error uploading audio: " + audioPath);
            throw new HttpException();
        }
    } catch (Exception e) {
        Log.e("DataUploaderTask", "Error uploading audio: " + audioPath);
    }
}