android - YouTube api: Not connected. Call connect() and wait for onConnected() to be called -


i using youtubefragment in android app , getting following crash on android 4+ devices.

java.lang.illegalstateexception: not connected. call connect() , wait onconnected() called. @ com.google.android.youtube.player.a.at.i(unknown source) @ com.google.android.youtube.player.a.an.k(unknown source) @ com.google.android.youtube.player.a.an.a(unknown source) @ com.google.android.youtube.player.a.ao.<init>(unknown source) @ com.google.android.youtube.player.a.f.a(unknown source) @ com.google.android.youtube.player.q.a(unknown source) @ com.google.android.youtube.player.a.at.g(unknown source) @ com.google.android.youtube.player.a.ax.a(unknown source) @ com.google.android.youtube.player.a.aw.a(unknown source) @ com.google.android.youtube.player.a.av.handlemessage(unknown source) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5450) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:525) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1187) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1003) @ dalvik.system.nativestart.main(native method) 

the fragment being started this:

 xyoutubefragment yfragment = xyoutubefragment.newinstance(ytvideoid);  activity.commitfragment(yfragment); 

and defined this:

public class xyoutubefragment extends youtubeplayersupportfragment {      public static xyoutubefragment newinstance(string url) {         xyoutubefragment youtubefrag = new xyoutubefragment();         bundle bundle = new bundle();         bundle.putstring("url", url);         youtubefrag.setarguments(bundle);         youtubefrag.init();         return youtubefrag;     }      private void init() {          initialize(constants.youtube_api_key, new oninitializedlistener() {              @override             public void oninitializationfailure(provider arg0, youtubeinitializationresult arg1) { }              @override             public void oninitializationsuccess(youtubeplayer.provider provider, youtubeplayer player, boolean wasrestored) {                 player.setplayerstyle(youtubeplayer.playerstyle.default);                 if (!wasrestored) {                     player.loadvideo(getarguments().getstring("url"), 0);                 }             }         });     }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);          mainactivity activity = (mainactivity) getactivity();         activity.getsupportactionbar().hide();         activity.findviewbyid(r.id.alert_list).setvisibility(view.gone);     } } 

any idea wrong?

public class youtubemanager implements youtubeplayer.oninitializedlistener {           string videotitle;         string videoidloaded;         boolean videotitleenabled;         boolean ispreloaded;          public void loadvideowithid(string videoid) {          }      public static final string default_api_key = "your api key";     string appkey;     string searchkey;     string videoid_local;     string userid_local;     boolean firstrun;      activity mactivity;     youtubeplayer myoutubeplayer;     private youtubefragment youtubeplayerfragment;     private myplayerstatechangelistener myplayerstatechangelistener;     private myplaybackeventlistener myplaybackeventlistener;      public youtubemanager(activity activity, string key, int containerid, int windowwidth, int windowheight) {         mactivity = activity;         appkey = key;         searchkey = null;         videoid_local = null;         userid_local = null;         firstrun = true;         offsettime = 0d;         myplayerstatechangelistener = new myplayerstatechangelistener();         myplaybackeventlistener = new myplaybackeventlistener();         fragmentmanager fragmentmanager = activity.getfragmentmanager();         fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction();         youtubeplayerfragment = new youtubefragment();         viewgroup.marginlayoutparams params =                 new viewgroup.marginlayoutparams(windowwidth / 2,                         windowheight / 2);         params.setmargins(0, 0, 0, 0);         youtubeplayerfragment.setlayoutparams(params);         fragmenttransaction.add(containerid, youtubeplayerfragment);         fragmenttransaction.commit();         youtubeplayerfragment.initialize(key, this);     }      public void oninitializationsuccess(youtubeplayer.provider provider, youtubeplayer player,                                         boolean wasrestored) {         myoutubeplayer = player;         myoutubeplayer.setplayerstatechangelistener(myplayerstatechangelistener);         myoutubeplayer.setplaybackeventlistener(myplaybackeventlistener);         if (!wasrestored) {             myoutubeplayer.cuevideo("ncgqdjiotg0");         } else {             //test of video playback             myoutubeplayer.cuevideo("ncgqdjiotg0");             play(null);         }     }      public void oninitializationfailure(youtubeplayer.provider provider,                                         youtubeinitializationresult errorreason) {         if (errorreason.isuserrecoverableerror()) {             //errorreason.geterrordialog(this, recovery_dialog_request).show();         } else {             //string errormessage = string.format(getstring(r.string.error_player), errorreason.tostring());             //toast.maketext(this, errormessage, toast.length_long).show();         }     }      public void loadvideowithid(string videotoload) {         videoid_local = videotoload;         myoutubeplayer.cuevideo(videoid_local);     }      //users     public string getlocaluserid() {         return videoid_local;     }      ;      public void adduser(string userid) {      }      ;      public void removeuser(string userid) {      }      public void removeallusers() {      }      //external playback     public void play(string userid) {         myoutubeplayer.play();     }      public void pause(string userid) {         myoutubeplayer.pause();     }      public void stop(string userid) {      }      public void close(string userid) {      }      private final class myplayerstatechangelistener implements playerstatechangelistener {          @override         public void onadstarted() {             log.info("youtube", "onadstarted()");         }          @override         public void onerror(                 com.google.android.youtube.player.youtubeplayer.errorreason arg0) {             log.info("youtube", "onerror(): " + arg0.tostring());         }          @override         public void onloaded(string arg0) {             log.info("youtube", "onloaded(): " + arg0);         }          @override         public void onloading() {             log.info("youtube", "onloading()");         }          @override         public void onvideoended() {             log.info("youtube", "onvideoended()");         }          @override         public void onvideostarted() {             log.info("youtube", "onvideostarted()");         }      }      private final class myplaybackeventlistener implements playbackeventlistener {          @override         public void onbuffering(boolean arg0) {             log.info("youtube", "onbuffering(): " + string.valueof(arg0));         }          @override         public void onpaused() {          }          @override         public void onplaying() {          }          @override         public void onseekto(int arg0) {          }          @override         public void onstopped() {          }      } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -