// 创建 TRTCCloud 主实例(人声实例)TRTCCloud *trtcCloud = [TRTCCloud sharedInstance];// 创建 TRTCCloud 子实例(伴奏实例)TRTCCloud *subCloud = [trtcCloud createSubCloud];
TRTCParams *params = [[TRTCParams alloc] init];params.sdkAppId = sdkAppId;params.userId = userId;params.userSig = userSign;params.role = TRTCRoleAnchor;params.roomId = roomIdIntValue;[trtcCloud enterRoom:params appScene:TRTCAppSceneLIVE];// 打开音频上行,设置音质[trtcCloud startLocalAudio:TRTCAudioQualityMusic];// 设置媒体类型[trtcCloud setSystemVolumeType:TRTCSystemVolumeTypeMedia];// 静音远端伴奏音乐[trtcCloud muteRemoteAudio:remoteAudioId mute:YES];
TRTCParams *bgmParams = [[TRTCParams alloc] init];bgmParams.sdkAppId = sdkAppId;bgmParams.userId = [NSString stringWithFormat:@"%@%@",userId,@"_bgm"];bgmParams.userSig = bgmUserSign;bgmParams.role = TRTCRoleAnchor;bgmParams.roomId = roomIdIntValue;[subCloud enterRoom:bgmParams appScene:TRTCAppSceneLIVE];//设置媒体类型[subCloud setSystemVolumeType:TRTCSystemVolumeTypeMedia];// 开启预加载NSDictionary *jsonDict = @{@"api": @"preloadMusic",@"params": @{@"musicId": @(self.currentPlayMusicID),@"path": path,@"startTimeMS": @(startMs),}};NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:NULL];NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];[subCloud callExperimentalAPI:jsonString];// 播放伴奏音乐并推流(在约定时间播放)TXAudioMusicParam *musicParam = [[TXAudioMusicParam alloc] init];musicParam.ID = musicID;musicParam.path = url;musicParam.loopCount = 0;musicParam.publish = YES;// 将伴奏音乐传到远端param.publish = YES;[[subCloud getAudioEffectManager] startPlayMusic:musicParam onStart:startBlock onProgress:progressBlock onComplete:completedBlock]
// 创建 TRTCPublishTarget 对象TRTCPublishTarget *publishTarget = [[TRTCPublishTarget alloc] init];// 混流后回推到房间,若发布到 CDN 应填 TRTCPublishMixStreamToCdnpublishTarget.mode = TRTCPublishMixStreamToRoom;// 混流机器人的 userid,不能和房间内其他用户的 userid 重复publishTarget.mixStreamIdentity = [NSString stringWithFormat:@"%@%@",userId,@"_mix"];// 设置转码后的音频流的编码参数TRTCStreamEncoderParam *streamEncoderParam = [[TRTCStreamEncoderParam alloc] init];streamEncoderParam.videoEncodedFPS = 15;streamEncoderParam.videoEncodedGOP = 3;streamEncoderParam.videoEncodedKbps = 30;streamEncoderParam.audioEncodedSampleRate = 48000;streamEncoderParam.audioEncodedChannelNum = 2;streamEncoderParam.audioEncodedKbps = 64;streamEncoderParam.audioEncodedCodecType = 2;// 设置音频混流参数TRTCStreamMixingConfig *streamMixingConfig = [[TRTCStreamMixingConfig alloc] init];// 支持填写空值,会自动将所有主播的音频混合输出streamMixingConfig.audioMixUserList = @[];// 发起混流转推请求[trtcCloud startPublishMediaStream:publishTarget encoderParam:streamEncoderParam mixingConfig:streamMixingConfig];
本页内容是否解决了您的问题?