// 创建 TRTCCloud 主实例(人声实例)TRTCCloud mTRTCCloud = TRTCCloud.sharedInstance(getApplicationContext());// 创建 TRTCCloud 子实例(伴奏实例)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);// 打开音频上行,设置音质mTRTCCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_MUSIC);// 设置媒体类型mTRTCCloud.setSystemVolumeType(TRTCCloudDef.TRTCSystemVolumeTypeMedia);// 静音远端伴奏音乐mTRTCCloud.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);//设置媒体类型subCloud.setSystemVolumeType(TRTCCloudDef.TRTCSystemVolumeTypeMedia);// 开启预加载subCloud.callExperimentalAPI("{\\"api\\":\\"preloadMusic\\",\\"params\\": {\\"musicId\\":musicId,\\"path\\":\\"path\\",\\"startTimeMS\\":startTimeMS}}");// 播放伴奏音乐并推流(在约定时间播放)TXAudioEffectManager.AudioMusicParam param = new TXAudioEffectManager.AudioMusicParam(musicID, musicPath);// 将伴奏音乐传到远端param.publish = true;subCloud.getAudioEffectManager().startPlayMusic(param);
// 创建 TRTCPublishTarget 对象TRTCCloudDef.TRTCPublishTarget target = new TRTCCloudDef.TRTCPublishTarget();// 混流后回推到房间,若发布到 CDN 应填 TRTC_PublishMixStream_ToCdntarget.mode = TRTCCloudDef.TRTC_PublishMixStream_ToRoom;target.mixStreamIdentity.intRoomId = Integer.parseInt(mRoomId);// 混流机器人的 userid,不能和房间内其他用户的 userid 重复target.mixStreamIdentity.userId = mUserId + "_mix";// 设置转码后的音频流的编码参数TRTCCloudDef.TRTCStreamEncoderParam trtcStreamEncoderParam = new TRTCCloudDef.TRTCStreamEncoderParam();trtcStreamEncoderParam.audioEncodedChannelNum = 2;trtcStreamEncoderParam.audioEncodedKbps = 64;trtcStreamEncoderParam.audioEncodedCodecType = 2;trtcStreamEncoderParam.audioEncodedSampleRate = 48000;// 设置音频混流参数TRTCCloudDef.TRTCStreamMixingConfig trtcStreamMixingConfig = new TRTCCloudDef.TRTCStreamMixingConfig();// 支持填写空值,会自动将所有主播的音频混合输出trtcStreamMixingConfig.audioMixUserList = null;// 发起混流转推请求mTRTCCloud.startPublishMediaStream(target, trtcStreamEncoderParam, trtcStreamMixingConfig);
本页内容是否解决了您的问题?