Skip to content

Commit 3f7d9a5

Browse files
committed
Add internal audio streaming + Mute audio button
1 parent 799bd59 commit 3f7d9a5

File tree

14 files changed

+138
-9
lines changed

14 files changed

+138
-9
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/SettingsActivity.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.fpvout.digiview;
22

3+
import android.os.Build;
34
import android.os.Bundle;
45
import android.view.MenuItem;
56

67
import androidx.annotation.NonNull;
78
import androidx.appcompat.app.ActionBar;
89
import androidx.appcompat.app.AppCompatActivity;
10+
import androidx.preference.ListPreference;
911
import androidx.preference.PreferenceFragmentCompat;
1012

13+
import java.util.ArrayList;
14+
import java.util.Arrays;
15+
1116
public class SettingsActivity extends AppCompatActivity {
1217

1318
@Override
@@ -41,6 +46,19 @@ public static class SettingsFragment extends PreferenceFragmentCompat {
4146
@Override
4247
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
4348
setPreferencesFromResource(R.xml.root_preferences, rootKey);
49+
50+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
51+
ListPreference audioSourcePreference = findPreference("AudioSource");
52+
53+
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(audioSourcePreference.getEntries()));
54+
ArrayList<CharSequence> entryValues = new ArrayList<>(Arrays.asList(audioSourcePreference.getEntryValues()));
55+
56+
entries.add(getString(R.string.audio_source_internal));
57+
entryValues.add("internal");
58+
59+
audioSourcePreference.setEntries(entries.toArray(new CharSequence[0]));
60+
audioSourcePreference.setEntryValues(entryValues.toArray(new CharSequence[0]));
61+
}
4462
}
4563
}
4664
}

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.content.SharedPreferences;
1010
import android.os.Build;
1111
import android.os.IBinder;
12+
import android.util.DisplayMetrics;
1213
import android.util.Log;
1314

1415
import androidx.annotation.Nullable;
@@ -30,6 +31,7 @@ public class StreamingService extends Service {
3031
private static Intent mediaProjectionData;
3132
private static int mediaProjectionResultCode;
3233
private static DisplayBase rtmpDisplayBase;
34+
private static int dpi;
3335
private String endpoint;
3436
@Nullable
3537
@Override
@@ -75,9 +77,24 @@ private void startStreaming() {
7577
Integer.parseInt(sharedPreferences.getString("OutputFramerate", "60")),
7678
Integer.parseInt(sharedPreferences.getString("OutputBitrate", "1200")) * 1024,
7779
0,
78-
320
79-
) && rtmpDisplayBase.prepareAudio()) {
80-
rtmpDisplayBase.startStream(endpoint);
80+
dpi
81+
)) {
82+
boolean audioInitialized;
83+
if (sharedPreferences.getString("AudioSource", "0").equals("internal") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
84+
audioInitialized = rtmpDisplayBase.prepareInternalAudio(64 * 1024, 32000, true, false, false);
85+
} else {
86+
audioInitialized = rtmpDisplayBase.prepareAudio(Integer.parseInt(sharedPreferences.getString("AudioSource", "0")), 64 * 1024, 32000, false, false, false);
87+
}
88+
89+
if (audioInitialized) {
90+
if (!sharedPreferences.getBoolean("RecordAudio", true)) {
91+
rtmpDisplayBase.disableAudio();
92+
} else {
93+
rtmpDisplayBase.enableAudio();
94+
}
95+
96+
rtmpDisplayBase.startStream(endpoint);
97+
}
8198
}
8299
}
83100
}
@@ -104,8 +121,24 @@ public static boolean isStreaming() {
104121
return rtmpDisplayBase != null && rtmpDisplayBase.isStreaming();
105122
}
106123

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+
107138
public static void init(Context context) {
108139
appContext = context;
140+
DisplayMetrics dm = context.getResources().getDisplayMetrics();
141+
dpi = dm.densityDpi;
109142
if (rtmpDisplayBase == null) {
110143
rtmpDisplayBase = new RtmpDisplay(context, true, (ConnectCheckerRtmp) context);
111144
}
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"

app/src/main/res/values-de/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
<string name="record_audio">Record audio</string>
4747
<string name="audio_source">Audio source</string>
4848
<string name="audio_source_default">Default</string>
49+
<string name="audio_source_mic">Mic</string>
50+
<string name="audio_source_cam">Camera</string>
51+
<string name="audio_source_communication">Communication</string>
52+
<string name="audio_source_performance">Performance</string>
4953
<string name="audio_source_internal">Internal audio</string>
5054
<string name="output_width">Output Width</string>
5155
<string name="output_height">Output Height</string>

app/src/main/res/values-es/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
<string name="record_audio">Record audio</string>
4646
<string name="audio_source">Audio source</string>
4747
<string name="audio_source_default">Default</string>
48+
<string name="audio_source_mic">Mic</string>
49+
<string name="audio_source_cam">Camera</string>
50+
<string name="audio_source_communication">Communication</string>
51+
<string name="audio_source_performance">Performance</string>
4852
<string name="audio_source_internal">Internal audio</string>
4953
<string name="output_width">Output Width</string>
5054
<string name="output_height">Output Height</string>

app/src/main/res/values-fr/strings.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
<string name="rtmp_key">RTMP Key</string>
4343
<string name="record_audio">Enregistrer le son</string>
4444
<string name="audio_source">Source audio</string>
45-
<string name="audio_source_default">Micro par défaut</string>
45+
<string name="audio_source_default">Par défaut</string>
46+
<string name="audio_source_mic">Mic</string>
47+
<string name="audio_source_cam">Camera</string>
48+
<string name="audio_source_communication">Communication</string>
49+
<string name="audio_source_performance">Performance</string>
4650
<string name="audio_source_internal">Audio interne</string>
4751
<string name="output_width">Output Width</string>
4852
<string name="output_height">Output Height</string>

app/src/main/res/values-pt/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
<string name="record_audio">Record audio</string>
4646
<string name="audio_source">Audio source</string>
4747
<string name="audio_source_default">Default</string>
48+
<string name="audio_source_mic">Mic</string>
49+
<string name="audio_source_cam">Camera</string>
50+
<string name="audio_source_communication">Communication</string>
51+
<string name="audio_source_performance">Performance</string>
4852
<string name="audio_source_internal">Internal audio</string>
4953
<string name="output_width">Output Width</string>
5054
<string name="output_height">Output Height</string>

0 commit comments

Comments
 (0)