Android Camera video demo, androidcameraGoogle launched the Camera2 class in Android 5.0 to replace Camera. However, Camera2 requires the minimum android sdk version to be minSdkVersion = 21 (5.0 system), so Camera2 cannot completely replace Camera, when it is compatible with earlier versions, the two must be jointly developed. The following is an example of Camera shooting: First, you need to layout A SurfaceView in xml to set full screen
The status bar and titleBar are also hidden:
RequestWin
Collision is a very important part. Let me briefly introduce it. Circleactivity Code ; Package yy. circle; import android. app. activity; import android. OS. bundle; import android. view. view; import android. view. window; import android. view. windowmanager; public class circleactivity extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); this. requestwindowfeature (window. featur
SurfaceView is a classic in Android. It can implement all the functions required for two-dimensional animation. If you like animation, you can learn it in depth. Today we will start with this article, first understand the animation effect of SurfaceView.
1. A simple small example:
1) MySurfaceView. java
Package com. example. l0904_surfaceview;/*** use the combination of SurfaceView and Canvas to complete * simple animation effect */import java. util. timer; import java. util. timerTask; import
Method Stub super.onresume (); Surfaceview = (Surfaceview) Findviewbyid (R.ID.SV); Get the preview screen of the receiving class Surfaceholder Holder = Surfaceview.getholder (); The Receive class settings callback-->surface created when the camera starts previewing, and the data is closed//set when exiting to originate from the rendering engine, without using its own buffer. Holder.settype (surfaceholder.surface_type_push_
interface. SurfaceView is provided for applications that need to directly draw pixels rather than using form components. An important concept and clue in the Android graphics system is surface. View and its subclass, such as TextView and Button)
Draw the image on the surface. Creates a Canvas object for each surface, but its attributes change frequently. This object is used to manage the drawing operations of a view on the surface, such as drawing points and draw lines. Note that The hierarchy
empty Surfaceview or setting this preview to be transparent.But I have failed both of these approaches. And the user Sam gave the preview set to a 1x1 size scheme played a role. The following demo shows this scenario:The interface is very simple, a button to take pictures, the OnClick event method named Ontakephotoclicked. Public void ontakephotoclicked(View view) {FinalSurfaceview preview =NewSurfaceview ( This); Surfaceholder holder = Preview.getho
,onclicklistener{Private Surfaceholder Msurfaceholder =NullPrivate Surfaceview Msurfaceview =NullPrivate Camera Mcamera =Null@OverridePublicvoid OnCreate (Bundle savedinstancestate) {Super.oncreate (savedinstancestate); Setcontentview (R.layout.main);//Initialize component, Surfaceview Msurfaceview = (surfaceview) Findviewbyid (R.ID.SURFACEVIEW01);/*** Through the code, we obtained holder from Surfaceview and added callback function to "this". * This
This article is a custom video player that can be switched on screen (the computer is separated due to changes in size when changing the screen), such as:--------------Play Video Summary:2 Ways of Surfaceview+mediaplayer and VideoviewThere is a surfaceholder in the Surfaceview, which is obtained through the Surfaceview.getholder () method, plus settype if a compatible 2.3 system is required (surfaceholder.surface_type_ Push_buffers); otherwise only th
use the Mediacontroller class, but you need to implement Mediacontroller.mediacontroller interface * To implement some control methods. * * Then, set Controller.setmediaplayer (), Setanchorview (), setenabled (), show () on it, no longer implemented here * @author Administrator * */public class Videosurfacedemo extends Activity implements Oncompletionlistener,onerrorlistener,oninfolistener, Onpreparedlistener, Onseekcompletelistener,onvideosizechang edlistener,surfaceholder.callba
Layer, you can also use the Mediacontroller class, but you need to implement Mediacontroller.mediacontroller interface * To implement some control methods. * * Then, set Controller.setmediaplayer ()Anchorview (), setenabled (), show () on it, no longer implemented * @author Administrator * */public class Videosurfacedemo Extends Activity implements Oncompletionlistener,onerrorlistener,oninfolistener, Onpreparedlistener, Onseekcompl etelistener,onvideosizechangedlistener,surfacehol
= bytebuffer.allocate (buffersize); Boolean finished = false; Bufferinfo bufferinfo = new Bufferinfo (); Muxer.start ();while (!finished) {Getinputbuffer () would fill the inputbuffer with one frame of encodedSample from either Mediacodec or Mediaextractor, set Isaudiosample toTrue when the sample was audio data, set up all the fields of Bufferinfo,and return True if there is no more samples.Finished = Getinputbuffer (InputBuffer, Isaudiosample, Bufferinfo);if (!finished) {int currenttrackind
. */public class Camerafragment extends Fragment {public static final int request_camera_code = 100; public static final String package = "Package:"; Private static final Sparseintarray orientations = new Sparseintarray (); To make the photo appear vertically static {Orientations.append (SURFACE.ROTATION_0, 90); Orientations.append (surface.rotation_90, 0); Orientations.append (surface.rotation_180, 270); Orientations.append (surface.rotation_270, 180); } priv
); Canvas.drawbitmap (BG, New Rect (0,0,bg.getwidth (), Bg.getheight ()), New Rect (0,height, display_w,display_h+height), p); Canvas.drawbitmap (BG, new Rect (0,0,bg.getwidTh (), Bg.getheight ()), New Rect (0,-display_h+height,display_w,height), p); height++; if (height==display_h) {height=0; } return Newbitmap; } public int GetX () {return 0; } public int GetY () {return 0; }} private Boolean state = false; Private
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.