Idea: Define a surfaceview to display a preview, launch a preview with the camera object in the Surfaceholder callback, and then call Mediarecorder to record it. Just realize the simple recording start and stop function, the top can display the time of recording, still need to be perfected.The code is as follows:Add the following permissions in Androidmanifest.xml:activity_main.xml mainactivity.java Package Com.jackie.videorecorder;import Java.io.fi
You can use viewview or surfaceview or videoview to play a video,
Code As follows:
Define a Android: layout_height = "240px"/>
Java code:
Videoview. setvideouri (URI. parse ("file: // sdcard/test.3gp "));Videoview. setmediacontroller (New mediacontroller (this ));Videoview. Start ();
Although videoview can easily play a video, the playback position and playback size are not controlled. Therefore, you need to use surfaceview to play the video. The Code is as follows:
Surfaceview = (s
PackageCom.zimo.guo.customcamera.view;ImportAndroid.content.Context;ImportAndroid.content.pm.PackageManager;ImportAndroid.graphics.ImageFormat;ImportAndroid.hardware.Camera;ImportAndroid.os.Environment;ImportAndroid.util.AttributeSet;ImportAndroid.view.SurfaceHolder;ImportAndroid.view.SurfaceView;ImportJava.io.File;ImportJava.io.FileNotFoundException;ImportJava.io.FileOutputStream;ImportJava.io.IOException;/** * Created by Zimo on 15/12/27. * * Public class cameraview extends surfaceview imple
camera control class, the source code is as follows:
Package Com.testcamera;
Import java.io.IOException;
Import Android.graphics.PixelFormat;
Import Android.hardware.Camera;
Import Android.util.Log;
Import Android.view.SurfaceHolder;
public class Sfhcamera implements surfaceholder.callback{private Surfaceholder holder = null;
Private Camera Mcamera;
private int width,height;
Private Camera.previewcallback Previewcallback;
Public Sfhcamer
;When the game starts:The floor gives a feeling of wanting to move to the left;The pipe moves at the same speed as the floor to the left;Bird default drop;When the user touches the screen, the bird rises a distance and drops;It is necessary to determine the position relationship between the pipe and the bird, whether the contact is touching or not, and the score needs to be calculated.Well, that's about it, so let's start thinking about drawing first ~ ~ ~3, the general wording of SurfaceviewNex
MediaPlayer to play video is as follows:Create a MediaPlayer object and let it load the specified video fileDefine the Surfaceview component in the interface layout file, or create the Surfaceview component in the program, and add Surfaceholder listeners for the callback of Surfaceview SurfaceviewCall the MediaPlayer object's Setpisplay (Surfaceholder sh): Outputs the video image that is played to the spec
amount of resources, so it is only used to play background music.
Vi. 2D image processing
1. Attach Images
AssetManager assetManager = context. getAssets ();
InputStream inputStream = assetManager. open ("bob.png ");
Bitmap bitmap = BitmapFactory. decodeStream (inputStream );
InputStream. close ();
2. Draw
Canvas. drawBitmap (Bitmap bitmap, float topLeftX, float topLeftY, painting );
Or Canvas. drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint );
2. Release image resourc
Use the interfaces provided by the android SDK to develop the simplest video playback demo.Next, paste the source code of main. xml:[Html]Xmlns: tools = "http://schemas.android.com/tools"Android: layout_width = "match_parent"Android: layout_height = "match_parent">Android: id = "@ + id/surfaceView1"Android: layout_width = "wrap_content"Android: layout_height = "360dp"Android: layout_alignParentLeft = "true"Android: layout_alignParentRight = "true"Android: layout_alignParentTop = "true"/>
Next, p
technology: There are two canvases in memory, a canvas is displayed to the screen, and the B canvas draws the next frame in memory. After drawing is finished, B is displayed to the screen, a continues to draw the next frame in memory.
Play video is also used MediaPlayer. Just unlike audio, to set which surfaceview to display inSurfaceView sv = (SurfaceView) findViewById(R.id.sv);SurfaceHolder sh = sv.getHolder();MediaPlayer player = new MediaPlayer
Method: Create (context, Uri URI)Explanation: The static method creates a multimedia player through Uri.
Method: Create (context, int resid)Explanation: The static method creates a multimedia player using the resource ID.
Method: Create (context, Uri, surfaceholder holder)Explanation: The static method creates a multimedia player through Uri and the specified surfaceholder [abstract class ].
Method: getcurr
Most Android controls inherit from the view type. Therefore, they generally inherit the View class when using custom controls. However, for highly efficient, game-level graphics, or players, the common view class isThe surfaceview class is required at this time. Because it is relatively advanced, it is recommended to install B. Simply inheriting from the surfaceview class is not acceptable, and a surfaceholder must be implemented. callback interface i
Android mediaplayer common methodsMethod: Create (context, Uri URI)Explanation: The static method creates a multimedia player through Uri.Method: Create (context, int resid)Explanation: The static method creates a multimedia player using the resource ID.Method: Create (context, Uri, surfaceholder holder)Explanation: The static method creates a multimedia player through Uri and the specified surfaceholder [a
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.