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

4

16

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 ?

Cabanatuan answered 22/7, 2015 at 17:34 Comment(0)
P
25

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"/>
Pic answered 23/7, 2015 at 21:50 Comment(2)
But then the method is setSupportActionBar(toolbar); gives an error as it can not be called if your activity is not extending from AppCompatActivity. What to do if the toolbar is necessary?Inge
@Pic My QuestionLink is: https://mcmap.net/q/749087/-android-error-inflating-class-fragment-while-using-youtubeplayersupportfragment/5059725 I have still Error inflating class fragment, with other error Binary XML file line #15: Duplicate id 0x7f1001d0, tag null, or parent id 0x7f1001cf with another fragment for com.google.android.youtube.player.YouTubePlayerSupportFragmentShankle
O
2

In your java file MainActivity.java try to replace public class MainActivity extends AppCompatActivity with public class MainActivity extends YouTubeBaseActivity.

Orford answered 8/2, 2019 at 6:31 Comment(0)
I
1

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.

Indignity answered 23/8, 2016 at 10:38 Comment(0)
H
0

If you do not want to use fragment in your layout, another solution that you can use is extends your activity from YouTubeBaseActivity() . This will allow you use <com.google.android.youtube.player.YouTubePlayerView/> inside your layout

Example:

class PlayVideoActivity : YouTubeBaseActivity(), YouTubePlayer.OnInitializedListener {...}
Hectare answered 31/10, 2018 at 0:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.