I started to make a trial app to do audio recording in Android (with kotlin).
I just followed some tutorial and documentation I found to get started. But I hit one problem on the way.
Android Studio seems to show some problem by drawing an horizontal line on the word MediaRecorder, as shown in this image, but I do not see any error or other kind of information.
So my question is: What am I supposed to do?
For reference here is most of the code of the app.
package me.soft.myapp
import android.Manifest
import android.content.pm.PackageManager
import android.media.MediaRecorder
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import androidx.core.app.ActivityCompat
class MainActivity : AppCompatActivity() {
lateinit private var recordBtn:Button
lateinit private var stopBtn:Button
lateinit private var playBtn:Button
private var mediaRecorder: MediaRecorder? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
......
recordBtn.setOnClickListener {
println("recordBtn.setOnClickListener")
if (applicationContext.checkSelfPermission(
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
val permissions = arrayOf(android.Manifest.permission.RECORD_AUDIO)
ActivityCompat.requestPermissions(this, permissions,0)
} else {
startRecording()
}
}
......
}
private fun startRecording() {
......
stopBtn.isEnabled = true
playBtn.isEnabled = false
recordBtn.isEnabled = false
mediaRecorder = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
......
try {
prepare()
} catch (e: IOException) {
Log.e(LOG_TAG, "prepare() failed")
}
start()
}
}
