0

i am trying to play a youtube video in android webview.. The following are the things that i have done

VideoWebview.java :

String URL = "http://www.youtube.com/results";

WebSettings settings = volWebview.getSettings();

settings.setPluginState(PluginState.ON);

settings.setJavaScriptEnabled(true);

volWebview.setWebViewClient(new WebViewClient());   

volWebview.setInitialScale(1);

volWebview.setWebChromeClient(new WebChromeClient());

settings.setLoadWithOverviewMode(true);

settings.setUseWideViewPort(true);

volWebview.loadUrl(URL);

webview_file.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <WebView
        android:id="@+id/web_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

i have added android:hardwareAccelerated="true" to the manifest file

The url is getting loaded.. but when tried to play a video, its not playing. Any help regarding the same will be highly appreciated.. Thank you..

Amith_Nagraj
  • 231
  • 1
  • 2
  • 9

2 Answers2

0

Make sure that you have set internet permission in your manifest file

  <uses-permission android:name="android.permission.INTERNET" />
ADT
  • 255
  • 1
  • 4
  • 14
0

In place of webview use VideoView this is working for me see this one

Activity.java

   private VideoView myVideoView;

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.videoplay);

     videoplay();

 }
   private void videoplay() {   

    myVideoView = (VideoView) findViewById(R.id.myvideoview);    
    myVideoView.setVideoPath(DATA_PATH); // this is url path
    myVideoView.setMediaController(new MediaController(this));
    myVideoView.requestFocus();      

}

videoplay.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<VideoView
    android:id="@+id/myvideoview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" />

</RelativeLayout>
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
  • thanks for instant repy.. i have a situation where in i have to load a youtube link in my webview. when clicked on it, it has to start playing video on the same page.. how to achieve this?? – Amith_Nagraj Oct 15 '13 at 10:51