Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

java.lang.IllegalStateException: YouTubeServiceEntity not initialized error when using YouTubePlayerApi

$
0
0

I'm using YouTubePlayerAPI and YouTubePlayerSupportFragment in my app and I'm getting the following error, but I couldn't find out what is causing it. I've been looking for information but I haven't found anything useful.

java.lang.IllegalStateException: YouTubeServiceEntity not initialized    at android.os.Parcel.readException(Parcel.java:1433)    at android.os.Parcel.readException(Parcel.java:1379)    at com.google.android.youtube.player.internal.l$a$a.a(Unknown Source)    at com.google.android.youtube.player.internal.o.a(Unknown Source)    at com.google.android.youtube.player.internal.ad.a(Unknown Source)    at com.google.android.youtube.player.YouTubePlayerView.a(Unknown Source)    at com.google.android.youtube.player.YouTubePlayerView$1.a(Unknown Source)    at com.google.android.youtube.player.internal.r.g(Unknown Source)    at com.google.android.youtube.player.internal.r$c.a(Unknown Source)    at com.google.android.youtube.player.internal.r$b.a(Unknown Source)    at com.google.android.youtube.player.internal.r$a.handleMessage(Unknown Source)    at android.os.Handler.dispatchMessage(Handler.java:99)    at android.os.Looper.loop(Looper.java:137)    at android.app.ActivityThread.main(ActivityThread.java:5041)    at java.lang.reflect.Method.invokeNative(Native Method)    at java.lang.reflect.Method.invoke(Method.java:511)    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)    at dalvik.system.NativeStart.main(Native Method)

In the stackstrace there isn't any line number pointing to any of my classes or activities.

Any idea of it?

Thanks!

EDIT

My custom YoutubePlayerFragment Class: YouTubeVideoPlayerFragment.java

public class YouTubeVideoPlayerFragment extends YouTubePlayerSupportFragment {private static final String ARG_URL = "url";// ===========================================================// Constructors// ===========================================================/** * Mandatory empty constructor for the fragment manager to instantiate the * fragment (e.g. upon screen orientation changes). */public YouTubeVideoPlayerFragment() {}/** * Factory method to generate a new instance of the fragment given a video URL. * * @param url The video url this fragment represents * @return A new instance of this fragment with itemId extras */public static YouTubeVideoPlayerFragment newInstance(String url) {    final YouTubeVideoPlayerFragment mFragment = new YouTubeVideoPlayerFragment();    // Set up extras    final Bundle args = new Bundle();    args.putString(ARG_URL, url);    mFragment.setArguments(args);    // Initialize YouTubePlayer    mFragment.init();    return mFragment;}@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);}private void init(){    initialize(Constants.API_KEY, new YouTubePlayer.OnInitializedListener() {        @Override        public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {            if (!wasRestored) {                youTubePlayer.cueVideo(getArguments().getString(ARG_URL));                youTubePlayer.setShowFullscreenButton(false);            }    }}

fragment.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout    android:layout_height="match_parent"    android:layout_width="match_parent"    android:background="@color/black"><!-- For YoutubeFragment --><FrameLayout        android:id="@+id/youtube_fragment"        android:layout_width="match_parent"        android:layout_height="match_parent" /></RelativeLayout>

calling method:

// Create a new instance of YouTubeVideoPlayerFragment providing video id        // and place it in the corresponding FrameLayout        final YouTubeVideoPlayerFragment youTubeVideoPlayerFragment = YouTubeVideoPlayerFragment.newInstance(VIDEO_ID);        final FragmentTransaction ft = getChildFragmentManager().beginTransaction();        ft.replace(R.id.youtube_fragment, youTubeVideoPlayerFragment);        ft.commit();

EDIT

I've found out the origin of that error. This is the scenario:

The activity starts. In onCreate() it instantiates a new YouTubeVideoPlayerFragment and initializes YouTube object (which starts the YouTubeServiceEntity internally) in its newInstance() method. Then the YouTube fragment that was instantiated before, is attached with FragmentManager to the corresponding FrameLayout while video is loading.

Here is the issue: If user exits the activity before video had been loaded, the exception is thrown.

So if user want to exit from the activity in that case, what should I do and how? I don't really know what to do!


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>