主唱 | 合唱 | 观众 |
NTP 校时 开启补黑帧 发送 SEI 消息 本地歌词同步 更新歌词控件 | NTP 校时 本地歌词同步 更新歌词控件 | NTP 校时 接收 SEI 消息 更新歌词控件 |
// 纯音频模式下,主实例(人声实例)需要开启补黑帧以携带 SEI 消息NSDictionary *jsonDic = @{@"api": @"enableBlackStream",@"params":@{@"enable": @(1)}};NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDic options:NSJSONWritingPrettyPrinted error:nil];NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];[trtcCloud callExperimentalAPI:jsonString];
TXAudioMusicProgressBlock progressBlock = ^(NSInteger progressMs, NSInteger durationMs) {//当前 ntp 时间NSInteger ntpTime = [TXLiveBase getNetworkTimestamp];//通知歌曲进度,用户会在这里进行歌词的滚动NSDictionary *progressMsg = @{@"bgmProgressTime":@(progressMs),@"ntpTime":@(ntpTime),@"musicId": @(musicId),@"duration": @(durationMs),};NSData *jsonData = [NSJSONSerialization dataWithJSONObject:progressMsg options:NSJSONWritingPrettyPrinted error:nil];NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];[trtcCloud sendSEIMsg:[jsonString dataUsingEncoding:NSUTF8StringEncoding] repeatCount:1];};
// 本地歌词同步TXAudioMusicProgressBlock progressBlock = ^(NSInteger progressMs, NSInteger durationMs) {...// TODO 更新歌词控件逻辑:// 根据最新进度和本地歌词进度误差,判断是否需要 seek 歌词控件...};// 远端歌词同步- (void)onRecvSEIMsg:(NSString *)userId message:(NSData *)message {NSError *err = nil;NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:message options:NSJSONReadingMutableContainers error:&err];if (err || ![dic isKindOfClass:[NSDictionary class]]) {// 解析出错return;}NSInteger bgmProgressTime = [[dic objectForKey:@"bgmProgressTime"] integerValue];NSInteger ntpTime = [[dic objectForKey:@"ntpTime"] integerValue];int32_t musicId = [[dic objectForKey:@"musicId"] intValue];NSInteger duration = [[dic objectForKey:@"duration"] integerValue];...// TODO 更新歌词控件逻辑:// 根据接收到的最新进度和本地歌词进度误差,判断是否需要 seek 歌词控件...}
本页内容是否解决了您的问题?