android - How to make VideoView full screen -


i want play video in activity using videoview,and make fullscreen , landscape mode (with hiding virtual button , status bar)when click button.

but can not hide virtual button , has white line in bottom. my app

this activity code:

public class videoactivity extends activity { private videoview mvideoview; private string murl; private button mfullscreen; private static string tag = videoactivity.class.getname(); @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     log.d(tag,"oncreate");     setcontentview(r.layout.video);     mvideoview = (videoview) findviewbyid(r.id.video);     mfullscreen = (button) findviewbyid(r.id.fullscreen);     file file = new file(environment.getexternalstoragedirectory(),"video.mp4");     mvideoview.setvideopath(file.getpath());     mvideoview.start();     mfullscreen.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             enterfullscreen();             mfullscreen.setvisibility(view.gone);         }     });  }  @override protected void ondestroy() {     super.ondestroy();     log.d(tag,"ondestroy"); }  private void enterfullscreen(){     getwindow().setflags(windowmanager.layoutparams.flag_fullscreen,windowmanager.layoutparams.flag_fullscreen);//设置全屏     this.setrequestedorientation(activityinfo.screen_orientation_landscape);//设置横屏     getwindow().setflags(windowmanager.layoutparams.flag_keep_screen_on,windowmanager.layoutparams.flag_keep_screen_on);//常亮     relativelayout.layoutparams layoutparams = new relativelayout.layoutparams(       relativelayout.layoutparams.match_parent,       relativelayout.layoutparams.match_parent     );     layoutparams.addrule(relativelayout.align_parent_bottom);     layoutparams.addrule(relativelayout.align_parent_top);     layoutparams.addrule(relativelayout.align_parent_left);     layoutparams.addrule(relativelayout.align_parent_right);   } } 

video.xml

 <?xml version="1.0" encoding="utf-8"?>     <relativelayout         xmlns:android="http://schemas.android.com/apk/res/android"         android:orientation="vertical"     android:layout_width="match_parent"     android:layout_height="match_parent">     <videoview         android:id="@+id/video"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:padding="0dp"/>     <button         android:id="@+id/fullscreen"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:visibility="visible"         android:text="fullscreen"/> </relativelayout> 

try on landscape mode.

<videoview android:id="@+id/video"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"    android:layout_alignparentright="true"    android:layout_alignparentbottom="true"    android:layout_alignparenttop="true"     /> 

hide virtual buttons add code:

getwindow().getdecorview().setsystemuivisibility(view.system_ui_flag_hide_navigation); 

original size

         displaymetrics metrics = new displaymetrics();  getwindowmanager().getdefaultdisplay().getmetrics(metrics);          android.widget.linearlayout.layoutparams params = (android.widget.linearlayout.layoutparams) videoview.getlayoutparams();          params.width =  (int) (300*metrics.density);          params.height = (int) (250*metrics.density);          params.leftmargin = 30;          videoview.setlayoutparams(params); 

full screen size

         displaymetrics metrics = new displaymetrics(); getwindowmanager().getdefaultdisplay().getmetrics(metrics);          android.widget.linearlayout.layoutparams params = (android.widget.linearlayout.layoutparams) videoview.getlayoutparams();          params.width =  metrics.widthpixels;          params.height = metrics.heightpixels;          params.leftmargin = 0;          videoview.setlayoutparams(params); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -