<FrameLayout anroid: layout_weight = "1">
<ImageView android: scaleType = "fitCenter"/>
// No title bar
RequestWindowFeature (Window. FEATURE_NO_TITLE );
// Full screen display (hide the status bar)
// Call getWindow (). addFlages (WindowManager. LayoutParams. FLAG_FULLSCREEN) before setContentView );
Androied-programming UI/layout Switching
LinearLayout linearLayout = new LinearLayout (this );
LayoutParams = new LinearLayout. LayoutParams (ViewGroup. LayoutParams. FILL_PARENT, ViewGroup. LayoutParams. FILL_PARENT ){
TextView = new TextView (this );
TextView. setText (R. string. hello );
TextView. setId (34 );
LinearLayout. LayoutParams textParams = new LinearLayout. LayoutParams (
ViewGroup. LayoutParams. FILL_PARENT, ViewGroup. LayoutParams. WRAP_CONTENT );
LinearLayout. addView (textView, textParams );
SetContentView (linearLayout, layoutParams );
}
Android-multimedia (recording)
<Uses-permission android: name = "android. permission. RECORD_AUDIO"/>
MediaRecorder recorder = new MediaRecorder ();
// Collect sound from the microphone
Recorder. setAudioSource (MediaRecorder. AudioSource. MIC );
// Content output format
Recorder. setOutputFormat (MediaRecorder. OutputFormat. THREE_GPP)
Recorder. setAudioEncoder (MediaRecorder. AudioEncoder. AMR_NB); // Audio Encoding Method
Recorder. setOutputFile ("/mnt/sdcard/itcast. amr ");
Recorder. prepare (); // expected preparation
Recorder. start (); // starts to burn
...
Recorder. stop (); stop burning
Recorder. reset (); // reset
Recorder. release (); // resources must be released after the data is burned.
Android-multimedia (audio player)
MediaPlayer mediaPlayer = new MediaPlayer ();
MediaPlayer. setDataSource ("/mnt/sdcard/god.mp3 ");
MediaPlayer. prepare ();
MediaPlayer. start (); // starts or resumes playback.
MediaPlayer. pause (); // pause playback
MediaPlayer. stop (); // stop playing
MediaPlayer. release (); // release resources
// Playback error event
MediaPlayer. setOnErrorListener (new MediaPlayer. OnErrorListener (){
Public Boolean onError (MediaPlayer player, int arg1, int arg2 ){
MediaPlayer. release ();
Return false;
}
});
Multimedia (Audio/Video Player)
Add the SurfaceView Control for video screen painting in the main. xml layout file.
<SurfaceView...>
SurfaceView. getHolder (). setFixedSize (176.144); // sets the resolution.
// Set the Surface below not to maintain its own buffer, but to wait for the screen rendering engine content to be pushed to the user
SurfaceView. getHolder (). setType (SurfaceHolder. SURFACE_TYPE_PUSH_BUFFERS );
// When a new Activity is opened, SurfaceView is destroyed. When the new Activity is closed, the current Activity returns to the foreground, and SurfaceView is re-created after onResume. Therefore, the callback is complete.
SvVedio. getHolder (). addCallback (new CallbackImpl ())
MediaPlayer mediaPlayer = new MediaPlayer ();
MediaPlayer. reset (); // reset to initial state
MediaPlayer. setDisplay (surfaceView. getHolder ());
MediaPlayer. setDataSource ("/mnt/sdcard/oppo.mp4 ");
MediaPlayer. prepare | start (); | pause | stop | release ();
Note: If the audio/video playback system has a problem with simulator 2.2, You need to port it to the 2.0 platform.
Android-multimedia (CAMERA)
SurfaceView. getHolder (). setFixedSize (176,144); // sets the resolution.
SurfaceView. getHolder (). setType (SurfaceHolder. SURFACE_TYPE_PUSH_BUFFERS );
SurfaceView. getHolder (). addCallback (); // callback
WindowManager wm = getSystemService (Context. WINDOW_SERVICE); // Window Manager
Display display = wm. getDefaultDisplay ();//
Camera camera = Camera. open (); // open the Camera
Camera. Parameters parameters = camera. getParameters ();
Parameters. setPreviewSize (display. getWidth (), display. getHeight (); // size
Parameters. setPreviewFrameRate (3); // 3 frames per second
Parameters. setPictureFormat (PixelFormat. JPEG); // you can specify the photo output format.
Parameters. set ("jpeg-quality", 85); // photo quality
Parameters. setPictureSize (display. getWidth (), display. getHeight ());
Camera. setParameters (parameters );
The photo needs to complete the camera settings and start previewing in the surfaceView. holder callback, because it must be available only after the holder is ready, and the truth is the same as that of the player.
StartPreview cannot be called after takePicture because it is asynchronous. You need to start previewing in the picCall callback.
Camera
// Display the screenshot through SurfaceView
Camera. setPrevieDisplay (surfaceView. getHolder)
Camera. startPrevice (); // start previewing
Camera. autoFocus (null); // auto focus
Camera. takePicture (null, callback); // take a photo
Camera. stopPrevice (); // stop previewing
Camera. release (); // release the camera.
OnKeyDown:
Public Boolean onKeyDown (int keyCode, keyEvent event ){
If (camera! = Null & event. getRepeatCount () = 0 ){
Case KeyEvent. KEYCODE_SEARCH:
}
PictureCallback:
Bitmap bmp = BitmapFactory. decodeByteArray (data, 0, data. length );
File jpg = new File(Environment.getExternalStorageDirectory(),”1.jpg ");
FileOutputStream fos = new FileOutputStream (jpg );
Bmp. compress (Bitmap. CompressFormat. JPEG, 100, fos );
Fos. close ();
Camera. startPreview ();
}
Simulate a photo with Intent
If no camera hardware is available, you can use the built-in provider to implement the camera function (this function is not supported by Simulators of 2.2)
Intent intent = new Intent (android. provider. MediaStore. ACTION_IMAGE_CAPTURE );
// Specify the output file
// OutputFileUri specifies the address where the photo is stored. If yes, It stores all-size and large photos; otherwise, a bitmap is returned.
// Receive in the onActivityResult Method
Intent. putExtra (mediaStore. EXTRA_OUTPUT, outputFileUri );
StartActivityForResult (intent, 0 );
BitmapFactory. Options options = new BitmapFactory. Options ();
Options. inSampleSize = 1;
Bitmap bitmap = BitmapFactory. decodeFile (_ path, options );
_ Image. setImageBitmap (bitmap );
<! -The following permissions are required: ---> www.2cto.com
<Uses-permission android: name = "android. permission. CAMERA"/>
<Uses-feature android: name = "android. hardware. camera"/>
<Uses-feature android: name = "android. hardware. camera. autofocus"/>
Author: to1297488504