//添加依赖的Agora SDK
dependencies {
implementation 'io.agora.rtc:full-sdk:3.5.0'
}
//创建Agora Engine实例
private lateinit var agoraEngine: RtcEngine
//初始化Agora Engine
private fun initAgoraEngine(context: Context, appId: String, callback: IRtcEngineEventHandler) {
try {
agoraEngine = RtcEngine.create(context, appId, callback)
} catch (e: Exception) {
Log.e(TAG, Log.getStackTraceString(e))
throw RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e))
}
}
// 设置必要的回调方法
private fun setChannelProfile() {
agoraEngine.setChannelProfile(Constants.CHANNEL_PROFILE_COMMUNICATION)
agoraEngine.enableVideo()
agoraEngine.setVideoEncoderConfiguration(VideoEncoderConfiguration(VideoEncoderConfiguration.VD_640x360,
VideoEncoderConfiguration.FRAME_RATE.FRAME_RATE_FPS_15,
VideoEncoderConfiguration.STANDARD_BITRATE,
VideoEncoderConfiguration.ORIENTATION_MODE.ORIENTATION_MODE_FIXED_PORTRAIT))
}
// 自动订阅远程视频流
private fun subscribeRemoteVideoStream(uid: Int, remoteVideo: SurfaceView) {
agoraEngine.subscribeVideo(uid, remoteVideo.renderer as SurfaceViewRenderer)
}
//通过SurfaceViewRenderer显示本地和远程视频
var localView: SurfaceView? = null
var remoteView
上一篇:Agora WebSDK - 播放直播时出现错误和无限状态变化循环
下一篇:Agora-Flutter:PlatformException(-17,requesttojoinchannelisrejected,null,null)错误。