// Create TRTCCloud main instance (vocal instance)TRTCCloud mTRTCCloud = TRTCCloud.sharedInstance(getApplicationContext());// Create TRTCCloud sub-instance (accompaniment instance)TRTCCloud subCloud = mTRTCCloud.createSubCloud();
TRTCCloudDef.TRTCParams params = new TRTCCloudDef.TRTCParams();params.sdkAppId = sdkAppId;params.userId = mUserId;params.userSig = userSig;params.role = TRTCCloudDef.TRTCRoleAnchor;params.roomId = mRoomId;mTRTCCloud.enterRoom(params, TRTCCloudDef.TRTC_APP_SCENE_LIVE);// Turn on audio uplink and set audio qualitymTRTCCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_MUSIC);// Set media typemTRTCCloud.setSystemVolumeType(TRTCCloudDef.TRTCSystemVolumeTypeMedia);// Mute remote accompaniment musicmTRTCCloud.muteRemoteAudio(mUserId + "_bgm", true);
TRTCCloudDef.TRTCParams bgmParams = new TRTCCloudDef.TRTCParams();bgmParams.sdkAppId = sdkAppId;bgmParams.userId = mUserId + "_bgm";bgmParams.userSig = userSig;bgmParams.role = TRTCCloudDef.TRTCRoleAnchor;bgmParams.roomId = mRoomId;subCloud.enterRoom(bgmParams, TRTCCloudDef.TRTC_APP_SCENE_LIVE);// Set media typesubCloud.setSystemVolumeType(TRTCCloudDef.TRTCSystemVolumeTypeMedia);// Enable preloadingsubCloud.callExperimentalAPI("{\\"api\\":\\"preloadMusic\\",\\"params\\": {\\"musicId\\":musicId,\\"path\\":\\"path\\",\\"startTimeMS\\":startTimeMS}}");// Play accompaniment music and push the stream (play at the agreed time)TXAudioEffectManager.AudioMusicParam param = new TXAudioEffectManager.AudioMusicParam(musicID, musicPath);// Send accompaniment music to the remote endparam.publish = true;subCloud.getAudioEffectManager().startPlayMusic(param);
// Create a TRTCPublishTarget objectTRTCCloudDef.TRTCPublishTarget target = new TRTCCloudDef.TRTCPublishTarget();// Push back to the room after mixing, if publishing to CDN, fill in TRTC_PublishMixStream_ToCdntarget.mode = TRTCCloudDef.TRTC_PublishMixStream_ToRoom;target.mixStreamIdentity.intRoomId = Integer.parseInt(mRoomId);// The userid of the mixing robot, which cannot be duplicated with other users' userid in the roomtarget.mixStreamIdentity.userId = mUserId + "_mix";// Set the encoding parameters of the transcoded audio streamTRTCCloudDef.TRTCStreamEncoderParam trtcStreamEncoderParam = new TRTCCloudDef.TRTCStreamEncoderParam();trtcStreamEncoderParam.audioEncodedChannelNum = 2;trtcStreamEncoderParam.audioEncodedKbps = 64;trtcStreamEncoderParam.audioEncodedCodecType = 2;trtcStreamEncoderParam.audioEncodedSampleRate = 48000;// Set audio mixing parametersTRTCCloudDef.TRTCStreamMixingConfig trtcStreamMixingConfig = new TRTCCloudDef.TRTCStreamMixingConfig();// Support filling in empty values, which will automatically mix the audio of all hosts and outputtrtcStreamMixingConfig.audioMixUserList = null;// Initiate mixed stream transcoding and pushing requestmTRTCCloud.startPublishMediaStream(target, trtcStreamEncoderParam, trtcStreamMixingConfig);
Feedback