Skip to content

Commit 9b1af78

Browse files
committed
Mute audio button
1 parent e42d117 commit 9b1af78

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

app/src/main/java/com/fpvout/digiview/MainActivity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class MainActivity extends AppCompatActivity implements UsbDeviceListener
5454
private float buttonAlpha = 1;
5555
private View settingsButton;
5656
private FloatingActionButton liveButton;
57+
private FloatingActionButton muteButton;
5758
private View watermarkView;
5859
private OverlayView overlayView;
5960
PendingIntent permissionIntent;
@@ -127,6 +128,12 @@ protected void onCreate(Bundle savedInstanceState) {
127128
});
128129

129130
StreamingService.init(this);
131+
muteButton = findViewById(R.id.muteButton);
132+
muteButton.setOnClickListener(v -> {
133+
StreamingService.toggleMute();
134+
updateLiveButtonIcon();
135+
});
136+
130137
liveButton = findViewById(R.id.liveButton);
131138
liveButton.setOnClickListener(v -> {
132139
if (!StreamingService.isStreaming()) {
@@ -444,8 +451,16 @@ private void checkDataCollectionAgreement() {
444451
private void updateLiveButtonIcon() {
445452
runOnUiThread(() -> {
446453
if (StreamingService.isStreaming()) {
454+
if (StreamingService.isMuted()) {
455+
muteButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_microphone_slash_solid, this.getTheme()));
456+
} else {
457+
muteButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_microphone_solid, this.getTheme()));
458+
}
459+
460+
toggleView(muteButton, true);
447461
liveButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.exo_icon_stop, this.getTheme()));
448462
} else {
463+
toggleView(muteButton, false);
449464
liveButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.exo_icon_play, this.getTheme()));
450465
}
451466
});

app/src/main/java/com/fpvout/digiview/StreamingService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ public static boolean isStreaming() {
121121
return rtmpDisplayBase != null && rtmpDisplayBase.isStreaming();
122122
}
123123

124+
public static boolean isMuted() {
125+
return rtmpDisplayBase != null && rtmpDisplayBase.isAudioMuted();
126+
}
127+
128+
public static void toggleMute() {
129+
if (isStreaming()) {
130+
if (rtmpDisplayBase.isAudioMuted()) {
131+
rtmpDisplayBase.enableAudio();
132+
} else {
133+
rtmpDisplayBase.disableAudio();
134+
}
135+
}
136+
}
137+
124138
public static void init(Context context) {
125139
appContext = context;
126140
DisplayMetrics dm = context.getResources().getDisplayMetrics();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="640dp"
3+
android:height="512dp"
4+
android:viewportWidth="640"
5+
android:viewportHeight="512">
6+
<path
7+
android:pathData="M633.82,458.1l-157.8,-121.96C488.61,312.13 496,285.01 496,256v-48c0,-8.84 -7.16,-16 -16,-16h-16c-8.84,0 -16,7.16 -16,16v48c0,17.92 -3.96,34.8 -10.72,50.2l-26.55,-20.52c3.1,-9.4 5.28,-19.22 5.28,-29.67V96c0,-53.02 -42.98,-96 -96,-96s-96,42.98 -96,96v45.36L45.47,3.37C38.49,-2.05 28.43,-0.8 23.01,6.18L3.37,31.45C-2.05,38.42 -0.8,48.47 6.18,53.9l588.36,454.73c6.98,5.43 17.03,4.17 22.46,-2.81l19.64,-25.27c5.41,-6.97 4.16,-17.02 -2.82,-22.45zM400,464h-56v-33.77c11.66,-1.6 22.85,-4.54 33.67,-8.31l-50.11,-38.73c-6.71,0.4 -13.41,0.87 -20.35,0.2 -55.85,-5.45 -98.74,-48.63 -111.18,-101.85L144,241.31v6.85c0,89.64 63.97,169.55 152,181.69V464h-56c-8.84,0 -16,7.16 -16,16v16c0,8.84 7.16,16 16,16h160c8.84,0 16,-7.16 16,-16v-16c0,-8.84 -7.16,-16 -16,-16z"
8+
android:fillColor="#FFFFFFFF"/>
9+
</vector>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="640dp"
3+
android:height="512dp"
4+
android:viewportWidth="640"
5+
android:viewportHeight="512">
6+
7+
<group android:translateX="144">
8+
<path
9+
android:pathData="M176,352c53.02,0 96,-42.98 96,-96L272,96c0,-53.02 -42.98,-96 -96,-96S80,42.98 80,96v160c0,53.02 42.98,96 96,96zM336,192h-16c-8.84,0 -16,7.16 -16,16v48c0,74.8 -64.49,134.82 -140.79,127.38C96.71,376.89 48,317.11 48,250.3L48,208c0,-8.84 -7.16,-16 -16,-16L16,192c-8.84,0 -16,7.16 -16,16v40.16c0,89.64 63.97,169.55 152,181.69L152,464L96,464c-8.84,0 -16,7.16 -16,16v16c0,8.84 7.16,16 16,16h160c8.84,0 16,-7.16 16,-16v-16c0,-8.84 -7.16,-16 -16,-16h-56v-33.77C285.71,418.47 352,344.9 352,256v-48c0,-8.84 -7.16,-16 -16,-16z"
10+
android:fillColor="#FFFFFFFF"/>
11+
</group>
12+
</vector>

app/src/main/res/layout/activity_main.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
app:layout_constraintEnd_toEndOf="parent"
6565
app:srcCompat="@drawable/exo_icon_play" />
6666

67+
<com.google.android.material.floatingactionbutton.FloatingActionButton
68+
android:alpha="0"
69+
android:id="@+id/muteButton"
70+
android:layout_width="wrap_content"
71+
android:layout_height="wrap_content"
72+
android:layout_marginEnd="15dp"
73+
android:layout_marginBottom="25dp"
74+
android:clickable="true"
75+
app:layout_constraintBottom_toBottomOf="parent"
76+
app:layout_constraintEnd_toStartOf="@id/liveButton"
77+
app:srcCompat="@drawable/ic_microphone_solid" />
78+
6779
<ProgressBar
6880
android:layout_width="1px"
6981
android:layout_height="1px"

0 commit comments

Comments
 (0)