Я пытаюсь загрузить YoutubePlayer в GroupieViewHolder, который затем загружаю в Recyclerview. Я получаю следующую ошибку и изо всех сил пытаюсь решить проблему. У вас есть предложения по ее исправлению?
Ошибка
android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class com.google.android.youtube.player.YouTubePlayerView
Часть MainActivity.kt
val adapter = GroupAdapter<GroupieViewHolder>()
recyclerview.adapter = adapter
adapter.add(VideoContentRow("wKJ9KzGQq0w"))
VideoContentRow.kt
package com.myapplication.views
import com.google.android.youtube.player.YouTubeInitializationResult
import com.google.android.youtube.player.YouTubePlayer
import com.myapplication.R
import com.xwray.groupie.GroupieViewHolder
import com.xwray.groupie.Item
import kotlinx.android.synthetic.main.row_video_content.view.*
class VideoContentRow(val videoID : String) : Item<GroupieViewHolder>() {
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
viewHolder.itemView.youtube_player_row_video_content.initialize("myKey", object: YouTubePlayer.OnInitializedListener {
override fun onInitializationSuccess(
provider: YouTubePlayer.Provider?,
player: YouTubePlayer?,
wasRestored: Boolean
) {
if (!wasRestored) {
player?.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT)
player?.cueVideo(videoID);
}
}
override fun onInitializationFailure(
p0: YouTubePlayer.Provider?,
p1: YouTubeInitializationResult?
) {
}
})
}
override fun getLayout(): Int {
return R.layout.row_video_content
}
}
row_video_content. xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content"
android:background="@android:color/white"
tools:context=".views.VideoContentRow">
<com.google.android.youtube.player.YouTubePlayerView
android:id="@+id/youtube_player_row_video_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>