1818
1919import androidx .annotation .NonNull ;
2020import androidx .annotation .Nullable ;
21+ import androidx .appcompat .widget .SwitchCompat ;
2122
2223import com .yanzhenjie .permission .AndPermission ;
2324import com .yanzhenjie .permission .runtime .Permission ;
2829import io .agora .api .example .R ;
2930import io .agora .api .example .annotation .Example ;
3031import io .agora .api .example .common .BaseFragment ;
32+ import io .agora .api .example .common .Constant ;
3133import io .agora .api .example .common .widget .VideoReportLayout ;
3234import io .agora .api .example .utils .CommonUtil ;
3335import io .agora .api .example .utils .TokenUtils ;
3941import io .agora .rtc2 .RtcEngineConfig ;
4042import io .agora .rtc2 .video .VideoCanvas ;
4143import io .agora .rtc2 .video .VideoEncoderConfiguration ;
44+ import io .agora .rtc2 .video .WatermarkOptions ;
4245
4346/**
4447 * This demo demonstrates how to make a one-to-one video call
@@ -67,6 +70,7 @@ public class LiveStreaming extends BaseFragment implements View.OnClickListener
6770 private boolean isHost = false ;
6871 private boolean isLowLatency = false ;
6972 private boolean isLocalVideoForeground = true ;
73+ private SwitchCompat watermarkSwitch ;
7074
7175 @ Nullable
7276 @ Override
@@ -90,6 +94,24 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9094 foreGroundVideo = view .findViewById (R .id .background_video );
9195 backGroundVideo = view .findViewById (R .id .foreground_video );
9296 view .findViewById (R .id .btn_take_shot ).setOnClickListener (this );
97+ watermarkSwitch = view .findViewById (R .id .switch_watermark );
98+ watermarkSwitch .setOnCheckedChangeListener ((buttonView , isChecked ) -> {
99+ if (isChecked ) {
100+ engine .enableVideo ();
101+ WatermarkOptions watermarkOptions = new WatermarkOptions ();
102+ int size = ((MainApplication ) getActivity ().getApplication ()).getGlobalSettings ().getVideoEncodingDimensionObject ().width / 6 ;
103+ int height = ((MainApplication ) getActivity ().getApplication ()).getGlobalSettings ().getVideoEncodingDimensionObject ().height ;
104+ watermarkOptions .positionInPortraitMode = new WatermarkOptions .Rectangle (10 , height / 2 , size , size );
105+ watermarkOptions .positionInLandscapeMode = new WatermarkOptions .Rectangle (10 , height / 2 , size , size );
106+ watermarkOptions .visibleInPreview = true ;
107+ int ret = engine .addVideoWatermark (Constant .WATER_MARK_FILE_PATH , watermarkOptions );
108+ if (ret != Constants .ERR_OK ) {
109+ Log .e (TAG , "addVideoWatermark error=" + ret + ", msg=" + RtcEngine .getErrorDescription (ret ));
110+ }
111+ } else {
112+ engine .clearVideoWatermarks ();
113+ }
114+ });
93115 }
94116
95117 @ Override
@@ -179,6 +201,9 @@ public void onClick(View v) {
179201 engine .stopPreview ();
180202 engine .leaveChannel ();
181203 join .setText (getString (R .string .join ));
204+ watermarkSwitch .setEnabled (false );
205+ publish .setEnabled (false );
206+ latency .setEnabled (false );
182207 remoteUid = 0 ;
183208 }
184209 } else if (v .getId () == R .id .btn_publish ) {
@@ -487,10 +512,12 @@ public void run() {
487512 */
488513 @ Override
489514 public void onClientRoleChanged (int oldRole , int newRole ) {
490- Log .i (TAG , String .format ("client role changed from state %d to %d" , oldRole , newRole )); handler .post (new Runnable () {
515+ Log .i (TAG , String .format ("client role changed from state %d to %d" , oldRole , newRole ));
516+ handler .post (new Runnable () {
491517 @ Override
492518 public void run () {
493519 publish .setEnabled (true );
520+ watermarkSwitch .setEnabled (newRole == Constants .CLIENT_ROLE_BROADCASTER );
494521 }
495522 });
496523 }
0 commit comments