YouTube Android Player API SDK has been fully deprecated. It is no longer supported or maintained by YouTube. So need to implement YouTube IFrame Player API in Android.
When play an YouTube video "An error occurred while initializing YouTube player" message shows.
As per developer.google documentation https://developers.google.com/youtube/iframe_api_reference I create a sample app using IFrame YouTube player for android using Kotlin and jetpack compose.
use the below dependency
implementation "androidx.webkit:webkit:1.4.0"
Give internet permission in Manifest.xml
uses-permission android:name="android.permission.INTERNET"
Create a Compose function
Use getHTMLData function to load the HTML page contain IFrame
Call compose function in Main activity