Example usage for android.media MediaRecorder stop

List of usage examples for android.media MediaRecorder stop

Introduction

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

Prototype

public native void stop() throws IllegalStateException;

Source Link

Document

Stops recording.

Usage

From source file:Main.java

/**
 * task: pause recording/*  ww w . ja v  a2s.  co m*/
 * @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 stopRecording(MediaRecorder mRecorder) {
    if (mRecorder != null) {
        mRecorder.stop();
        mRecorder.release();//w  w  w .  j a v a2s. co m
    }
}

From source file:Main.java

public static void stopRecordAction(MediaRecorder recorder) {
    if (recorder != null) {
        recorder.stop();
        recorder.release();//  w  w  w  .  java  2 s  .com
        recorder = null;
    }
}

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 ww .  j  a  v a2  s .  c  om*/
        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 {/* ww w.j  av a 2s .co  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);
    }
}