Play Youtube videos in your App

  1. Download youtube player API from https://developers.google.com/youtube/android/player/downloads
  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 https://console.developers.google.com/projectselector2/apis/credentials?supportedpurview=project&project&folder&organizationId
  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"
buildConfigField 'String', 'YOUTUBE_DEVELOPER_KEY', YOUTUBE_DEVELOPER_KEY
}
}
private fun startYoutubeActivity(videoId: String) {
val intent = YouTubeStandalonePlayer.createVideoIntent(this, BuildConfig.YOUTUBE_DEVELOPER_KEY, videoId)
if (intent.resolveActivity(this.packageManager) != null) {
this.startActivity(intent)
} else {
val webIntent = Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=$videoId"))
if (webIntent.resolveActivity(this.packageManager) != null) {
this.startActivity(webIntent)
} else {
// handle the error here
}
}
}

Working remotely as Android Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to get Android Device Current location, i.e

How to add country code picker in Android studio

Pushing the right buttons in Jetpack Compose

Jetpack Compose banner with a laptop, Android logo, mobile phone, and other general shapes.

Integrate the Behavior Awareness feature using Huawei Awareness kit in Android (Kotlin)

PageObject Pattern into App Integration Tests

Differences Between A Normal Class and A Data Class In Kotlin

Navigating in a pure jetpack compose project — part #1

How to preload Room Database with prepackaged DB 🗃

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

More from Medium

I will do instagram marketing or promote for organic growth fast

10 TOP LOGO DESIGNERS AND THEIR GIGS ON FIVERR 2022.

How to run a website audit?

How to Use Video to Expand your Reach on Social Media

video to expand reach