0

I try to load youtube website using WebView in Android application. Need to load whole youtube site to WebView (not only one certain video url). It means user select video on youtube site and then play. But the playing of video is jammming. Is it wrong way using youtube inside application ?

I am using this code: webView.loadUrl(url);

mira
  • 1,056
  • 3
  • 15
  • 32
  • For your usecase I would advise you to use [Chrome Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs). In your case this would fit better then a WebView and its performance is a lot better too :). I hope this would also solve your issue! – Rene Ferrari Dec 16 '17 at 22:53
  • hi mira , did you the tried the below answer , i have shared the working code and picture of screenshot too , it worked , – Sachin Rajput Jan 07 '18 at 13:44

2 Answers2

0

pls Follow this code it will work for you

MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

private WebView mWebview ;
private String youtubeUrl = "https://www.youtube.com/";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebview = (WebView) findViewById(R.id.youtubeWebView);
    mWebview.loadUrl(youtubeUrl);
    mWebview.getSettings().setJavaScriptEnabled(true);

}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

</android.support.constraint.ConstraintLayout>

and add Internet Permission inside your Manifest file

AndroidManifest.xml

 <uses-permission android:name="android.permission.INTERNET" />

it will looks like this in the below pic.

enter image description here

Sachin Rajput
  • 4,326
  • 2
  • 18
  • 29
0

you can load any url into web view and add the internet permission inside your app's manifest file and use like below code --

yourWebView.loadUrl(youtubeUrl);

this works for me , i am sure it will work mate