android - Web View Fragment html embeed video fullscreen suport -
hello got question regarding how enable full screen support in html embed videos on webview have hardware accelerated true on manifest , video works ok wen pressed go fullscreen video stops.
here code
import com.photoshop.video.tutorials.r; import android.annotation.suppresslint; import android.os.bundle; import android.support.v4.app.fragment; import android.text.textutils; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.webkit.webchromeclient; import android.webkit.webview; import android.webkit.webviewclient; import android.widget.progressbar; public class webviewfragment extends fragment { public final static string tag = webviewfragment.class.getsimplename(); private webview viewcontentwebview; private string url; private boolean resethistory = true; @suppresslint("setjavascriptenabled") @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { final view v = inflater.inflate(r.layout.webview, container, false); final progressbar viewcontentprogress = (progressbar) v.findviewbyid(r.id.progress); viewcontentwebview = (webview) v.findviewbyid(r.id.webview); viewcontentwebview.getsettings().setjavascriptenabled(true); viewcontentwebview.setwebviewclient(new webviewclient() { public void onreceivederror(webview view, int errorcode, string description, string failingurl) { viewcontentwebview.loadurl("file:///android_asset/myerrorpage.html"); } @override public boolean shouldoverrideurlloading(webview view, string url) { return super.shouldoverrideurlloading(view, url); } }); viewcontentwebview.setwebchromeclient(new webchromeclient() { @override public void onprogresschanged(webview view, int newprogress) { viewcontentprogress.setprogress(newprogress); viewcontentprogress.setvisibility(newprogress == 100 ? view.gone : view.visible); if (newprogress == 100 && resethistory) { viewcontentwebview.clearhistory(); resethistory = false; } } }); return v; } @override public void onviewcreated(view view, bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); reload(); } @override public void onhiddenchanged(boolean hidden) { super.onhiddenchanged(hidden); if (hidden) viewcontentwebview.stoploading(); else reload(); } public void seturl(string url) { this.url = url; if (viewcontentwebview != null) viewcontentwebview.stoploading(); resethistory = true; } public void reload() { if (textutils.isempty(url)) return; viewcontentwebview.loadurl(url); } public boolean onbackpressed() { if (viewcontentwebview.cangoback()) { viewcontentwebview.goback(); return true; } return false; } }
how can achieve many in advance , little patience me because very new android
you should override 2 following methods in webchromeclient:
public void onshowcustomview(view view, customviewcallback callback);
public void onhidecustomview();
this extract of code i'm using:
private view mcustomview; private class mywebchromeclient extends webchromeclient { private int moriginalorientation; private fullscreenholder mfullscreencontainer; private customviewcallback mcustomviewcollback; @override public void onshowcustomview(view view, customviewcallback callback) { if (mcustomview != null) { callback.oncustomviewhidden(); return; } moriginalorientation = mactivity.getrequestedorientation(); framelayout decor = (framelayout) mactivity.getwindow().getdecorview(); mfullscreencontainer = new fullscreenholder(mactivity); mfullscreencontainer.addview(view, viewgroup.layoutparams.match_parent); decor.addview(mfullscreencontainer, viewgroup.layoutparams.match_parent); mcustomview = view; mcustomviewcollback = callback; mactivity.setrequestedorientation(moriginalorientation); } @override public void onhidecustomview() { if (mcustomview == null) { return; } framelayout decor = (framelayout) mactivity.getwindow().getdecorview(); decor.removeview(mfullscreencontainer); mfullscreencontainer = null; mcustomview = null; mcustomviewcollback.oncustomviewhidden(); // show content view. mactivity.setrequestedorientation(moriginalorientation); } static class fullscreenholder extends framelayout { public fullscreenholder(context ctx) { super(ctx); setbackgroundcolor(ctx.getresources().getcolor(android.r.color.black)); } @override public boolean ontouchevent(motionevent evt) { return true; } }
Comments
Post a Comment