Skip to content

Commit 7cbb143

Browse files
committed
update ktvapi
1 parent 1991e57 commit 7cbb143

File tree

5 files changed

+51
-28
lines changed

5 files changed

+51
-28
lines changed

KTVAPI/iOS/Example/KTVApiDemo/KTVApiDemo.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
E3ED27292A826B0D0087B7AA /* KTVLyricView.swift */,
131131
E3ED272B2A8312120087B7AA /* FileDownloadCache */,
132132
E3ED27272A8243480087B7AA /* NetworkManager.swift */,
133+
E38BDE792B6F7ABD007A2834 /* ApiManager.swift */,
133134
E3ED271E2A822ED30087B7AA /* KTVAPI */,
134135
E3ED27102A822E9D0087B7AA /* Main.storyboard */,
135136
E3ED27132A822E9E0087B7AA /* Assets.xcassets */,
@@ -145,7 +146,6 @@
145146
E3ED271F2A822ED30087B7AA /* KTVApiImpl.swift */,
146147
E3ED27202A822ED30087B7AA /* KTVApi.swift */,
147148
E38BDE772B6F7A77007A2834 /* KTVGiantChorusApiImpl.swift */,
148-
E38BDE792B6F7ABD007A2834 /* ApiManager.swift */,
149149
E39BAF742B6CC695002C692F /* LrcTime.pb.swift */,
150150
E39BAF752B6CC695002C692F /* LrcTime.proto */,
151151
);
File renamed without changes.

KTVAPI/iOS/Example/KTVApiDemo/KTVApiDemo/KTVAPI/KTVApi.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,41 +156,41 @@ import AgoraRtcKit
156156
var chorusChannelToken: String
157157
var maxCacheSize: Int = 10
158158
var musicType: loadMusicType = .mcc
159-
var isDebugMode: Bool = false
160159
var audienceChannelToken: String = ""
161160
var musicStreamUid: Int = 0
162161
var musicChannelToken: String = ""
163162
var topN: Int = 0
163+
var isDebugMode: Bool = false
164164
@objc public
165165
init(appId: String,
166166
rtmToken: String,
167167
engine: AgoraRtcEngineKit,
168-
channelName: String,
169168
localUid: Int,
169+
audienceChannelName: String,
170+
audienceChannelToken: String,
170171
chorusChannelName: String,
171172
chorusChannelToken: String,
172-
maxCacheSize: Int,
173-
musicType: loadMusicType,
174-
isDebugMode: Bool,
175-
audienceChannelToken: String,
176173
musicStreamUid: Int,
177174
musicChannelToken: String,
178-
topN: Int
175+
maxCacheSize: Int,
176+
musicType: loadMusicType,
177+
topN: Int,
178+
isDebugMode: Bool
179179
) {
180180
self.appId = appId
181181
self.rtmToken = rtmToken
182182
self.engine = engine
183-
self.channelName = channelName
183+
self.channelName = audienceChannelName
184184
self.localUid = localUid
185185
self.chorusChannelName = chorusChannelName
186186
self.chorusChannelToken = chorusChannelToken
187187
self.maxCacheSize = maxCacheSize
188188
self.musicType = musicType
189-
self.isDebugMode = isDebugMode
190189
self.audienceChannelToken = audienceChannelToken
191190
self.musicStreamUid = musicStreamUid
192191
self.musicChannelToken = musicChannelToken
193192
self.topN = topN
193+
self.isDebugMode = isDebugMode
194194
}
195195
}
196196

@@ -215,8 +215,8 @@ import AgoraRtcKit
215215
chorusChannelName: String,
216216
chorusChannelToken: String,
217217
type: KTVType,
218-
maxCacheSize: Int,
219218
musicType: loadMusicType,
219+
maxCacheSize: Int,
220220
isDebugMode: Bool
221221
) {
222222
self.appId = appId

KTVAPI/iOS/Example/KTVApiDemo/KTVApiDemo/KTVAPI/KTVApiImpl.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ fileprivate enum KTVSongMode: Int {
154154
engine.setParameters("{\"che.audio.neteq.targetlevel_offset\": 20}")
155155
engine.setParameters("{\"che.audio.ans.noise_gate\": 20}")
156156
engine.setParameters("{\"rtc.use_audio4\": true}")
157-
engine.setParameters("{\"rtc.max_audio_metadata_length\": 200}")
158157
if apiConfig?.type == .singRelay {
159158
engine.setParameters("{\"che.audio.aiaec.working_mode\": 1}")
160159
}
@@ -173,7 +172,7 @@ fileprivate enum KTVSongMode: Int {
173172
dataStreamConfig.syncWithAudio = true
174173
self.apiConfig?.engine?.createDataStream(&dataStreamId, config: dataStreamConfig)
175174
sendCustomMessage(with: "renewInnerDataStreamId", label: "")
176-
agoraPrint("")
175+
agoraPrint("renewInnerDataStreamId")
177176
}
178177
}
179178

@@ -405,11 +404,19 @@ extension KTVApiImpl {
405404
}
406405

407406
private func agoraPrint(_ message: String) {
408-
apiConfig?.engine?.writeLog(.info, content: message)
407+
#if DEBUG
408+
print(message)
409+
#else
410+
apiConfig?.engine?.writeLog(.info, content: message)
411+
#endif
409412
}
410413

411414
private func agoraPrintError(_ message: String) {
412-
apiConfig?.engine?.writeLog(.error, content: message)
415+
#if DEBUG
416+
print(message)
417+
#else
418+
apiConfig?.engine?.writeLog(.error, content: message)
419+
#endif
413420
}
414421
}
415422

@@ -867,7 +874,7 @@ extension KTVApiImpl {
867874

868875
@objc func enableProfessionalStreamerMode(_ enable: Bool) {
869876
if self.isPublishAudio == false {return}
870-
agoraPrint("enableProfessionalStreamerMode")
877+
agoraPrint("enableProfessionalStreamerMode enable:\(enable)")
871878
self.enableProfessional = enable
872879
//专业非专业还需要根据是否佩戴耳机来判断是否开启3A
873880
apiConfig?.engine?.setAudioProfile(enable ? .musicHighQualityStereo : .musicStandardStereo)
@@ -886,6 +893,7 @@ extension KTVApiImpl {
886893

887894
}
888895
}
896+
889897
}
890898

891899
// rtc的子频道代理回调
@@ -1451,7 +1459,7 @@ extension Date {
14511459

14521460
extension KTVApiImpl: KTVApiRTCDelegate {
14531461
func didJoinChannel(channel: String, withUid uid: UInt, elapsed: Int) {
1454-
print("ktvapi加入主频道成功")
1462+
agoraPrint("ktvapi加入主频道成功")
14551463
}
14561464

14571465
func didJoinedOfUid(uid: UInt, elapsed: Int) {
@@ -1486,7 +1494,7 @@ extension KTVApiImpl: KTVApiRTCDelegate {
14861494
func didAudioPublishStateChange(channelId: String, oldState: AgoraStreamPublishState, newState: AgoraStreamPublishState, elapseSinceLastState: Int32) {
14871495
self.isPublishAudio = newState == .published
14881496
enableProfessionalStreamerMode(self.enableProfessional)
1489-
print("PublishStateChange:\(newState)")
1497+
agoraPrint("PublishStateChange:\(newState)")
14901498
}
14911499

14921500
func receiveStreamMessageFromUid(uid: UInt, streamId: Int, data: Data) {
@@ -1514,7 +1522,7 @@ extension KTVApiImpl: KTVApiRTCDelegate {
15141522
}
15151523

15161524
func didRTCAudioRouteChanged(routing: AgoraAudioOutputRouting) {
1517-
print("Route changed:\(routing)")
1525+
agoraPrint("Route changed:\(routing)")
15181526
let headPhones: [AgoraAudioOutputRouting] = [.headset, .headsetBluetooth, .headsetNoMic]
15191527
let wearHeadPhone: Bool = headPhones.contains(routing)
15201528
if wearHeadPhone == self.isWearingHeadPhones {

KTVAPI/iOS/Example/KTVApiDemo/KTVApiDemo/KTVAPI/KTVGiantChorusApiImpl.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ extension KTVGiantChorusApiImpl {
271271

272272
//主要针对本地歌曲播放的主唱伴奏切换的 MCC直接忽视这个方法
273273
func switchPlaySrc(url: String, syncPts: Bool) {
274-
agoraPrint("switchPlaySrc called: (url)")
274+
agoraPrint("switchPlaySrc called: \(url)")
275275

276276
if self.songUrl != url && self.songUrl2 != url {
277277
print("switchPlaySrc failed: canceled")
@@ -358,7 +358,7 @@ extension KTVGiantChorusApiImpl {
358358

359359
func renewToken(rtmToken: String, chorusChannelRtcToken: String) {
360360
sendCustomMessage(with: "renewToken", label: "rtmToken:\(rtmToken), chorusChannelRtcToken:\(chorusChannelRtcToken)")
361-
agoraPrint("renewToken")
361+
agoraPrint("renewToken rtmToken:\(rtmToken) chorusChannelRtcToken:\(chorusChannelRtcToken)")
362362
// 更新RtmToken
363363
mcc?.renewToken(rtmToken)
364364
// 更新合唱频道RtcToken
@@ -466,11 +466,19 @@ extension KTVGiantChorusApiImpl {
466466
}
467467

468468
private func agoraPrint(_ message: String) {
469-
apiConfig?.engine?.writeLog(.info, content: message)
469+
#if DEBUG
470+
print(message)
471+
#else
472+
apiConfig?.engine?.writeLog(.info, content: message)
473+
#endif
470474
}
471475

472476
private func agoraPrintError(_ message: String) {
473-
apiConfig?.engine?.writeLog(.error, content: message)
477+
#if DEBUG
478+
print(message)
479+
#else
480+
apiConfig?.engine?.writeLog(.error, content: message)
481+
#endif
474482
}
475483

476484
}
@@ -1188,7 +1196,9 @@ extension KTVGiantChorusApiImpl {
11881196
let ntpTime = dict["ntp"] as? Int,
11891197
let songId = dict["songIdentifier"] as? String
11901198
else { return }
1191-
print("realTime:\(realPosition) position:\(position) lastNtpTime:\(lastNtpTime) ntpTime:\(ntpTime) ntpGap:\(ntpTime - self.lastNtpTime) ")
1199+
#if DUBUG
1200+
print("realTime:\(realPosition) position:\(position) lastNtpTime:\(lastNtpTime) ntpTime:\(ntpTime) ntpGap:\(ntpTime - self.lastNtpTime) ")
1201+
#endif
11921202
//如果接收到的歌曲和自己本地的歌曲不一致就不更新进度
11931203
// guard songCode == self.songCode else {
11941204
// agoraPrint("local songCode[\(songCode)] is not equal to recv songCode[\(self.songCode)] role: \(singerRole.rawValue)")
@@ -1202,8 +1212,9 @@ extension KTVGiantChorusApiImpl {
12021212
// self.lastMainSingerUpdateTime = Date().milListamp
12031213
// self.remotePlayerPosition = TimeInterval(realPosition)
12041214
if self.playerState != state {
1205-
agoraPrint("[setLrcTime] recv state: \(self.playerState.rawValue)->\(state.rawValue) role: \(singerRole.rawValue) role: \(singerRole.rawValue)")
1206-
1215+
#if DUBUG
1216+
print("[setLrcTime] recv state: \(self.playerState.rawValue)->\(state.rawValue) role: \(singerRole.rawValue) role: \(singerRole.rawValue)")
1217+
#endif
12071218
if state == .playing, singerRole == .coSinger, playerState == .openCompleted {
12081219
//如果是伴唱等待主唱开始播放,seek 到指定位置开始播放保证歌词显示位置准确
12091220
self.localPlayerPosition = self.lastMainSingerUpdateTime - Double(position)
@@ -1267,7 +1278,9 @@ extension KTVGiantChorusApiImpl {
12671278
let threshold = expectPosition - Int(localPosition)
12681279
let ntpTime = dict["ntp"] as? Int ?? 0
12691280
let time = dict["time"] as? Int64 ?? 0
1270-
// agoraPrint("checkNtp, diff:\(threshold), localNtp:\(getNtpTimeInMs()), localPosition:\(localPosition), audioPlayoutDelay:\(audioPlayoutDelay), remoteDiff:\(String(describing: ntpTime - Int(time)))")
1281+
#if DUBUG
1282+
agoraPrint("checkNtp, diff:\(threshold), localNtp:\(getNtpTimeInMs()), localPosition:\(localPosition), audioPlayoutDelay:\(audioPlayoutDelay), remoteDiff:\(String(describing: ntpTime - Int(time)))")
1283+
#endif
12711284
if abs(threshold) > 50 {
12721285
agoraPrint("need seek, time:\(threshold)")
12731286
mediaPlayer?.seek(toPosition: expectPosition)
@@ -1556,7 +1569,9 @@ extension KTVGiantChorusApiImpl: AgoraRtcMediaPlayerDelegate {
15561569
"forward": true,
15571570
"ver":2,
15581571
]
1559-
// print("position_ms:\(position_ms), ntp:\(getNtpTimeInMs()), delta:\(self.getNtpTimeInMs() - position_ms), autoPlayoutDelay:\(self.audioPlayoutDelay), state:\(self.playerState.rawValue)")
1572+
#if DEBUG
1573+
print("position_ms:\(position_ms), ntp:\(getNtpTimeInMs()), delta:\(self.getNtpTimeInMs() - position_ms), autoPlayoutDelay:\(self.audioPlayoutDelay), state:\(self.playerState.rawValue)")
1574+
#endif
15601575
sendStreamMessageWithDict(dict, success: nil)
15611576
}
15621577
}

0 commit comments

Comments
 (0)