Skip to content

Commit c0e0e56

Browse files
author
xia ning
authored
Merge pull request #235 from AgoraIO/staging
Staging
2 parents e1213bf + 6cabbaa commit c0e0e56

File tree

44 files changed

+396
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+396
-211
lines changed

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/PreCallTest.java

Lines changed: 106 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
import android.content.Context;
55
import android.os.Bundle;
66
import android.os.Handler;
7+
import android.os.Looper;
78
import android.os.Message;
89
import android.util.Log;
910
import android.view.LayoutInflater;
11+
import android.view.SurfaceView;
1012
import android.view.View;
1113
import android.view.ViewGroup;
1214
import android.widget.Button;
15+
import android.widget.FrameLayout;
1316
import android.widget.TextView;
1417
import android.widget.Toast;
1518

@@ -28,6 +31,7 @@
2831
import io.agora.rtc.IRtcEngineEventHandler;
2932
import io.agora.rtc.RtcEngine;
3033
import io.agora.rtc.internal.LastmileProbeConfig;
34+
import io.agora.rtc.models.EchoTestConfiguration;
3135

3236
import static io.agora.api.example.common.model.Examples.ADVANCED;
3337

@@ -43,18 +47,18 @@ public class PreCallTest extends BaseFragment implements View.OnClickListener {
4347

4448
private RtcEngine engine;
4549
private int myUid;
46-
private Button btn_lastmile, btn_echo;
50+
private Button btn_lastmile, btn_echo, btn_echoVideo;
51+
private FrameLayout preview;
4752
private StatisticsInfo statisticsInfo;
4853
private TextView lastmileQuality, lastmileResult;
4954
private static final Integer MAX_COUNT_DOWN = 8;
5055
private int num;
51-
private Timer timer;
52-
private TimerTask task;
56+
private boolean echoTesting = false;
57+
private Thread countDownThread;
5358

5459
@Override
5560
public void onCreate(@Nullable Bundle savedInstanceState) {
5661
super.onCreate(savedInstanceState);
57-
handler = new Handler();
5862
}
5963

6064
@Nullable
@@ -81,8 +85,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
8185
* The SDK uses this class to report to the app on SDK runtime events.*/
8286
String appId = getString(R.string.agora_app_id);
8387
engine = RtcEngine.create(getContext().getApplicationContext(), appId, iRtcEngineEventHandler);
84-
}
85-
catch (Exception e) {
88+
} catch (Exception e) {
8689
e.printStackTrace();
8790
getActivity().onBackPressed();
8891
}
@@ -94,40 +97,23 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9497
statisticsInfo = new StatisticsInfo();
9598
btn_echo = view.findViewById(R.id.btn_echo);
9699
btn_echo.setOnClickListener(this);
100+
btn_echoVideo = view.findViewById(R.id.btn_echoVideoTest);
101+
btn_echoVideo.setOnClickListener(this);
97102
btn_lastmile = view.findViewById(R.id.btn_lastmile);
98103
btn_lastmile.setOnClickListener(this);
99104
lastmileQuality = view.findViewById(R.id.lastmile_quality);
100105
lastmileResult = view.findViewById(R.id.lastmile_result);
101-
task = new TimerTask(){
102-
public void run() {
103-
num++;
104-
if(num >= MAX_COUNT_DOWN * 2){
105-
handler.post(() -> {
106-
btn_echo.setEnabled(true);
107-
btn_echo.setText("Start");
108-
});
109-
engine.stopEchoTest();
110-
timer.cancel();
111-
task.cancel();
112-
}
113-
else if(num >= MAX_COUNT_DOWN) {
114-
handler.post(() -> btn_echo.setText("PLaying with " + (MAX_COUNT_DOWN * 2 - num) + "Seconds"));
115-
}
116-
else{
117-
handler.post(() -> btn_echo.setText("Recording with " + (MAX_COUNT_DOWN - num) + "Seconds"));
118-
}
119-
}
120-
};
106+
preview = view.findViewById(R.id.echoTestView);
121107
}
122108

123109
@Override
124110
public void onClick(View v) {
125-
if (v.getId() == R.id.btn_lastmile)
126-
{
111+
if (v.getId() == R.id.btn_lastmile) {
127112
// Configure a LastmileProbeConfig instance.
128-
LastmileProbeConfig config = new LastmileProbeConfig(){};
113+
LastmileProbeConfig config = new LastmileProbeConfig() {
114+
};
129115
// Probe the uplink network quality.
130-
config.probeUplink = true;
116+
config.probeUplink = true;
131117
// Probe the downlink network quality.
132118
config.probeDownlink = true;
133119
// The expected uplink bitrate (bps). The value range is [100000, 5000000].
@@ -138,14 +124,34 @@ public void onClick(View v) {
138124
engine.startLastmileProbeTest(config);
139125
btn_lastmile.setEnabled(false);
140126
btn_lastmile.setText("Testing ...");
141-
}
142-
else if (v.getId() == R.id.btn_echo){
127+
} else if (v.getId() == R.id.btn_echo) {
143128
num = 0;
144129
engine.startEchoTest(MAX_COUNT_DOWN);
145130
btn_echo.setEnabled(false);
146-
btn_echo.setText("Recording on Microphone ...");
147-
timer = new Timer(true);
148-
timer.schedule(task, 1000, 1000);
131+
btn_echo.setText(R.string.recording_start);
132+
countDownThread = new Thread(new CountDownTask());
133+
countDownThread.start();
134+
} else if (v.getId() == R.id.btn_echoVideoTest) {
135+
if (!echoTesting) {
136+
SurfaceView surfaceView = RtcEngine.CreateRendererView(getContext());
137+
// Add to the local container
138+
preview.addView(surfaceView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
139+
EchoTestConfiguration config = new EchoTestConfiguration();
140+
config.enableAudio = true;
141+
config.enableVideo = true;
142+
config.channelId = "randomChannel";
143+
config.view = surfaceView;
144+
engine.startEchoTest(config);
145+
echoTesting = true;
146+
btn_echoVideo.setText(getText(R.string.stop_echo_video_audio_test));
147+
} else {
148+
engine.stopEchoTest();
149+
if (preview.getChildCount() > 0) {
150+
preview.removeAllViews();
151+
}
152+
echoTesting = false;
153+
btn_echoVideo.setText(getText(R.string.start_echo_video_audio_test));
154+
}
149155
}
150156
}
151157

@@ -263,7 +269,7 @@ public void onUserOffline(int uid, int reason) {
263269
* @param quality
264270
*/
265271
@Override
266-
public void onLastmileQuality(int quality){
272+
public void onLastmileQuality(int quality) {
267273
statisticsInfo.setLastMileQuality(quality);
268274
updateLastMileResult();
269275
}
@@ -281,20 +287,80 @@ public void onLastmileProbeResult(LastmileProbeResult lastmileProbeResult) {
281287
updateLastMileResult();
282288
handler.post(() -> {
283289
btn_lastmile.setEnabled(true);
284-
btn_lastmile.setText("Start");
290+
btn_lastmile.setText(getString(R.string.start));
285291
});
286292
}
287293
};
288294

289295
private void updateLastMileResult() {
290296
handler.post(() -> {
291-
if(statisticsInfo.getLastMileQuality() != null){
297+
if (statisticsInfo.getLastMileQuality() != null) {
292298
lastmileQuality.setText("Quality: " + statisticsInfo.getLastMileQuality());
293299
}
294-
if(statisticsInfo.getLastMileResult() != null){
300+
if (statisticsInfo.getLastMileResult() != null) {
295301
lastmileResult.setText(statisticsInfo.getLastMileResult());
296302
}
297303
});
298304
}
299305

300-
}
306+
307+
@Override
308+
public void onDestroy() {
309+
/**leaveChannel and Destroy the RtcEngine instance*/
310+
if (engine != null) {
311+
/**After joining a channel, the user must call the leaveChannel method to end the
312+
* call before joining another channel. This method returns 0 if the user leaves the
313+
* channel and releases all resources related to the call. This method call is
314+
* asynchronous, and the user has not exited the channel when the method call returns.
315+
* Once the user leaves the channel, the SDK triggers the onLeaveChannel callback.
316+
* A successful leaveChannel method call triggers the following callbacks:
317+
* 1:The local client: onLeaveChannel.
318+
* 2:The remote client: onUserOffline, if the user leaving the channel is in the
319+
* Communication channel, or is a BROADCASTER in the Live Broadcast profile.
320+
* @returns 0: Success.
321+
* < 0: Failure.
322+
* PS:
323+
* 1:If you call the destroy method immediately after calling the leaveChannel
324+
* method, the leaveChannel process interrupts, and the SDK does not trigger
325+
* the onLeaveChannel callback.
326+
* 2:If you call the leaveChannel method during CDN live streaming, the SDK
327+
* triggers the removeInjectStreamUrl method.*/
328+
engine.leaveChannel();
329+
}
330+
handler.post(RtcEngine::destroy);
331+
engine = null;
332+
super.onDestroy();
333+
}
334+
335+
class CountDownTask implements Runnable {
336+
337+
private void updateCountDown() {
338+
if (num > MAX_COUNT_DOWN * 2)
339+
return;
340+
try {
341+
Thread.sleep(1000);
342+
} catch (InterruptedException e) {
343+
e.printStackTrace();
344+
}
345+
if (num == MAX_COUNT_DOWN * 2) {
346+
handler.post(() -> {
347+
btn_echo.setText(getString(R.string.start_echo_audio_test));
348+
btn_echo.setEnabled(true);
349+
});
350+
engine.stopEchoTest();
351+
} else if (num >= MAX_COUNT_DOWN) {
352+
handler.post(() -> btn_echo.setText(getString(R.string.echo_playing_countdown) + " " + (MAX_COUNT_DOWN * 2 - num + 1)));
353+
} else {
354+
handler.post(() -> btn_echo.setText(getString(R.string.echo_record_countdown) + " " + (MAX_COUNT_DOWN - num + 1)));
355+
}
356+
num++;
357+
updateCountDown();
358+
}
359+
360+
@Override
361+
public void run() {
362+
updateCountDown();
363+
}
364+
}
365+
366+
}

Android/APIExample/app/src/main/java/io/agora/api/example/examples/advanced/customaudio/AudioRecordService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ public class AudioRecordService extends Service {
2727

2828
/**
2929
* Since v3.5.1
30-
* 根据实际需求,你可以将外部音频帧推送到音频采集后、编码前或本地播放前的位置。
31-
* 你可以多次调用该方法,将一个音频帧推送到多个位置或者将多个音频帧推送到不同位置。
32-
* 例如,在 KTV 场景中,你可以将歌声推送到音频采集后的位置,让歌声经过 SDK 音频模块的处理,
33-
* 从而获取优质的音频体验;将伴奏推送到音频编码前的位置,让伴奏不受 SDK 音频模块的影响。
30+
* https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/java/classio_1_1agora_1_1rtc_1_1_rtc_engine.html?platform=Android#acc77cfbe4ddfcf36d722a89af6729ce5
3431
*
3532
* {@link io.agora.rtc.Constants.AudioExternalSourcePos}
3633
* AUDIO_EXTERNAL_PLAYOUT_SOURCE(0)

Android/APIExample/app/src/main/res/layout/fragment_precall_test.xml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
android:layout_width="wrap_content"
2424
android:layout_height="wrap_content"
2525
android:layout_alignParentTop="true"
26-
android:text="Lastmile Network Pretest" />
26+
android:text="@string/lastmile_network_pretest" />
2727

2828
<androidx.appcompat.widget.AppCompatButton
2929
android:id="@+id/btn_lastmile"
3030
android:layout_width="wrap_content"
3131
android:layout_height="wrap_content"
3232
android:layout_below="@id/lb_lastmile"
3333
android:clickable="true"
34-
android:text="start" />
34+
android:text="@string/start" />
3535

3636
<TextView
3737
android:id="@+id/lastmile_quality"
@@ -61,15 +61,31 @@
6161
android:layout_width="wrap_content"
6262
android:layout_height="wrap_content"
6363
android:layout_alignParentTop="true"
64-
android:text="Echo Pretest" />
64+
android:text="@string/echo_pretest" />
6565

6666
<androidx.appcompat.widget.AppCompatButton
6767
android:id="@+id/btn_echo"
6868
android:layout_width="wrap_content"
6969
android:layout_height="wrap_content"
7070
android:layout_below="@id/lb_echo"
7171
android:clickable="true"
72-
android:text="start" />
72+
android:text="@string/start_echo_audio_test" />
73+
74+
<androidx.appcompat.widget.AppCompatButton
75+
android:id="@+id/btn_echoVideoTest"
76+
android:layout_width="wrap_content"
77+
android:layout_height="wrap_content"
78+
android:layout_below="@id/btn_echo"
79+
android:clickable="true"
80+
android:text="@string/start_echo_video_audio_test" />
81+
82+
<FrameLayout
83+
android:id="@+id/echoTestView"
84+
android:layout_width="120dp"
85+
android:layout_height="120dp"
86+
android:layout_marginTop="10dp"
87+
android:layout_below="@id/btn_echoVideoTest"
88+
/>
7389

7490
</RelativeLayout>
7591

Android/APIExample/app/src/main/res/values-zh/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,13 @@
154154
<string name="track_change">音轨切换(%d)</string>
155155
<string name="track_last">上一个</string>
156156
<string name="track_next">下一个</string>
157+
<string name="start_echo_video_audio_test">开始音视频测试</string>
158+
<string name="start_echo_audio_test">开始音频测试</string>
159+
<string name="stop_echo_video_audio_test">停止音视频测试</string>
160+
<string name="stop_echo_audio_test">停止音频测试</string>
161+
<string name="echo_pretest">网络回路测试</string>
162+
<string name="lastmile_network_pretest">网络延迟测试</string>
163+
<string name="echo_record_countdown">录制倒计时</string>
164+
<string name="echo_playing_countdown">播放倒计时</string>
165+
<string name="recording_start">开始麦克风录制</string>
157166
</resources>

Android/APIExample/app/src/main/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,13 @@
158158
<string name="track_change">change track(%d)</string>
159159
<string name="track_last">LAST</string>
160160
<string name="track_next">NEXT</string>
161+
<string name="start_echo_video_audio_test">Start Echo Video/Audio Test</string>
162+
<string name="start_echo_audio_test">Start Echo Audio Test</string>
163+
<string name="stop_echo_video_audio_test">Stop Echo Video/Audio Test</string>
164+
<string name="stop_echo_audio_test">Stop Echo Audio Test</string>
165+
<string name="echo_pretest">Echo Test</string>
166+
<string name="lastmile_network_pretest">Lastmile Network Pretest</string>
167+
<string name="echo_record_countdown">Recording Countdown</string>
168+
<string name="echo_playing_countdown">Playing Countdown</string>
169+
<string name="recording_start">Recording on Microphone</string>
161170
</resources>

Android/APIExample/lib-component/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies {
3030
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3131
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3232

33-
api 'io.agora.rtc:full-sdk:3.5.1'
33+
api 'io.agora.rtc:full-sdk:3.5.2'
3434
api 'io.agora:player:1.3.0'
3535

3636
}

0 commit comments

Comments
 (0)