

TXLiveBase.setListener(new TXLiveBaseListener() {@Overridepublic void onUpdateNetworkTime(int errCode, String errMsg) {super.onUpdateNetworkTime(errCode, errMsg);// errCode 0: Calibration is successful and the deviation is within 30ms;// 1: Calibration is successful, but the deviation may be more than 30ms;// -1: Calibration failed.if (errCode == 0) {// Call getNetworkTimestamp of TXLivebase to get the NTP timestamp.long ntpTime = TXLiveBase.getNetworkTimestamp();} else {// Call updateNetworkTime again to start a calibration.TXLiveBase.updateNetworkTime();}}});TXLiveBase.updateNetworkTime();
JSONObject jsonObject = new JSONObject();jsonObject.put("cmd", "startChorus");// Agree on a time for the chorus.jsonObject.put("startPlayMusicTS", startTs);jsonObject.put("musicId", "musicId");String body = jsonObject.toString();mTRTCCloud.sendCustomCmdMsg(0, body.getBytes(), false, false);
public void onRecvCustomCmdMsg(String userId, int cmdID, int seq, byte[] message) {JSONObject json = new JSONObject(new String(message, "UTF-8"));String cmd = json.getString("cmd");// Chorus commandif (cmd.equals("startChorus")) {// Chorus start timelong startPlayMusicTs = json.getLong("startPlayMusicTS");int musicId = json.getInt("musicId");// The difference between the agreed chorus time and the current timelong delayMs = Math.abs(startPlayMusicTs - getNtpTime());// Start preloading, and jump the song progress according to the agreed chorus time and the current NTP difference.mTRTCCloud.callExperimentalAPI("{\\"api\\":\\"preloadMusic\\",\\"params\\": {\\"musicId\\":musicId,\\"path\\":\\"path\\",\\"startTimeMS\\":delayMs}}");// Play the songTXAudioEffectManager.AudioMusicParam param = new TXAudioEffectManager.AudioMusicParam(musicId, musicPath);param.publish = false;mTRTCCloud.getAudioEffectManager().startPlayMusic(param);}
long mStartPlayMusicTs = "The initially agreed chorus time";long currentProgress = subCloud.getAudioEffectManager().getMusicCurrentPosInMS(musicID);// The ideal playback progress of the current songlong estimatedProgress = getNtpTime() - mStartPlayMusicTs;// When the playback progress exceeds 50ms, make correctionsif (estimatedProgress >= 0 &&; Math.abs(currentProgress - estimatedProgress) > 50) {subCloud.getAudioEffectManager().seekMusicToPosInMS(mMusicID, (int) estimatedProgress);}
Feedback