title: Loading Youtube video through iframe in Android webview
body: <p>I want to load youtube video to Android webview using iframe</p>
  
  <p>here is my layout Xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@android:color/white"
  android:id="@+id/mainLayout"&gt;
  
  &lt;WebView
      android:background="@android:color/white"
      android:id="@+id/webView"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>public class WebTube extends Activity {
  
  private WebView wv;
  
  String html = "&lt;iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/WBYnk3zR0os"
              + "?fs=0\" frameborder=\"0\"&gt;\n"
              + "&lt;/iframe&gt;";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_main);
  
      wv = (WebView)findViewById(R.id.webView); 
      wv.getSettings().setJavaScriptEnabled(true);
          wv.loadDataWithBaseURL("", html , "text/html",  "UTF-8", "");
  
       }
  } 
  </code></pre>
  
  <p>Also I provide <code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;</code></p>
  
  <p>&amp; <code>android:hardwareAccelerated="true"</code></p>
  
  <p>when I run this I didn't get any result its just showing a black screen </p>
  
  <p>I tried <a href="https://stackoverflow.com/questions/11117720/play-video-file-from-youtube-in-android?answertab=active#tab-top">this</a> .but this provide me video on <code>.3gp Quality</code> . but I need the videos from youtube on original quality. That's why I am using <code>iframe</code>.</p>
  
  <p>I try code using <code>&lt;object&gt;&lt;/object&gt;</code> and <code>&lt;video&gt;&lt;/video&gt;</code> instead of <code>iframe</code>. but it didn't solve my issue.</p>
  
  <p>when I run this code on emulator it shows</p>
  
  <p>Before Pressing Play Button</p>
  
  <p><img src="https://i.stack.imgur.com/Q1tmQ.jpg" alt="iframe result on emulator"></p>
  
  <p>After Pressing Play button on video</p>
  
  <p><img src="https://i.stack.imgur.com/SU3pm.jpg" alt="iframe result on emulator on play button click"></p>
  
  <p>I think we cannot stream videos on emulator since it is a virtual device</p>
  
  <p>But when I run this on phone it's not even showing this result. </p>
  
  <p>I try iframe with a document attach to it works fine on phone as well as emulator </p>
  
  <pre><code>String customHtml = "&lt;iframe src='http://docs.google.com/viewer?url=http://www.iasted.org/conferences/formatting/presentations-tips.ppt&amp;embedded=true' width='100%' height='100%' style='border: none;'&gt;&lt;/iframe&gt;";
  </code></pre>
  
  <p>So please help me to load videos to this frame.</p>
  
  <p>(I run it on phone). What's the problem?
  also will iframe work on Android 2.1?</p>
  
  <p>did any one tried <a href="https://developers.google.com/youtube/android/player/downloads/" rel="nofollow noreferrer">Youtube Api</a> ? </p>