Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is another example which is working</p> <pre><code>public class EnregistrementVideoStackActivity extends Activity implements SurfaceHolder.Callback { private SurfaceHolder surfaceHolder; private SurfaceView surfaceView; public MediaRecorder mrec = new MediaRecorder(); private Button startRecording = null; File video; private Camera mCamera; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera_surface); Log.i(null , "Video starting"); startRecording = (Button)findViewById(R.id.buttonstart); mCamera = Camera.open(); surfaceView = (SurfaceView) findViewById(R.id.surface_camera); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, 0, 0, "StartRecording"); menu.add(0, 1, 0, "StopRecording"); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 0: try { startRecording(); } catch (Exception e) { String message = e.getMessage(); Log.i(null, "Problem Start"+message); mrec.release(); } break; case 1: //GoToAllNotes mrec.stop(); mrec.release(); mrec = null; break; default: break; } return super.onOptionsItemSelected(item); } protected void startRecording() throws IOException { mrec = new MediaRecorder(); // Works well mCamera.unlock(); mrec.setCamera(mCamera); mrec.setPreviewDisplay(surfaceHolder.getSurface()); mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA); mrec.setAudioSource(MediaRecorder.AudioSource.MIC); mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); mrec.setPreviewDisplay(surfaceHolder.getSurface()); mrec.setOutputFile("/sdcard/zzzz.3gp"); mrec.prepare(); mrec.start(); } protected void stopRecording() { mrec.stop(); mrec.release(); mCamera.release(); } private void releaseMediaRecorder(){ if (mrec != null) { mrec.reset(); // clear recorder configuration mrec.release(); // release the recorder object mrec = null; mCamera.lock(); // lock camera for later use } } private void releaseCamera(){ if (mCamera != null){ mCamera.release(); // release the camera for other applications mCamera = null; } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @Override public void surfaceCreated(SurfaceHolder holder) { if (mCamera != null){ Parameters params = mCamera.getParameters(); mCamera.setParameters(params); } else { Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show(); finish(); } } @Override public void surfaceDestroyed(SurfaceHolder holder) { mCamera.stopPreview(); mCamera.release(); } } </code></pre> <p>camera_surface.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;SurfaceView android:id="@+id/surface_camera" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" /&gt; &lt;Button android:id="@+id/buttonstart" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/record_start" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>And of course include these permission in manifest:</p> <pre><code>&lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt; &lt;uses-permission android:name="android.permission.CAMERA" /&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload