0

Is there any way to get the play button to stay hidden in the background during recording until the user intervene to click the screen to allow the button to resurface the play button to stop the recording process?? Is the code coded in the .xml file or somewhere else.. How it be done??

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by peter_budo
0

After reading the link you provided i'm still quite lost on how should i integrate the surfaceview to the buttons similar to youtube to stop and start recording.. Sorry i'm very kinna bad in programming..

public class CameraTest extends Activity implements SurfaceHolder.Callback {
	
	private static final String TAG ="CAMERA_TUTORIAL";
	
	private SurfaceView surfaceView;
	private SurfaceHolder surfaceHolder;
	private Camera camera;
	private boolean previewRunning;

	File tempFile = null;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        surfaceView = (SurfaceView)findViewById(R.id.surface_camera);
        surfaceHolder = surfaceView.getHolder();
        surfaceHolder.addCallback(this);
        
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        
        Button btnStart = (Button) findViewById(R.id.button4);
        btnStart.setOnClickListener(new View.OnClickListener() 
        {
        	public void onClick(View v)
        	{
        		startRecording();
        	}
        	
        });
        
        Button btnStop = (Button) findViewById(R.id.button5);
        btnStop.setOnClickListener(new View.OnClickListener() 
        {
        	public void onClick(View v)
        	{
        		stopRecording();
        	}
        	
        });
    }
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
    	camera = Camera.open();
    	if (camera != null) {
    		Camera.Parameters params = camera.getParameters();
    		camera.setParameters(params);
    	}
    	else {
    		Toast.makeText(getApplicationContext(), "Camera not available!", Toast.LENGTH_LONG).show();
    		finish();
    	}
    }
    
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    	if (previewRunning) {
    		camera.stopPreview();
    	}
    	Camera.Parameters p = camera.getParameters();
    	p.setPreviewSize(320, 240);
    	p.setPreviewFormat(PixelFormat.JPEG);
    	camera.setParameters(p);
    	
    	try {
    			camera.setPreviewDisplay(holder);
    			camera.startPreview();
    			previewRunning = true;
    	}
    	catch (IOException e) {
    		Log.e(TAG,e.getMessage());
    		e.printStackTrace();
    	}
    }
    
    @Override
    public void surfaceDestroyed(SurfaceHolder holder){
    		camera.stopPreview();
    		previewRunning = false;
    		camera.release();
    }
    
    
    
    private MediaRecorder mediaRecorder;
    private final int maxDurationInMs = 20000;
    private final int videoFramesPerSecond = 20;
    
    public boolean startRecording(){
    	try {
    			camera.unlock();
    			
    			mediaRecorder = new MediaRecorder();
    			
    			mediaRecorder.setCamera(camera);
    			
    			mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    
    			mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    
    			mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
    				
    			mediaRecorder.setMaxDuration(maxDurationInMs);
    				
    				
    			
    				
    				mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    				
    				mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
    				
    				//mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
    				
    				tempFile = new File(Environment.getExternalStorageDirectory(),"1.3gp");
    				mediaRecorder.setOutputFile(tempFile.getPath());
    				
    				mediaRecorder.setVideoSize(surfaceView.getWidth(),surfaceView.getHeight());
    				
    				//mediaRecorder.setVideoFrameRate(videoFramesPerSecond);
    				
    				mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
    				
    								
    						mediaRecorder.prepare();
    						mediaRecorder.start();	
    						return true;
    								
    	} catch (IllegalStateException e) {
    		Log.e(TAG,e.getMessage());
    		e.printStackTrace();
    		return false;
    	} catch (IOException e) {
    		Log.e(TAG,e.getMessage());
    		e.printStackTrace();
    		return false;
    	}
    }
    
    public void stopRecording(){
    	mediaRecorder.stop();
    	camera.lock();
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.