android - Placing TextureView inside FrameLayout -
i inherited code of recording app. preview of camera uses half of screen, , can used in landscape mode. user records himself, , play video recorded (again, using half of screen, in landscape).
this layout of recording:
<framelayout android:layout_weight="1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toendof="@+id/textview" android:layout_above="@+id/framelayout" android:layout_alignparenttop="true" android:id="@+id/framelayout3" android:background="@color/negro"> <framelayout android:id="@+id/videoresultlayout" android:layout_width="match_parent" android:background="@android:color/black" android:layout_height="match_parent" /> </framelayout>
in videoresultlayout preview of camera goes.
and layout of playing activity:
<framelayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparenttop="true" android:layout_toendof="@+id/textview2" android:background="@android:color/black" android:layout_above="@+id/framelayout2" android:id="@+id/videoresultlayout"> <textureview android:id="@+id/videoresult" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="fill_horizontal"/> </framelayout>
in activities, there resizing, recording activity:
private void resizepreview() { camera.size size = fdcamera.getpreviewsize(); // landscape float ratio = (float)size.width/size.height; int new_width=0, new_height=0; if(videoresultlayout.getwidth()/ videoresultlayout.getheight()<ratio){ new_width = math.round(videoresultlayout.getheight()*ratio); new_height = videoresultlayout.getheight(); //new_width = videoresultlayout.getwidth(); //new_height = math.round(videoresultlayout.getwidth()/ratio); }else{ new_width = videoresultlayout.getwidth(); new_height = math.round(videoresultlayout.getwidth()/ratio); } videoresultlayout.setlayoutparams(new framelayout.layoutparams(new_width, new_height)); //videoresultlayout.setscalex(-1); fdcamera.startcamera(); }
and play activity:
private void setvideosize() { // // dimensions of video int videowidth = mplayer.getvideowidth(); int videoheight = mplayer.getvideoheight(); float videoproportion = (float) videowidth / (float) videoheight; // width of screen int screenwidth = getwindowmanager().getdefaultdisplay().getwidth(); int screenheight = getwindowmanager().getdefaultdisplay().getheight(); float screenproportion = (float) screenwidth / (float) screenheight; // surfaceview layout parameters final android.view.viewgroup.layoutparams lp = videoresult.getlayoutparams(); if (videoproportion > screenproportion) { lp.width = screenwidth; lp.height = (int) ((float) screenwidth / videoproportion); } else { lp.width = (int) (videoproportion * (float) screenheight); lp.height = screenheight; } // commit layout parameters runonuithread(new runnable() { @override public void run() { videoresult.setlayoutparams(lp); boolean isfrontcamera=prefs.getboolean("isfrontcamera", true); if(isfrontcamera){ videoresult.setscalex(-1); } } }); }
this way, see effect of "zoom in" when playing video, , little misplace of user (i mean, if user places himself in right of screen while recording, when playing bit @ center. how avoid effects , "what see get"?
thank you.
Comments
Post a Comment