title: Xamarin forms Android SurfaceView - still video image left behind
body: <p>In my Xamarin forms Android app, I play videos in view 1 and 16 in a matrix of 16 views using Android SurfaceView integrating with third-party video SDK, see screenshot below. Then I switch to 4 views. On switching, I stopped both videos first and then resume playing. It still plays video in view 1 which is correct. But it also shows a still video image left behind (from previous view 16). Th surface view of this image should have been removed. What could be the cause of the image?</p>
  <p>I can clear a video or image and detach the camera using the following code. We do have such a command button Clear All.</p>
  <pre><code>public int ClearVideo(int cameraIndex)
  {
      if (App.CameraToViewHolderDictionary.ContainsKey(cameraIndex))
      {
          var surfaceHolder = (ISurfaceHolder)App.CameraToViewHolderDictionary[cameraIndex];
          if (surfaceHolder != null/* &amp;&amp; surfaceHolder.Surface.IsValid*/)
          {
              surfaceHolder.SetFormat(Format.Transparent);
              surfaceHolder.SetFormat(Format.Opaque);
          }
      }
  
      _videoViewModel.DetachCamera(cameraIndex);
  
      return 0;
  }
  </code></pre>
  <p>However this code shouldn't be required when changing the size of matrix views. Please suggest a way to get rid of the image left behind. Thank you.</p>
  <p>I understand that this may not be an issue of Xamarin forms. Please note that the app works on some Android versions such as Pixel 3 or emulators such as bluestacks.</p>
  <p><a href="https://i.stack.imgur.com/fTNXk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fTNXk.jpg" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/lwF8f.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lwF8f.jpg" alt="enter image description here" /></a></p>