99import android .content .SharedPreferences ;
1010import android .os .Build ;
1111import android .os .IBinder ;
12+ import android .util .DisplayMetrics ;
1213import android .util .Log ;
1314
1415import 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 }
@@ -106,6 +123,8 @@ public static boolean isStreaming() {
106123
107124 public static void init (Context context ) {
108125 appContext = context ;
126+ DisplayMetrics dm = context .getResources ().getDisplayMetrics ();
127+ dpi = dm .densityDpi ;
109128 if (rtmpDisplayBase == null ) {
110129 rtmpDisplayBase = new RtmpDisplay (context , true , (ConnectCheckerRtmp ) context );
111130 }
0 commit comments