< ul>
[*]Ошибка источника из ExoPlayer
[*]java.io.IOException : Не удалось подготовиться.: status=0x1 из MediaPlayer
Как я записываю звук :
Код: Выделить всё
private fun startRecording() {
recorder = MediaRecorder().apply {
setAudioSource(MediaRecorder.AudioSource.MIC)
setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
setOutputFile(File(
cacheDir.absolutePath, "${System.currentTimeMillis()}.3gpp"
).absolutePath.also {
audioFilePath = it
})
try {
prepare()
} catch (e: IOException) {
toast(getString(R.string.error_loading_data))
binding.micLayout.clearFocus()
}
start()
}
}
Код: Выделить всё
private fun processRecording() {
val audioFile = File(audioFilePath!!)
Log.d("Path>>", audioFilePath!!)
if (audioFile.exists()) {
val audioBytes = audioFile.readBytes()
playRecording(Uri.fromFile(audioFile))
FireRef.storageRef.child("ChatAudios/").child(audioFile.name).putBytes(audioBytes)
.addOnSuccessListener {
val url = it.storage.downloadUrl
url.addOnCompleteListener { link ->
if (link.isSuccessful) {
Log.d("URL>", link.result.toString())
}
}
}
}
}
Код: Выделить всё
private fun playRecording(uri: Uri) {
MediaPlayer().apply {
setAudioAttributes(
AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setUsage(AudioAttributes.USAGE_MEDIA)
.build()
)
setDataSource(applicationContext, uri)
prepare()
start()
}
}
Код: Выделить всё
private fun playRecording(uri: Uri) {
val exoPlayer = ExoPlayer.Builder(applicationContext).build()
val mediaItem = MediaItem.fromUri(uri)
exoPlayer.apply {
setMediaItem(mediaItem)
prepare()
play()
addListener(object : Player.Listener {
override fun onPlaybackStateChanged(playbackState: Int) {
if (playbackState == Player.STATE_ENDED) {
exoPlayer.release()
}
}
})
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... exo-player