Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MARK: Audio Recording
- private fun record() {
- recorder.setAudioSource(MediaRecorder.AudioSource.MIC)
- recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
- val path: File = filesDir
- try {
- tempFile = File.createTempFile("audioTemp", ".3gp", path)
- } catch (e: IOException) {
- Log.d("recording error", "recording error:", e)
- } catch (e: FileAlreadyExistsException) {
- Log.d("File already Exist", e.toString())
- }
- recorder.setOutputFile(tempFile?.absolutePath)
- try {
- recorder.prepare()
- } catch (e: IOException) {
- Log.d("recording error", "recording error:", e)
- }
- recorder.start()
- }
- private fun stopRecord() {
- recorder.stop()
- recorder.release()
- button_play_sample.isEnabled = true
- button_record.isEnabled = true
- player.setOnCompletionListener(this)
- try {
- player.setDataSource(tempFile?.absolutePath)
- } catch (e: IOException) {
- Log.d("stop recording error", "Stop Recording Error:", e)
- }
- try {
- player.prepare()
- } catch (e: IOException) {
- Log.d("recording error", "recording error:", e)
- }
- }
- private fun play() {
- player.start()
- button_record.isEnabled = false
- }
- override fun onCompletion(mp: MediaPlayer?) {
- handler = Handler()
- handler?.postDelayed({button_record.isEnabled = true}, 1000)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement