title: Android - YouTube Api player on floating window using service
body: <p>I like to implement YouTube Player as a floating window (on top all apps)  on Android.</p>
  
  <p>I saw many apps that do the same
  <a href="https://play.google.com/store/apps/details?id=com.sarvopari.anytime.floatingtubeplayer&amp;hl=en&amp;rdid=com.sarvopari.anytime.floatingtubeplayer" rel="nofollow noreferrer">like this one</a></p>
  
  <p>And I try to Understand how to implement it.</p>
  
  <p>I tried this :</p>
  
  <pre><code> wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
   LayoutInflater li = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
   View vi = li.inflate(R.layout.youtube_view,null);
   YouTubePlayerView youTubeView = vi.findViewById(R.id.youtube_view);
   youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
  </code></pre>
  
  <p>But get This error :</p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: A YouTubePlayerView can only be created with an Activity  which extends YouTubeBaseActivity as its context
  </code></pre>
  
  <p>And it is obvious - as I extends Service and not YouTubeBaseActivity</p>
  
  <p>Did all those floating YouTube apps use webview as the player container ?
  or did i miss better solution using the official <a href="https://developers.google.com/youtube/android/player/downloads/" rel="nofollow noreferrer">Youtube Player API</a></p>