Intro
I'm new to Jetpack Compose and it is not that easy for me to understand or get everything correct on my first try.
That's why I love to have a look at other's open-source work to understand the topic a little bit better.
Problem
My current problem is that I must embed YouTube videos into my app. At first, I thought I use an embedded web view, but hey, I'm a native app dev, let's do it native!
But I stumbled a lot
That's why it would be awesome if someone of you could point me into the correct direction to make any progress with my tiny self-learning app.
the simplest way is first just add this line in gradle file
"implementation" ("com.pierfrancescosoffritti.androidyoutubeplayer:core:11.1.0")
@Composable
fun YoutubeScreen(
videoId: String,
modifier: Modifier
) {
val ctx = LocalContext.current
AndroidView(factory = {
var view = YouTubePlayerView(it)
val fragment = view.addYouTubePlayerListener(
object : AbstractYouTubePlayerListener() {
override fun onReady(youTubePlayer: YouTubePlayer) {
super.onReady(youTubePlayer)
youTubePlayer.loadVideo(videoId, 0f)
}
}
)
view
})
}