I am only able to broadcast audio alone using mic and speaker, and if I use setExternalAudioSource method, then the broadcast encounter with some heavy unwanted noise. I just want to broadcast the raw audio data alone without using mic, speaker and unwanted noise.
private val PERMISSION_REQ_ID_RECORD_AUDIO = 22
private var mRtcEngine: RtcEngine? = null// Tutorial Step 1
private val mRtcEventHandler = object : IRtcEngineEventHandler() { // Tutorial Step 1
override fun onUserOffline(uid: Int, reason: Int) { // Tutorial Step 4
//runOnUiThread { onRemoteUserLeft(uid, reason) }
}
override fun onUserMuteAudio(uid: Int, muted: Boolean) { // Tutorial Step 6
// runOnUiThread { onRemoteUserVoiceMuted(uid, muted) }
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
createRtcChannel()
}
}
fun checkSelfPermission(permission: String, requestCode: Int): Boolean {
if (ContextCompat.checkSelfPermission(this,
permission) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
arrayOf(permission),
requestCode)
return false
}
return true
}
private fun createRtcChannel() {
initializeAgoraEngine() // Tutorial Step 1
joinChannel()
}
private fun initializeAgoraEngine() {
try {
mRtcEngine = RtcEngine.create(this, getString(R.string.agora_app_id), mRtcEventHandler)
//set the channel as live broadcast mode
mRtcEngine?.setChannelProfile(Constants.CHANNEL_PROFILE_LIVE_BROADCASTING)
mRtcEngine?.setClientRole(Constants.CLIENT_ROLE_BROADCASTER)
} catch (e: Exception) {
}
}
private fun joinChannel() {
mRtcEngine?.joinChannel(null, "voiceDemoChannel1", "Extra Optional Data", 0) // if you do not specify the uid, we will generate the uid for you
val payload = IOUtils.toByteArray(assets.openFd("ringtone.mp3").createInputStream())
mRtcEngine?.setExternalAudioSource(
true,
8000,
1 );
mRtcEngine?.pushExternalAudioFrame(
payload,
1000
)
}
Is this possible using agora or is there any alternative to it?