title: Android VideoView: video goes black after being removed from parent view
body: <p>I am currently playing an rtsp live streaming source using a VideoView. This works fine. </p>
  
  <p>The VideoView is initially inside a fragment with other elements, in 'normal' state, and I am trying to implement a fullscreen toggle button.</p>
  
  <p>To go to fullscreen mode, I am removing the VideoView from its parent (a LinearLayout), and then adding it to another LinearLayout, added on top of everything else using getActivity().addContentView(), here's the code:</p>
  
  <pre><code>    LayoutInflater lf = getActivity().getLayoutInflater();          
      vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);             
  
      LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
  
      ((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
  
      fullscreenCont.addView(vsPlayer);
  
      LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
      getActivity().addContentView(vFullScreen, params);
  </code></pre>
  
  <p>The problem is that the video goes black once it's removed from the original parent view. </p>
  
  <p>What I'm trying to achieve it's to preserve the video instance to avoid having to reconnect/buffer again, but I don't know how to preserve the video playback during this switching of parents, any ideas? </p>
  
  <p>EDIT:</p>
  
  <p>If I suspend the videoView and then resume it, like this:</p>
  
  <pre><code>LayoutInflater lf = getActivity().getLayoutInflater();          
  vFullScreen = lf.inflate(R.layout.full_screen, myViewGroup, false);             
  
  LinearLayout fullscreenCont = (LinearLayout) vFullScreen.findViewById(R.id.fullscreen_container);
  
  vsPlayer.getVideoView().suspend();
  ((ViewGroup) vsPlayer.getParent()).removeView(vsPlayer);
  
  fullscreenCont.addView(vsPlayer);
  
  LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
  getActivity().addContentView(vFullScreen, params);
  vsPlayer.getVideoView().resume();
  </code></pre>
  
  <p>the video play is interrupted (goes black for a few noticeable seconds) but then resumes, wich is a lot better, not perfect because it takes too long to resume play.</p>
  
  <p>Another not so good part is that the methods suspend() and resume() of the class VideoView are available from API level 8 and up, and I need to be compatible with API level 7  </p>