Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error inflating class com.google.android.youtube.player.YouTubePlayerView In List Adapter

I am trying to inflate

<com.google.android.youtube.player.YouTubePlayerView
                android:id="@+id/youtubeplayerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp" />

in List adapter so that I can play video in the listview it self but I am getting error

Error inflating class com.google.android.youtube.player.YouTubePlayerView

while if I am using

<com.google.android.youtube.player.YouTubeThumbnailView
                android:id="@+id/youtubeplayerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="5dp" />

It is getting inflated without any error and I am able to display thumbnail in list view

My requirement is when user click on this thumbnail video should play in list view

Please suggest how can I achieve this ?

like image 802
Naga Avatar asked Jul 22 '15 17:07

Naga


2 Answers

From the documentation:

Using this View directly is an alternative to using the YouTubePlayerFragment. If you choose to use this view directly, your activity needs to extend YouTubeBaseActivity.

Therefore, you must make sure your activity extends YouTubeBaseActivity. Alternatively, if your activity does not need to extend an activity provided by the library, you can use the YouTubePlayerSupportFragment and FrameActivity from android.support.v4.

<fragment
  android:name="com.google.android.youtube.player.YouTubePlayerSupportFragment"
  android:id="@+id/youtubesupportfragment"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>
like image 109
not_a_bot Avatar answered Sep 19 '22 14:09

not_a_bot


In addition to not_a_bot's answer, I'd like to add that you should make sure that you call super.onCreate(Bundle) method, as it seems that YouTubeBaseActivity class doesn't have the @CallSuper annotation.

like image 32
Dragas Avatar answered Sep 16 '22 14:09

Dragas