- (void)onRecvCustomCmdMsgUserId:(NSString *)userId cmdID:(NSInteger)cmdId seq:(UInt32)seq message:(NSData *)message {
NSString *msg = [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:[msg dataUsingEncoding:NSUTF8StringEncoding]
options:NSJSONReadingMutableContainers
error:&error];
NSObject *cmdObj = [json objectForKey:@"cmd"];
NSInteger musicDuration = [[json objectForKey:@"musicDuration"] integerValue];
NSString *cmd = (NSString *)cmdObj;
if ([cmd isEqualToString:@"startChorus"]) {
NSObject *startPlayMusicTsObj = [json objectForKey:@"startPlayMusicTS"];
NSString *musicId = [json objectForKey:@"musicId"];
NSInteger startPlayMusicTs = ((NSNumber *)startPlayMusicTsObj).longLongValue;
NSInteger startDelayMS = labs(startPlayMusicTs - [TXLiveBase getNetworkTimestamp]);
NSDictionary *jsonDict = @{
@"api": @"preloadMusic",
@"params": @{
@"musicId": @(musicId),
@"path": path,
@"startTimeMS": @(startDelayMS),
}
};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:0 error:NULL];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
[subCloud callExperimentalAPI:jsonString];
TXAudioMusicParam *param = [[TXAudioMusicParam alloc] init];
param.ID = musicId;
param.path = url;
param.loopCount = 0;
param.publish = NO;
[[subCloud getAudioEffectManager] startPlayMusic:param onStart:^(NSInteger errCode) {
} onProgress:^(NSInteger progressMs, NSInteger durationMs) {
} onComplete:^(NSInteger errCode) {
}];
}
}
本页内容是否解决了您的问题?