Skip to content

Commit

Permalink
Mute audio button
Browse files Browse the repository at this point in the history
  • Loading branch information
omouren committed Jun 1, 2021
1 parent e42d117 commit 9b1af78
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/com/fpvout/digiview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class MainActivity extends AppCompatActivity implements UsbDeviceListener
private float buttonAlpha = 1;
private View settingsButton;
private FloatingActionButton liveButton;
private FloatingActionButton muteButton;
private View watermarkView;
private OverlayView overlayView;
PendingIntent permissionIntent;
Expand Down Expand Up @@ -127,6 +128,12 @@ protected void onCreate(Bundle savedInstanceState) {
});

StreamingService.init(this);
muteButton = findViewById(R.id.muteButton);
muteButton.setOnClickListener(v -> {
StreamingService.toggleMute();
updateLiveButtonIcon();
});

liveButton = findViewById(R.id.liveButton);
liveButton.setOnClickListener(v -> {
if (!StreamingService.isStreaming()) {
Expand Down Expand Up @@ -444,8 +451,16 @@ private void checkDataCollectionAgreement() {
private void updateLiveButtonIcon() {
runOnUiThread(() -> {
if (StreamingService.isStreaming()) {
if (StreamingService.isMuted()) {
muteButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_microphone_slash_solid, this.getTheme()));
} else {
muteButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_microphone_solid, this.getTheme()));
}

toggleView(muteButton, true);
liveButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.exo_icon_stop, this.getTheme()));
} else {
toggleView(muteButton, false);
liveButton.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.exo_icon_play, this.getTheme()));
}
});
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/fpvout/digiview/StreamingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ public static boolean isStreaming() {
return rtmpDisplayBase != null && rtmpDisplayBase.isStreaming();
}

public static boolean isMuted() {
return rtmpDisplayBase != null && rtmpDisplayBase.isAudioMuted();
}

public static void toggleMute() {
if (isStreaming()) {
if (rtmpDisplayBase.isAudioMuted()) {
rtmpDisplayBase.enableAudio();
} else {
rtmpDisplayBase.disableAudio();
}
}
}

public static void init(Context context) {
appContext = context;
DisplayMetrics dm = context.getResources().getDisplayMetrics();
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_microphone_slash_solid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="640dp"
android:height="512dp"
android:viewportWidth="640"
android:viewportHeight="512">
<path
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"
android:fillColor="#FFFFFFFF"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_microphone_solid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="640dp"
android:height="512dp"
android:viewportWidth="640"
android:viewportHeight="512">

<group android:translateX="144">
<path
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"
android:fillColor="#FFFFFFFF"/>
</group>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/exo_icon_play" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:alpha="0"
android:id="@+id/muteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:layout_marginBottom="25dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/liveButton"
app:srcCompat="@drawable/ic_microphone_solid" />

<ProgressBar
android:layout_width="1px"
android:layout_height="1px"
Expand Down

0 comments on commit 9b1af78

Please sign in to comment.