Skip to content

Commit 140d4b8

Browse files
committed
[Android]1.perfect livestreaming;2.add first frame optimization case;3.adjust default resolution
1 parent 70c0902 commit 140d4b8

9 files changed

Lines changed: 557 additions & 237 deletions

File tree

Android/APIExample/app/src/main/java/io/agora/api/example/common/model/GlobalSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class GlobalSettings {
3737

3838
public String getVideoEncodingDimension() {
3939
if (videoEncodingDimension == null)
40-
return "VD_640x360";
40+
return "VD_960x540";
4141
else
4242
return videoEncodingDimension;
4343
}

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

Lines changed: 188 additions & 137 deletions
Large diffs are not rendered by default.
Lines changed: 42 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
34
xmlns:tools="http://schemas.android.com/tools"
45
android:layout_width="match_parent"
56
android:layout_height="match_parent"
@@ -9,123 +10,57 @@
910
<io.agora.api.example.common.widget.VideoReportLayout
1011
android:id="@+id/background_video"
1112
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
13-
android:layout_above="@+id/ll_join"></io.agora.api.example.common.widget.VideoReportLayout>
14-
15-
<io.agora.api.example.common.widget.VideoReportLayout
16-
android:id="@+id/foreground_video"
17-
android:layout_width="150dp"
18-
android:layout_height="200dp"
19-
android:layout_alignParentTop="true"
20-
android:layout_alignParentEnd="true" />
21-
22-
<LinearLayout
23-
android:id="@+id/fl_encoder_type"
24-
android:layout_width="wrap_content"
25-
android:layout_height="35dp"
26-
android:layout_above="@id/switch_b_frame"
27-
android:layout_alignParentEnd="true"
28-
android:layout_marginEnd="16dp"
29-
android:layout_marginBottom="16dp"
30-
android:orientation="horizontal"
31-
android:gravity="center_vertical"
32-
android:background="#dddddd">
33-
34-
<TextView
35-
android:layout_width="wrap_content"
36-
android:layout_height="wrap_content"
37-
android:paddingHorizontal="6dp"
38-
android:textColor="@android:color/black"
39-
android:text="@string/encode_type"/>
40-
41-
42-
<Spinner
43-
android:id="@+id/sp_encoder_type"
44-
android:layout_width="wrap_content"
45-
android:layout_height="match_parent"
46-
android:entries="@array/encoder_type" />
47-
48-
</LinearLayout>
49-
50-
<androidx.appcompat.widget.SwitchCompat
51-
android:id="@+id/switch_b_frame"
52-
android:layout_width="wrap_content"
13+
android:layout_height="0dp"
14+
app:layout_constraintBottom_toTopOf="@id/ll_join"
15+
app:layout_constraintTop_toTopOf="parent" />
16+
17+
<include
18+
android:id="@+id/foreground_layout"
19+
layout="@layout/fragment_live_streaming_video_item"
20+
android:layout_width="180dp"
5321
android:layout_height="wrap_content"
54-
android:layout_above="@+id/switch_low_stream"
55-
android:layout_alignParentEnd="true"
56-
android:layout_marginEnd="16dp"
57-
android:layout_marginBottom="16dp"
58-
android:background="#dddddd"
59-
android:paddingHorizontal="16dp"
60-
android:paddingVertical="8dp"
61-
android:text="@string/b_frame" />
62-
63-
<androidx.appcompat.widget.SwitchCompat
64-
android:id="@+id/switch_low_stream"
22+
android:layout_margin="8dp"
23+
app:layout_constraintEnd_toEndOf="parent"
24+
app:layout_constraintTop_toTopOf="parent" />
25+
26+
<include
27+
android:id="@+id/video_tracking_layout"
28+
layout="@layout/fragment_live_streaming_video_tracking"
29+
android:visibility="gone"
30+
tools:visibility="visible"
6531
android:layout_width="wrap_content"
6632
android:layout_height="wrap_content"
67-
android:layout_above="@+id/switch_watermark"
68-
android:layout_alignParentEnd="true"
69-
android:layout_marginEnd="16dp"
70-
android:layout_marginBottom="16dp"
71-
android:background="#dddddd"
72-
android:paddingHorizontal="16dp"
73-
android:paddingVertical="8dp"
74-
android:text="@string/low_stream" />
75-
76-
<androidx.appcompat.widget.SwitchCompat
77-
android:id="@+id/switch_watermark"
78-
android:layout_width="wrap_content"
79-
android:layout_height="wrap_content"
80-
android:layout_above="@+id/btn_take_shot"
81-
android:layout_alignParentEnd="true"
82-
android:layout_marginEnd="16dp"
83-
android:layout_marginBottom="16dp"
84-
android:background="#dddddd"
85-
android:enabled="false"
86-
android:paddingHorizontal="16dp"
87-
android:paddingVertical="8dp"
88-
android:text="@string/watermark" />
33+
app:layout_constraintBottom_toTopOf="@id/btn_remote_screenshot"
34+
app:layout_constraintStart_toStartOf="@id/btn_publish"/>
8935

9036
<androidx.appcompat.widget.AppCompatButton
91-
android:id="@+id/btn_take_shot"
37+
android:id="@+id/btn_remote_screenshot"
9238
android:layout_width="wrap_content"
9339
android:layout_height="wrap_content"
94-
android:layout_above="@+id/btn_latency"
95-
android:layout_alignParentEnd="true"
96-
android:layout_marginEnd="16dp"
97-
android:layout_marginBottom="16dp"
98-
android:text="@string/remote_screenshot" />
40+
android:layout_marginBottom="4dp"
9941

100-
<androidx.appcompat.widget.AppCompatButton
101-
android:id="@+id/btn_latency"
102-
android:layout_width="wrap_content"
103-
android:layout_height="wrap_content"
104-
android:layout_above="@id/btn_publish"
105-
android:layout_alignParentEnd="true"
106-
android:layout_marginEnd="16dp"
107-
android:layout_marginBottom="16dp"
108-
android:enabled="false"
109-
android:text="@string/enable_low_latency" />
42+
android:text="@string/remote_screenshot"
43+
app:layout_constraintBottom_toTopOf="@id/btn_publish"
44+
app:layout_constraintStart_toStartOf="@id/btn_publish" />
11045

11146
<androidx.appcompat.widget.AppCompatButton
11247
android:id="@+id/btn_publish"
11348
android:layout_width="wrap_content"
11449
android:layout_height="wrap_content"
115-
android:layout_above="@id/ll_join"
116-
android:layout_alignParentEnd="true"
117-
android:layout_marginEnd="16dp"
118-
android:layout_marginBottom="16dp"
50+
android:layout_marginStart="4dp"
11951
android:enabled="false"
120-
android:text="@string/enable_publish" />
52+
android:text="@string/enable_publish"
53+
app:layout_constraintBottom_toTopOf="@id/ll_join"
54+
app:layout_constraintStart_toStartOf="parent" />
55+
12156

12257
<LinearLayout
12358
android:id="@+id/ll_join"
12459
android:layout_width="match_parent"
12560
android:layout_height="wrap_content"
126-
android:layout_alignParentBottom="true"
12761
android:gravity="center_vertical"
128-
android:orientation="horizontal">
62+
android:orientation="horizontal"
63+
app:layout_constraintBottom_toBottomOf="parent">
12964

13065
<androidx.appcompat.widget.AppCompatEditText
13166
android:id="@+id/et_channel"
@@ -141,6 +76,14 @@
14176
android:layout_height="wrap_content"
14277
android:text="@string/join" />
14378

79+
80+
<androidx.appcompat.widget.AppCompatButton
81+
android:id="@+id/btn_setting"
82+
android:layout_width="wrap_content"
83+
android:layout_height="wrap_content"
84+
android:text="@string/setting" />
85+
14486
</LinearLayout>
14587

146-
</RelativeLayout>
88+
89+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:fitsSystemWindows="true"
7+
android:orientation="vertical"
8+
android:paddingBottom="16dp"
9+
android:layout_gravity="bottom"
10+
tools:context=".examples.advanced.LiveStreaming">
11+
12+
13+
<TextView
14+
android:layout_width="wrap_content"
15+
android:layout_height="wrap_content"
16+
android:text="@string/setting"
17+
android:textSize="20sp"
18+
android:textColor="@android:color/black"
19+
android:padding="12dp"
20+
android:layout_gravity="center_horizontal"/>
21+
22+
<View
23+
android:layout_width="match_parent"
24+
android:layout_height="1dp"
25+
android:background="#eeeeee"/>
26+
27+
<androidx.appcompat.widget.SwitchCompat
28+
android:id="@+id/switch_low_latency"
29+
android:layout_width="match_parent"
30+
android:layout_height="50dp"
31+
android:paddingHorizontal="16dp"
32+
android:text="@string/enable_low_latency" />
33+
34+
<View
35+
android:layout_width="match_parent"
36+
android:layout_height="1dp"
37+
android:layout_marginHorizontal="8dp"
38+
android:background="#eeeeee"/>
39+
40+
<androidx.appcompat.widget.SwitchCompat
41+
android:id="@+id/switch_watermark"
42+
android:layout_width="match_parent"
43+
android:layout_height="50dp"
44+
android:paddingHorizontal="16dp"
45+
android:text="@string/watermark" />
46+
47+
<View
48+
android:layout_width="match_parent"
49+
android:layout_height="1dp"
50+
android:layout_marginHorizontal="8dp"
51+
android:background="#eeeeee"/>
52+
53+
<androidx.appcompat.widget.SwitchCompat
54+
android:id="@+id/switch_low_stream"
55+
android:layout_width="match_parent"
56+
android:layout_height="50dp"
57+
android:paddingHorizontal="16dp"
58+
android:text="@string/low_stream" />
59+
<View
60+
android:layout_width="match_parent"
61+
android:layout_height="1dp"
62+
android:layout_marginHorizontal="8dp"
63+
android:background="#eeeeee"/>
64+
65+
<LinearLayout
66+
android:id="@+id/fl_encoder_type"
67+
android:layout_width="match_parent"
68+
android:layout_height="50dp"
69+
android:paddingHorizontal="16dp"
70+
android:orientation="horizontal"
71+
android:gravity="center_vertical">
72+
73+
<TextView
74+
android:layout_width="0dp"
75+
android:layout_weight="1"
76+
android:layout_height="wrap_content"
77+
android:textColor="@android:color/black"
78+
android:text="@string/encode_type"/>
79+
80+
<Spinner
81+
android:id="@+id/sp_encoder_type"
82+
android:layout_width="wrap_content"
83+
android:layout_height="match_parent"
84+
android:entries="@array/encoder_type" />
85+
86+
</LinearLayout>
87+
88+
<View
89+
android:layout_width="match_parent"
90+
android:layout_height="1dp"
91+
android:layout_marginHorizontal="8dp"
92+
android:background="#eeeeee"/>
93+
94+
95+
<androidx.appcompat.widget.SwitchCompat
96+
android:id="@+id/switch_b_frame"
97+
android:layout_width="match_parent"
98+
android:layout_height="50dp"
99+
android:paddingHorizontal="16dp"
100+
android:text="@string/b_frame" />
101+
102+
103+
<View
104+
android:layout_width="match_parent"
105+
android:layout_height="1dp"
106+
android:layout_marginHorizontal="8dp"
107+
android:background="#eeeeee"/>
108+
109+
<androidx.appcompat.widget.SwitchCompat
110+
android:id="@+id/switch_first_frame"
111+
android:layout_width="match_parent"
112+
android:layout_height="50dp"
113+
android:paddingHorizontal="16dp"
114+
android:text="@string/first_frame_optimization" />
115+
116+
</LinearLayout>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
tools:padding="5dp"
7+
xmlns:app="http://schemas.android.com/apk/res-auto">
8+
9+
<io.agora.api.example.common.widget.VideoReportLayout
10+
android:id="@+id/foreground_video"
11+
android:layout_width="match_parent"
12+
android:layout_height="0dp"
13+
app:layout_constraintTop_toTopOf="parent"
14+
app:layout_constraintDimensionRatio="9:16"
15+
android:layout_gravity="center"
16+
tools:background="@color/colorAccent" />
17+
18+
19+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)