android - close fullscreen of Youtube Player on back button inside fragment -
i using master/detail layout in tablet, on left few buttons open several fragments, 1 of fragments contains youtube player.
the problem,
when youtube player full screen, , press button, activity onbackpressed
called, , whole activity closed.
what have tried,
1- added on keylistener parent fragment (which contains youtube fragment) , handle when click on button, listener called if player not fullscreen, otherwise not called,
rootview.setfocusableintouchmode(true); rootview.requestfocus(); rootview.setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { if (keycode == keyevent.keycode_back && event.getaction() == keyevent.action_up) { try { // close full screen return true; } catch (exception e) { ahhexceptionhandler.handleexception(e); } } return false; } });
2- added onkeylistener youtubefragment view check if full screen close full screen mode
youtubefragment.getview().setfocusableintouchmode(true); youtubefragment.getview().requestfocus(); youtubefragment.getview().setonkeylistener(new view.onkeylistener() { @override public boolean onkey(view v, int keycode, keyevent event) { if (keycode == keyevent.keycode_back && event.getaction() == keyevent.action_up) { try { youtubeplayer.setfullscreen(false); return true; } catch (exception e) { ahhexceptionhandler.handleexception(e); } } return false; } });
and not called in cases.
i need handle hardware button while youtube player in fullscreen, fullscreen mode closed , application in previous state.
thanks.
edit 1: - want handle inside fragment, instead of handling in parent activity, handling inside parent activity, don't solution.
you can overwrite onbackpressed() in activity , in case player fullscreen can handle here , call not super.onbackpressed().
if it's not fullscreen call super.onbackpressed().
Comments
Post a Comment