11package io .agora .api .example .examples .advanced ;
22
3+ import static io .agora .api .example .common .model .Examples .ADVANCED ;
4+ import static io .agora .rtc .video .VideoEncoderConfiguration .STANDARD_BITRATE ;
5+
36import android .annotation .TargetApi ;
47import android .content .Context ;
58import android .graphics .Bitmap ;
1518import android .view .LayoutInflater ;
1619import android .view .MotionEvent ;
1720import android .view .PixelCopy ;
18- import android .view .SurfaceView ;
1921import android .view .View ;
2022import android .view .ViewGroup ;
2123import android .widget .Button ;
2224import android .widget .EditText ;
23- import android .widget .FrameLayout ;
2425import android .widget .Toast ;
2526
2627import androidx .annotation .NonNull ;
3536import com .google .ar .core .HitResult ;
3637import com .google .ar .core .Plane ;
3738import com .google .ar .core .Point ;
38- import com .google .ar .core .PointCloud ;
3939import com .google .ar .core .Session ;
4040import com .google .ar .core .Trackable ;
4141import com .google .ar .core .TrackingState ;
4444import com .google .ar .core .exceptions .UnavailableArcoreNotInstalledException ;
4545import com .google .ar .core .exceptions .UnavailableSdkTooOldException ;
4646import com .google .ar .core .exceptions .UnavailableUserDeclinedInstallationException ;
47- import com .yanzhenjie .permission .AndPermission ;
48- import com .yanzhenjie .permission .runtime .Permission ;
4947
5048import java .io .IOException ;
5149import java .nio .ByteBuffer ;
7472import io .agora .rtc .RtcEngine ;
7573import io .agora .rtc .mediaio .MediaIO ;
7674import io .agora .rtc .models .ChannelMediaOptions ;
77- import io .agora .rtc .video .VideoCanvas ;
7875import io .agora .rtc .video .VideoEncoderConfiguration ;
7976
80- import static io .agora .api .example .common .model .Examples .ADVANCED ;
81- import static io .agora .rtc .video .VideoCanvas .RENDER_MODE_HIDDEN ;
82- import static io .agora .rtc .video .VideoEncoderConfiguration .STANDARD_BITRATE ;
83-
8477/**This demo demonstrates how to make a one-to-one video call*/
8578@ Example (
8679 index = 24 ,
@@ -166,7 +159,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
166159 join = view .findViewById (R .id .btn_join );
167160 et_channel = view .findViewById (R .id .et_channel );
168161 et_channel .setText ("arcoreDemo" );
169- joinChannel ("arcoreDemo" );
170162 view .findViewById (R .id .btn_join ).setOnClickListener (this );
171163 mSurfaceView = view .findViewById (R .id .fl_local );
172164 mDisplayRotationHelper = new DisplayRotationHelper (getContext ());
@@ -216,6 +208,10 @@ public void onDestroy()
216208 {
217209 super .onDestroy ();
218210 /**leaveChannel and Destroy the RtcEngine instance*/
211+ if (mSession != null ){
212+ mSession .close ();
213+ mSession = null ;
214+ }
219215 if (engine != null )
220216 {
221217 engine .leaveChannel ();
@@ -228,7 +224,10 @@ public void onDestroy()
228224 //mRtcEngine.setRemoteVideoRenderer(render.getPeer().uid, null);
229225 }
230226 mRemoteRenders .clear ();
231- mSenderHandler .getLooper ().quit ();
227+ if (mSenderHandler != null ){
228+ mSenderHandler .getLooper ().quit ();
229+ mSenderHandler = null ;
230+ }
232231 }
233232
234233 @ Override
@@ -242,21 +241,7 @@ public void onClick(View v)
242241 // call when join button hit
243242 String channelId = et_channel .getText ().toString ();
244243 // Check permission
245- if (AndPermission .hasPermissions (this , Permission .Group .STORAGE , Permission .Group .MICROPHONE , Permission .Group .CAMERA ))
246- {
247- joinChannel (channelId );
248- return ;
249- }
250- // Request permission
251- AndPermission .with (this ).runtime ().permission (
252- Permission .Group .STORAGE ,
253- Permission .Group .MICROPHONE ,
254- Permission .Group .CAMERA
255- ).onGranted (permissions ->
256- {
257- // Permissions Granted
258- joinChannel (channelId );
259- }).start ();
244+ joinChannel (channelId );
260245 }
261246 else
262247 {
@@ -280,6 +265,10 @@ public void onClick(View v)
280265 * triggers the removeInjectStreamUrl method.*/
281266 engine .leaveChannel ();
282267 join .setText (getString (R .string .join ));
268+ if (mSenderHandler != null ) {
269+ mSenderHandler .getLooper ().quit ();
270+ mSenderHandler = null ;
271+ }
283272 }
284273 }
285274 }
@@ -584,14 +573,17 @@ public void onResume() {
584573
585574 @ RequiresApi (api = Build .VERSION_CODES .N )
586575 private void sendARViewMessage () {
576+ if (mSenderHandler == null ) {
577+ return ;
578+ }
587579 final Bitmap outBitmap = Bitmap .createBitmap (mSurfaceView .getWidth (), mSurfaceView .getHeight (), Bitmap .Config .ARGB_8888 );
588580 PixelCopy .request (mSurfaceView , outBitmap , new PixelCopy .OnPixelCopyFinishedListener () {
589581 @ Override
590582 public void onPixelCopyFinished (int copyResult ) {
591583 if (copyResult == PixelCopy .SUCCESS ) {
592584 sendARView (outBitmap );
593585 } else {
594- Toast .makeText (getContext (), "Pixel Copy Failed" , Toast .LENGTH_SHORT );
586+ handler . post (() -> Toast .makeText (getContext (), "Pixel Copy Failed" , Toast .LENGTH_SHORT ). show () );
595587 }
596588 }
597589 }, mSenderHandler );
0 commit comments