Coder Social home page Coder Social logo

Audio recording issue about recordview HOT 4 CLOSED

3llomi avatar 3llomi commented on June 20, 2024
Audio recording issue

from recordview.

Comments (4)

3llomi avatar 3llomi commented on June 20, 2024

@rameshpaladugu can you post your full code? i think the problem is in you App Logic.

from recordview.

rameshpaladugu avatar rameshpaladugu commented on June 20, 2024
    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(CreateNewReminderActivity.this);
    LayoutInflater inflater = getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.pop_up_record_audio, null);

    builder.setView(dialogView);
    final android.support.v7.app.AlertDialog dialog = builder.create();
    ImageView cancel = (ImageView) dialogView.findViewById(R.id.declineButton);

    cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Dismiss the alert dialog
            dialog.cancel();
            // Set the main layout background color red

        }
    });

    RecordView recordView = (RecordView) dialogView.findViewById(R.id.record_view);
    final RecordButton recordButton = (RecordButton) dialogView.findViewById(R.id.record_button);
    Button btnChangeOnclick = (Button) dialogView.findViewById(R.id.btn_change_onclick);

    //IMPORTANT
    recordButton.setRecordView(recordView);

    // if you want to click the button (in case if you want to make the record button a Send Button for example..)
// recordButton.setListenForRecord(false);

    btnChangeOnclick.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (recordButton.isListenForRecord()) {
                recordButton.setListenForRecord(false);
// Toast.makeText(CreateNewReminderActivity.this, "onClickEnabled", Toast.LENGTH_SHORT).show();
} else {
recordButton.setListenForRecord(true);
// Toast.makeText(CreateNewReminderActivity.this, "onClickDisabled", Toast.LENGTH_SHORT).show();
}
}
});

    //ListenForRecord must be false ,otherwise onClick will not be called
    recordButton.setOnRecordClickListener(new OnRecordClickListener() {
        @Override
        public void onClick(View v) {
// Toast.makeText(CreateNewReminderActivity.this, "Hold on the mic to record audio", Toast.LENGTH_SHORT).show();
// dialog.dismiss();
Log.d("RecordButton" + " RECORD BUTTON CLICKED");
}
});

    //Cancel Bounds is when the Slide To Cancel text gets before the timer . default is 25
    recordView.setCancelBounds(30);


    recordView.setSmallMicColor(Color.parseColor("#c2185b"));

    //prevent recording under one Second
    recordView.setLessThanSecondAllowed(false);


    recordView.setSlideToCancelText("Slide To Cancel");


    recordView.setCustomSounds(R.raw.record_start, R.raw.record_finished, 0);

    recordView.setOnRecordListener(new OnRecordListener() {
        @Override
        public void onStart() {
            Log.d("RecordView" + "  onStart");
// Toast.makeText(CreateNewReminderActivity.this, "OnStartRecord", Toast.LENGTH_SHORT).show();

            recorder = new MediaRecorder();

            //Start Recording..
            try {
                start();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onCancel() {
// Toast.makeText(CreateNewReminderActivity.this, "onCancel", Toast.LENGTH_SHORT).show();

            Log.d("RecordView" + "   onCancel");

        }

        @Override
        public void onFinish(long recordTime) {

            String time = getHumanTimeText(recordTime);
// Toast.makeText(CreateNewReminderActivity.this, "onFinishRecord - Recorded Time is: " + time, Toast.LENGTH_SHORT).show();
Log.d("RecordView" + " onFinish");
Log.d("RecordTime "+ time);

            //Stop Recording..
            try {
                stop();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            }

            dialog.dismiss();
        }

        @Override
        public void onLessThanSecond() {
            Toast.makeText(CreateNewReminderActivity.this, "Press and hold to record", Toast.LENGTH_SHORT).show();
            Log.d("RecordView" + "   onLessThanSecond");
           

        }
    });


    recordView.setOnBasketAnimationEndListener(new OnBasketAnimationEnd() {
        @Override
        public void onAnimationEnd() {
            Log.d("RecordView" + "  Basket Animation Finished");
        }
    });

    dialog.show();
}

private String getHumanTimeText(long milliseconds) {
    return String.format("%02d:%02d",
            TimeUnit.MILLISECONDS.toMinutes(milliseconds),
            TimeUnit.MILLISECONDS.toSeconds(milliseconds) -
                    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(milliseconds)));
}

public void start() throws IOException, IllegalStateException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
    String currentDateandTime = sdf.format(new Date());
    audioFileName = "Audio"+ currentDateandTime +".3gpp";
    String path = Util.getSentDirectoryPath() + File.separator + audioFileName;

    fileTemp = new File(Util.getSentDirectoryPath()  + File.separator + audioFileName);

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(path);
    recorder.prepare();
    recorder.start();
}

public void stop() throws IOException, IllegalStateException {

    if (recorder != null) {
        recorder.stop();
        recorder.release();
    }

    attachment_audio_section.removeAllViews();
    audio_selected_section.setVisibility(View.VISIBLE);
    isAudioFileSelected = true;
    txt_audio_file_name.setText(audioFileName);

    audio_file_remove.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (mAudioWife != null) {
                // when done playing, release the resources
                mAudioWife.release();

                Log.d("@@@ AudioWife release player...");
            }

            File file = new File(Util.getSentDirectoryPath()  + File.separator + audioFileName);
            if (file.exists()) {
                file.delete();

                audioFileName = null;
                isAudioFileSelected = false;
                audio_selected_section.setVisibility(View.GONE);

                attachment_audio_section.removeAllViews();
            }

            return false;
        }
    });

    Uri mUri = Uri.fromFile(new File(Util.getSentDirectoryPath() + File.separator + audioFileName));

    mAudioWife = AudioWife.getInstance();
    mAudioWife.init(getApplicationContext(), mUri).useDefaultUi(attachment_audio_section, getLayoutInflater());


}

@Override
protected void onPause() {
    super.onPause();

    if (mAudioWife != null) {
        // when done playing, release the resources
        mAudioWife.release();

        Log.d("@@@ AudioWife release player...");
    }

}

from recordview.

rameshpaladugu avatar rameshpaladugu commented on June 20, 2024

Error : stop called in an invalid state: 0

from recordview.

3llomi avatar 3llomi commented on June 20, 2024

@rameshpaladugu i am sorry, but i think this error is from MediaRecorder or MediaPlayer not from RecordView.

from recordview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.