The most easiest and simplest Tutorial step by step with free source code: Play YouTube Video using WebView Widget in Android Studio version 3.1.2. Create new project with Application name: Play YouTube Video; Minimum SDK: API 27 – Android 8.1 (Oreo). In manifest->AndroidManifest.xml write the code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.app.toyo.playyoutubevideo"
    android:installLocation="preferExternal">

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
  In app->res->layout->activity_main.xml write the code:
<?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"
    tools:context=".MainActivity">

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

</android.support.constraint.ConstraintLayout>
  In app->java->MainActivity.java write the code:
package com.app.toyo.playyoutubevideo;

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

public class MainActivity extends AppCompatActivity {

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

        WebView webView = (WebView)
                findViewById(R.id.webview);
        webView.loadUrl("https://youtu.be/vA2XLB2znsw");
    }
}
Run app in mobile device or Emulator (API 27 – Android 8.1) and watch video from YouTube in format portrait or landscape. Follow Video Tutorial How to Play YouTube Video in Android Studio:
  Download free PlayYouTubeVideo application and install it on your mobile device to see how it works: https://android-coffee.com/wp-content/uploads/projecs/PlayYouTubeVideo.apk Download project with Source Code from here: https://android-coffee.com/wp-content/uploads/projecs/PlayYouTubeVideo.7z Please subscribe here to our YouTube channel. Thank you! Check next tutorials to learn all about Android. For further questions leave a message.

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image Refresh

*