MegaphoneManager actually does not support upload the mp3 file.
You will need to convert the mp3 file to pcm audio data and encode the data by an OpusEncoder and then push opsu data to the megaphone.
If you want to learn how the OpusEncoder works, you can read the PSDK Speaker tutorial. The MSDK
Sample can be found here. An demo is listed below:
fun initRecorder() {
audioRecorderHandler = AudioRecordHandler.getInstance()
audioRecorderHandler?.init()
// Initialise an OpusEncoder.
opusEncoder = OpusEncoder()
// Set the default configuration of an OpusEncoder.
opusEncoder!!.config(audioRecorderHandler?.audioConfig)
// Get the opus data callback from the OpusEncoder.
opusEncoder!!.setEncodedDataCallback(object : EncodedDataCallback {
override fun onAudioEncodedCallback(
data: ByteArray?,
size: Int
) {
handler!!.post {
mAudioBos!!.write(data,0,size)
}
handler!!.post {
// Push the opus data to the megaphone.
MegaphoneManager.getInstance().sendRealTimeDataToMegaphone(
data,
size,
object : CommonCallbacks.CompletionCallback {
override fun onSuccess() {
LogUtils.i(
TAG,
"send real time data to megaphone success ${data?.size!!}"
)
}
override fun onFailure(error: IDJIError) {
LogUtils.i(TAG, "send real time data to megaphone failed")
}
})
}
}
})
audioRecorderHandler!!.setDataCallBack(object : SourceDataCallback {
override fun onAudioSourceDataCallback(data: ByteArray?, index: Int) {
handler!!.post {
mRawAudioBos!!.write(data)
}
// Push the PCM audio data to the OpusEncoder, the data length must be 1290.
opusEncoder!!.putData(data)
}
})
}
Comments
0 comments
Please sign in to leave a comment.