-2

I'm a new android developer.

I want to record a sound via press and hold of a button, and on release of the button, audio should be saved in external storage.

I know how to record an audio file.

please help me.

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78
Emadi_mehrdad
  • 146
  • 1
  • 2
  • 16
  • 2
    Well, what have you tried so far? This is a pretty broad question, in its current state you aren't likely to get much help. Please read this: http://stackoverflow.com/help/mcve – Andrew Brooke Oct 05 '15 at 14:10
  • @AndrewBrooke i write a code that record a sound by press "Record" and when press "stop" recording is stopped and save in SDcard i want to record by a button,when hold "record" its start to recording and when drop(unhold?) button recordig finish and save in sdcard – Emadi_mehrdad Oct 05 '15 at 14:15
  • Ah, if that code works for you, look at @Rahul Tiwari's answer – Andrew Brooke Oct 05 '15 at 14:16
  • Possible duplicate of [Separate Back Stack for each tab in Android using Fragments](https://stackoverflow.com/questions/6987334/separate-back-stack-for-each-tab-in-android-using-fragments) – Emadi_mehrdad Jul 05 '19 at 14:47

1 Answers1

3

You need to:

  1. implement onTouchListener for your button
  2. start recording at on action down event
  3. stop recording and save to file on action up event.

example:

button.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
       if(event.getAction() == MotionEvent.ACTION_DOWN){
            // start recording.
            return true;
        }
        if(event.getAction() == MotionEvent.ACTION_UP){
            // Stop recording and save file
            return true;
        }
        return false;
    }
});

also refer this answer for a similar behaviour.

Community
  • 1
  • 1
Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78