@@ -51,15 +51,16 @@ public class LiveStreaming extends BaseFragment implements View.OnClickListener
5151 private static final String TAG = LiveStreaming .class .getSimpleName ();
5252
5353 private FrameLayout foreGroundVideo , backGroundVideo ;
54- private Button join , publish , latency ;
54+ private Button join , publish , latency , super_resolution ;
5555 private EditText et_channel ;
5656 private RtcEngine engine ;
5757 private int myUid ;
5858 private int remoteUid ;
5959 private boolean joined = false ;
6060 private boolean isHost = false ;
6161 private boolean isLowLatency = false ;
62- private boolean isLocalVideoForeground = false ;
62+ private boolean isLocalVideoForeground = true ;
63+ private boolean enableSuperResolution = false ;
6364 private SeekBar sbCameraRotate ;
6465
6566 @ Nullable
@@ -76,6 +77,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
7677 publish = view .findViewById (R .id .btn_publish );
7778 latency = view .findViewById (R .id .btn_latency );
7879 et_channel = view .findViewById (R .id .et_channel );
80+ super_resolution = view .findViewById (R .id .btn_super_resolution );
81+ super_resolution .setOnClickListener (this );
7982 latency .setEnabled (false );
8083 publish .setEnabled (false );
8184 view .findViewById (R .id .btn_join ).setOnClickListener (this );
@@ -166,6 +169,8 @@ public void onClick(View v) {
166169 joinChannel (channelId );
167170 }).start ();
168171 } else {
172+ remoteUid = 0 ;
173+ isHost = false ;
169174 joined = false ;
170175 /**After joining a channel, the user must call the leaveChannel method to end the
171176 * call before joining another channel. This method returns 0 if the user leaves the
@@ -185,10 +190,17 @@ public void onClick(View v) {
185190 * 2:If you call the leaveChannel method during CDN live streaming, the SDK
186191 * triggers the removeInjectStreamUrl method.*/
187192 engine .leaveChannel ();
188- join .setText (getString (R .string .join ));
193+ engine .stopPreview ();
194+
195+
189196 foreGroundVideo .removeAllViews ();
190197 backGroundVideo .removeAllViews ();
191- engine .stopPreview ();
198+
199+ publish .setText (getString (R .string .enable_publish ));
200+ join .setText (getString (R .string .join ));
201+ publish .setEnabled (false );
202+ latency .setEnabled (false );
203+ super_resolution .setEnabled (false );
192204 }
193205 } else if (v .getId () == R .id .btn_publish ) {
194206 isHost = !isHost ;
@@ -241,6 +253,11 @@ public void onClick(View v) {
241253 localView .setZOrderMediaOverlay (true );
242254 localView .setZOrderOnTop (true );
243255 }
256+ }else if (v .getId () == R .id .btn_super_resolution ){
257+ int ret = engine .enableRemoteSuperResolution (remoteUid , !enableSuperResolution );
258+ if (ret !=0 ){
259+ Log .w (TAG , String .format ("enableRemoteSuperResolution error code %d " , ret ));
260+ }
244261 }
245262
246263 }
@@ -481,6 +498,8 @@ public void onUserJoined(int uid, int elapsed) {
481498
482499 // Setup remote video to render
483500 engine .setupRemoteVideo (new VideoCanvas (surfaceView , RENDER_MODE_HIDDEN , remoteUid ));
501+
502+ super_resolution .setEnabled (true );
484503 });
485504 }
486505
@@ -498,13 +517,16 @@ public void onUserJoined(int uid, int elapsed) {
498517 public void onUserOffline (int uid , int reason ) {
499518 Log .i (TAG , String .format ("user %d offline! reason:%d" , uid , reason ));
500519 showLongToast (String .format ("user %d offline! reason:%d" , uid , reason ));
520+ remoteUid = 0 ;
501521 handler .post (new Runnable () {
502522 @ Override
503523 public void run () {
504524 /**Clear render view
505525 Note: The video will stay at its last frame, to completely remove it you will need to
506526 remove the SurfaceView from its parent*/
507527 engine .setupRemoteVideo (new VideoCanvas (null , RENDER_MODE_HIDDEN , uid ));
528+
529+ super_resolution .setEnabled (false );
508530 }
509531 });
510532 }
@@ -525,5 +547,36 @@ public void run() {
525547 }
526548 });
527549 }
550+
551+ /**
552+ *
553+ * @param uid remote user id
554+ * @param enabled updated status of super resolution
555+ * @param reason possible reasons are:
556+ * SR_STATE_REASON_SUCCESS(0)
557+ * SR_STATE_REASON_STREAM_OVER_LIMITATION(1)
558+ * SR_STATE_REASON_USER_COUNT_OVER_LIMITATION(2)
559+ * SR_STATE_REASON_DEVICE_NOT_SUPPORTED(3)
560+ */
561+ @ Override
562+ public void onUserSuperResolutionEnabled (int uid , boolean enabled , int reason ) {
563+ super .onUserSuperResolutionEnabled (uid , enabled , reason );
564+ if (uid == 0 && !enabled && reason == 3 ){
565+ showLongToast (String .format ("Unfortunately, Super Resolution can't enabled because your device doesn't support this feature." ));
566+ return ;
567+ }
568+ if (remoteUid == uid ){
569+ if (reason !=0 ){
570+ showLongToast (String .format ("Super Resolution can't enabled because of reason code: %d" , reason ));
571+ }
572+ enableSuperResolution = enabled ;
573+ handler .post (new Runnable () {
574+ @ Override
575+ public void run () {
576+ super_resolution .setText (enableSuperResolution ?getText (R .string .closesuperr ):getText (R .string .opensuperr ));
577+ }
578+ });
579+ }
580+ }
528581 };
529582}
0 commit comments