@@ -101,23 +101,86 @@ class LivingFragment : BaseFragment<FragmentLivingBinding>() {
101
101
if (KeyCenter .role == KTVSingRole .LeadSinger ) {
102
102
toast(getString(R .string.app_no_premission))
103
103
} else {
104
- ktvApi.switchSingerRole(KTVSingRole .CoSinger , object : ISwitchRoleStateListener {
105
- override fun onSwitchRoleSuccess () {
106
- mainHandler.post {
107
- toast(" 加入合唱成功,自动开麦" )
108
- ktvApi.muteMic(false )
109
- btMicStatus.text = " 麦克风开"
110
- tvSinger.text = getString(R .string.app_co_singer)
111
- KeyCenter .role = KTVSingRole .CoSinger
104
+ if (KeyCenter .isMcc) {
105
+ // 使用声网版权中心歌单
106
+ val musicConfiguration = KTVLoadMusicConfiguration (
107
+ KeyCenter .songCode.toString(), // 需要传入唯一的歌曲id,demo 简化逻辑传了songCode
108
+ KeyCenter .LeadSingerUid ,
109
+ KTVLoadMusicMode .LOAD_MUSIC_ONLY
110
+ )
111
+ ktvApi.loadMusic(KeyCenter .songCode, musicConfiguration, object : IMusicLoadStateListener {
112
+ override fun onMusicLoadSuccess (songCode : Long , lyricUrl : String ) {
113
+ Log .d(" Music" , " onMusicLoadSuccess, songCode: $songCode , lyricUrl: $lyricUrl " )
114
+ // 切换身份为合唱者
115
+ ktvApi.switchSingerRole(KTVSingRole .CoSinger , object : ISwitchRoleStateListener {
116
+ override fun onSwitchRoleSuccess () {
117
+ mainHandler.post {
118
+ toast(" 加入合唱成功,自动开麦" )
119
+ ktvApi.muteMic(false )
120
+ btMicStatus.text = " 麦克风开"
121
+ tvSinger.text = getString(R .string.app_co_singer)
122
+ KeyCenter .role = KTVSingRole .CoSinger
123
+ }
124
+ }
125
+
126
+ override fun onSwitchRoleFail (reason : SwitchRoleFailReason ) {
127
+ mainHandler.post {
128
+ toast(" 加入合唱失败" )
129
+ }
130
+ }
131
+ })
112
132
}
113
- }
114
133
115
- override fun onSwitchRoleFail (reason : SwitchRoleFailReason ) {
116
- mainHandler.post {
117
- toast(" 加入合唱失败" )
134
+ override fun onMusicLoadFail (songCode : Long , reason : KTVLoadMusicFailReason ) {
135
+ Log .d(" Music" , " onMusicLoadFail, songCode: $songCode , reason: $reason " )
118
136
}
119
- }
120
- })
137
+
138
+ override fun onMusicLoadProgress (
139
+ songCode : Long ,
140
+ percent : Int ,
141
+ status : MusicLoadStatus ,
142
+ msg : String? ,
143
+ lyricUrl : String?
144
+ ) {
145
+ Log .d(" Music" , " onMusicLoadProgress, songCode: $songCode , percent: $percent " )
146
+ mainHandler.post {
147
+ binding?.btLoadProgress?.text = " 下载进度:$percent %"
148
+ }
149
+ }
150
+ })
151
+ } else {
152
+ // 使用本地音乐文件
153
+ val musicConfiguration = KTVLoadMusicConfiguration (
154
+ KeyCenter .songCode.toString(), // 需要传入唯一的歌曲id,demo 简化逻辑传了songCode
155
+ KeyCenter .LeadSingerUid ,
156
+ KTVLoadMusicMode .LOAD_NONE
157
+ )
158
+ val songPath = requireActivity().filesDir.absolutePath + File .separator
159
+ val songName = " 不如跳舞"
160
+ ktvApi.loadMusic(" $songPath$songName .mp4" , musicConfiguration)
161
+ val fileLrc = File (" $songPath$songName .xml" )
162
+ val lyricsModel = KaraokeView .parseLyricsData(fileLrc)
163
+ karaokeView?.lyricsData = lyricsModel
164
+
165
+ // 切换身份为合唱者
166
+ ktvApi.switchSingerRole(KTVSingRole .CoSinger , object : ISwitchRoleStateListener {
167
+ override fun onSwitchRoleSuccess () {
168
+ mainHandler.post {
169
+ toast(" 加入合唱成功,自动开麦" )
170
+ ktvApi.muteMic(false )
171
+ btMicStatus.text = " 麦克风开"
172
+ tvSinger.text = getString(R .string.app_co_singer)
173
+ KeyCenter .role = KTVSingRole .CoSinger
174
+ }
175
+ }
176
+
177
+ override fun onSwitchRoleFail (reason : SwitchRoleFailReason ) {
178
+ mainHandler.post {
179
+ toast(" 加入合唱失败" )
180
+ }
181
+ }
182
+ })
183
+ }
121
184
}
122
185
}
123
186
@@ -153,7 +216,8 @@ class LivingFragment : BaseFragment<FragmentLivingBinding>() {
153
216
if (KeyCenter .isMcc) {
154
217
// 使用声网版权中心歌单
155
218
val musicConfiguration = KTVLoadMusicConfiguration (
156
- KeyCenter .songCode.toString(), KeyCenter .LeadSingerUid ,
219
+ KeyCenter .songCode.toString(), // 需要传入唯一的歌曲id,demo 简化逻辑传了songCode
220
+ KeyCenter .LeadSingerUid ,
157
221
if (KeyCenter .role == KTVSingRole .Audience ) KTVLoadMusicMode .LOAD_LRC_ONLY else KTVLoadMusicMode .LOAD_MUSIC_AND_LRC
158
222
)
159
223
ktvApi.loadMusic(KeyCenter .songCode, musicConfiguration, object : IMusicLoadStateListener {
@@ -204,7 +268,9 @@ class LivingFragment : BaseFragment<FragmentLivingBinding>() {
204
268
} else {
205
269
// 使用本地音乐文件
206
270
val musicConfiguration = KTVLoadMusicConfiguration (
207
- KeyCenter .songCode.toString(), KeyCenter .LeadSingerUid , KTVLoadMusicMode .LOAD_NONE
271
+ KeyCenter .songCode.toString(), // 需要传入唯一的歌曲id,demo 简化逻辑传了songCode
272
+ KeyCenter .LeadSingerUid ,
273
+ KTVLoadMusicMode .LOAD_NONE
208
274
)
209
275
val songPath = requireActivity().filesDir.absolutePath + File .separator
210
276
val songName = " 不如跳舞"
@@ -381,7 +447,8 @@ class LivingFragment : BaseFragment<FragmentLivingBinding>() {
381
447
if (KeyCenter .isMcc) {
382
448
// 使用声网版权中心歌单
383
449
val musicConfiguration = KTVLoadMusicConfiguration (
384
- KeyCenter .songCode.toString(), KeyCenter .LeadSingerUid ,
450
+ KeyCenter .songCode.toString(), // 需要传入唯一的歌曲id,demo 简化逻辑传了songCode
451
+ KeyCenter .LeadSingerUid ,
385
452
if (KeyCenter .role == KTVSingRole .Audience ) KTVLoadMusicMode .LOAD_LRC_ONLY else KTVLoadMusicMode .LOAD_MUSIC_AND_LRC
386
453
)
387
454
ktvApi.loadMusic(KeyCenter .songCode, musicConfiguration, object : IMusicLoadStateListener {
@@ -422,7 +489,9 @@ class LivingFragment : BaseFragment<FragmentLivingBinding>() {
422
489
} else {
423
490
// 使用本地音乐文件
424
491
val musicConfiguration = KTVLoadMusicConfiguration (
425
- KeyCenter .songCode.toString(), KeyCenter .LeadSingerUid , KTVLoadMusicMode .LOAD_NONE
492
+ KeyCenter .songCode.toString(), // 需要传入唯一的歌曲id,demo 简化逻辑传了songCode
493
+ KeyCenter .LeadSingerUid ,
494
+ KTVLoadMusicMode .LOAD_NONE
426
495
)
427
496
val songPath = requireActivity().filesDir.absolutePath + File .separator
428
497
val songName = " 不如跳舞"
0 commit comments