|
22 | 22 | import io.agora.api.example.annotation.Example; |
23 | 23 | import io.agora.api.example.common.BaseFragment; |
24 | 24 | import io.agora.api.example.common.model.StatisticsInfo; |
| 25 | +import io.agora.api.example.utils.TokenUtils; |
25 | 26 | import io.agora.rtc2.ClientRoleOptions; |
26 | 27 | import io.agora.rtc2.Constants; |
27 | 28 | import io.agora.rtc2.EchoTestConfiguration; |
@@ -160,52 +161,68 @@ public void onClick(View v) { |
160 | 161 | btn_lastmile.setEnabled(false); |
161 | 162 | btn_lastmile.setText("Testing ..."); |
162 | 163 | } else if (v.getId() == R.id.btn_echo) { |
163 | | - EchoTestConfiguration config = new EchoTestConfiguration(); |
164 | | - config.enableVideo = false; |
165 | | - config.enableAudio = true; |
166 | | - config.intervalInSeconds = MAX_COUNT_DOWN; |
167 | | - config.channelId = "AudioEchoTest" + (new Random().nextInt(1000) + 10000); |
168 | | - engine.startEchoTest(config); |
169 | | - btn_echo_audio.setEnabled(false); |
170 | | - btn_echo_audio.setText("Recording on Microphone ..."); |
171 | | - btn_echo_video.setEnabled(false); |
172 | | - btn_echo_audio.post(new Runnable() { |
173 | | - int countDownNum = 0; |
| 164 | + String channelId = "AudioEchoTest" + (new Random().nextInt(1000) + 10000); |
| 165 | + TokenUtils.gen(requireContext(), channelId, 0, ret -> { |
| 166 | + if (ret == null) { |
| 167 | + showAlert("Gen token error"); |
| 168 | + return; |
| 169 | + } |
| 170 | + EchoTestConfiguration config = new EchoTestConfiguration(); |
| 171 | + config.enableVideo = false; |
| 172 | + config.enableAudio = true; |
| 173 | + config.intervalInSeconds = MAX_COUNT_DOWN; |
| 174 | + config.channelId = channelId; |
| 175 | + config.token = ret; |
| 176 | + engine.startEchoTest(config); |
| 177 | + btn_echo_audio.setEnabled(false); |
| 178 | + btn_echo_audio.setText("Recording on Microphone ..."); |
| 179 | + btn_echo_video.setEnabled(false); |
| 180 | + btn_echo_audio.post(new Runnable() { |
| 181 | + int countDownNum = 0; |
174 | 182 |
|
175 | | - @Override |
176 | | - public void run() { |
177 | | - countDownNum++; |
178 | | - if (countDownNum >= MAX_COUNT_DOWN * 2) { |
179 | | - btn_echo_video.setEnabled(true); |
180 | | - btn_echo_audio.setEnabled(true); |
181 | | - btn_echo_audio.setText(R.string.start); |
182 | | - engine.stopEchoTest(); |
183 | | - } else if (countDownNum >= MAX_COUNT_DOWN) { |
184 | | - btn_echo_audio.setText("PLaying with " + (MAX_COUNT_DOWN * 2 - countDownNum) + "Seconds"); |
185 | | - btn_echo_audio.postDelayed(this, 1000); |
186 | | - } else { |
187 | | - btn_echo_audio.setText("Recording with " + (MAX_COUNT_DOWN - countDownNum) + "Seconds"); |
188 | | - btn_echo_audio.postDelayed(this, 1000); |
| 183 | + @Override |
| 184 | + public void run() { |
| 185 | + countDownNum++; |
| 186 | + if (countDownNum >= MAX_COUNT_DOWN * 2) { |
| 187 | + btn_echo_video.setEnabled(true); |
| 188 | + btn_echo_audio.setEnabled(true); |
| 189 | + btn_echo_audio.setText(R.string.start); |
| 190 | + engine.stopEchoTest(); |
| 191 | + } else if (countDownNum >= MAX_COUNT_DOWN) { |
| 192 | + btn_echo_audio.setText("PLaying with " + (MAX_COUNT_DOWN * 2 - countDownNum) + "Seconds"); |
| 193 | + btn_echo_audio.postDelayed(this, 1000); |
| 194 | + } else { |
| 195 | + btn_echo_audio.setText("Recording with " + (MAX_COUNT_DOWN - countDownNum) + "Seconds"); |
| 196 | + btn_echo_audio.postDelayed(this, 1000); |
| 197 | + } |
189 | 198 | } |
190 | | - } |
| 199 | + }); |
191 | 200 | }); |
192 | 201 | } else if (v.getId() == R.id.btn_echo_video) { |
193 | | - EchoTestConfiguration config = new EchoTestConfiguration(); |
194 | | - config.enableVideo = true; |
195 | | - config.view = requireView().findViewById(R.id.surfaceView); |
196 | | - config.enableAudio = false; |
197 | | - config.intervalInSeconds = MAX_COUNT_DOWN; |
198 | | - config.channelId = "VideoEchoTest" + (new Random().nextInt(1000) + 10000); |
199 | | - engine.startEchoTest(config); |
200 | | - btn_echo_audio.setEnabled(false); |
201 | | - btn_echo_video.setEnabled(false); |
202 | | - btn_echo_video.setText(R.string.stop); |
203 | | - btn_echo_video.postDelayed(() -> { |
204 | | - btn_echo_video.setEnabled(true); |
205 | | - btn_echo_audio.setEnabled(true); |
206 | | - btn_echo_video.setText(R.string.start); |
207 | | - engine.stopEchoTest(); |
208 | | - }, MAX_COUNT_DOWN * 2 * 1000); |
| 202 | + String channelId = "VideoEchoTest" + (new Random().nextInt(1000) + 10000); |
| 203 | + TokenUtils.gen(requireContext(), channelId, 0, ret -> { |
| 204 | + if (ret == null) { |
| 205 | + showAlert("Gen token error"); |
| 206 | + return; |
| 207 | + } |
| 208 | + EchoTestConfiguration config = new EchoTestConfiguration(); |
| 209 | + config.enableVideo = true; |
| 210 | + config.view = requireView().findViewById(R.id.surfaceView); |
| 211 | + config.enableAudio = false; |
| 212 | + config.intervalInSeconds = MAX_COUNT_DOWN; |
| 213 | + config.channelId = channelId; |
| 214 | + config.token = ret; |
| 215 | + engine.startEchoTest(config); |
| 216 | + btn_echo_audio.setEnabled(false); |
| 217 | + btn_echo_video.setEnabled(false); |
| 218 | + btn_echo_video.setText(R.string.stop); |
| 219 | + btn_echo_video.postDelayed(() -> { |
| 220 | + btn_echo_video.setEnabled(true); |
| 221 | + btn_echo_audio.setEnabled(true); |
| 222 | + btn_echo_video.setText(R.string.start); |
| 223 | + engine.stopEchoTest(); |
| 224 | + }, MAX_COUNT_DOWN * 2 * 1000); |
| 225 | + }); |
209 | 226 | } |
210 | 227 | } |
211 | 228 |
|
|
0 commit comments