android - YouTube Player plays for 2 seconds and stop in full screen -
i'm facing 2 major problems,
i'm using youtube player , when gets on full screen, plays 1-2 seconds , stop.
when click "play" button in middle, it's buffering on again. if gray bar filled it's center.
those problems aren't occurring in portrait mode.
here class, youtube api demo bit defference
public class video extends youtubefailurerecoveryactivity implements youtubeplayer.onfullscreenlistener, utils.ongeturllistener, view.onclicklistener { static int auto_play_delay = 1000; static final int portrait_orientation = build.version.sdk_int < 9 ? activityinfo.screen_orientation_portrait : activityinfo.screen_orientation_sensor_portrait; private linearlayout mrootlayout; /** * * youtube *** */ youtubeplayerview mplayerview; youtubeplayer mplayer; boolean misfullscreen; string urlid; /** * * *** */ relativelayout mcontainer; imageview mbtplay; boolean misneedsetflags; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); utils.getinstance().setactivity(this); setcontentview(r.layout.video_main); misneedsetflags = true; mrootlayout = (linearlayout) findviewbyid(r.id.video_root_layout); mcontainer = (relativelayout) findviewbyid(r.id.container); mbtplay = (imageview) findviewbyid(r.id.video_play); mbtplay.setvisibility(view.invisible); mplayerview = (youtubeplayerview) findviewbyid(r.id.player); intent intent = getintent(); dolayout(); } @override public void oninitializationsuccess(youtubeplayer.provider provider, youtubeplayer player, boolean wasrestored) { mplayer = player; player.addfullscreencontrolflag(youtubeplayer.fullscreen_flag_custom_layout); player.setonfullscreenlistener(this); if (misneedsetflags) { misneedsetflags = false; int controlflags = player.getfullscreencontrolflags(); setrequestedorientation(portrait_orientation); controlflags |= youtubeplayer.fullscreen_flag_always_fullscreen_in_landscape; player.setfullscreencontrolflags(controlflags); } if (!wasrestored) { player.cuevideo(urlid); } } @override protected youtubeplayer.provider getyoutubeplayerprovider() { return mplayerview; } private void dolayout() { linearlayout.layoutparams playerparams = (linearlayout.layoutparams) mplayerview.getlayoutparams(); if (misfullscreen) { playerparams.width = linearlayout.layoutparams.match_parent; playerparams.height = linearlayout.layoutparams.match_parent; mparallaxscrollview.setvisibility(view.gone); } else { mparallaxscrollview.setvisibility(view.visible); if (getresources().getconfiguration().orientation != configuration.orientation_landscape) { viewgroup.layoutparams otherviewsparams = mparallaxscrollview.getlayoutparams(); playerparams.width = otherviewsparams.width = match_parent; playerparams.height = wrap_content; mrootlayout.setorientation(linearlayout.vertical); } } mplayerview.setlayoutparams(playerparams); } @override public void onfullscreen(boolean isfullscreen) { misfullscreen = isfullscreen; showplayerandplay(); dolayout(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); dolayout(); } @override public void ongeturlfinished(string videourl) { urlid = videourl; mbtplay.setvisibility(view.visible); mbtplay.setonclicklistener(this); mplayerview.initialize(utils.you_tube_dev_key, this); } @override public void onclick(view v) { switch (v.getid()) { case r.id.video_play: showplayerandplay(); break; } } private void showplayerandplay() { mplayerview.setvisibility(view.visible); mbtplay.setvisibility(view.invisible); if (!mplayer.isplaying()) new android.os.handler().postdelayed(new runnable() { @override public void run() { mplayer.play(); } }, auto_play_delay); } }
youtube not allow other views overlayed on top of player view.
if check logs, see warning message specifies limitation, plus more information on view (its id) , overlapping region.
Comments
Post a Comment