A Simple Android Library to record and pick audio.
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.abdullahalshafi:BasicAudioPicker:1.0.0'
}
AudioUtilHelper.create(this, audioLauncher) {
recordAudio()
start()
}
AudioUtilHelper.create(this, audioLauncher) {
pickAudio()
start()
}
private val audioLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == Activity.RESULT_OK) {
val basicAudioData: BasicAudioData =
it.data!!.getSerializableExtra(BasicAudioData::class.java.simpleName) as BasicAudioData
//do stuffs with the image object
Log.d("AUDIO_DATA", "name: ${basicAudioData.name} path: ${basicAudioData.path}")
} else if (it.resultCode == Activity.RESULT_CANCELED) {
//handle your own situation
}
}