Play Youtube videos in your App

  1. Download youtube player API from
  2. Extract the downloaded file and copy “YouTubeAndroidPlayerApi.jar”
  3. Paste “YouTubeAndroidPlayerApi.jar” to your android project “libs” folder
  4. Register your application: open the credential page here
  5. Click on create Project (if you don't have already).
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.FirstProject"
minSdkVersion 16
targetSdkVersion 29
versionCode buildCode
versionName buildName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
private fun startYoutubeActivity(videoId: String) {
val intent = YouTubeStandalonePlayer.createVideoIntent(this, BuildConfig.YOUTUBE_DEVELOPER_KEY, videoId)
if (intent.resolveActivity(this.packageManager) != null) {
} else {
val webIntent = Intent(Intent.ACTION_VIEW, Uri.parse("$videoId"))
if (webIntent.resolveActivity(this.packageManager) != null) {
} else {
// handle the error here



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gaurav Rajput

Gaurav Rajput

Working remotely as Android Developer