How to create a Video play button to stay invisible?

All your problems with Audio, Video and Images.

How to create a Video play button to stay invisible?

Postby imso » Wed Mar 23, 2011 2:05 pm

Is there any way to get the play button to stay hidden in the background during recording until the user intervene to click the surfaceView 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 should it be done?? Thanks in advance :D
imso
Developer
Developer
 
Posts: 49
Joined: Mon Mar 21, 2011 10:47 am

Top

Re: How to create a Video play button to stay invisible?

Postby strider2023 » Fri Apr 01, 2011 8:22 am

Hi imso,

You can set button.setVisible(false) when you start recording and onTouch event during the ecording process you can set it back its visibility to true.
strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Re: How to create a Video play button to stay invisible?

Postby imso » Fri Apr 01, 2011 9:04 am

But i kinna want this function on a surfaceview because i'm using surfaceview as an preview for the user. Is it possible for an surfaceview instead,which is similar to youtube where the user can click anywhere on the screen to start or stop the recording? Can you guide me along with this problem on to integrate this function into my surfaceview because i'm quite new to java and eclipse...

Code: Select all
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();
                Toast.makeText(getBaseContext(), "Recording Started", Toast.LENGTH_SHORT).show();
            }

        });

        Button btnStop = (Button) findViewById(R.id.button5);
        btnStop.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                stopRecording();
                Toast.makeText(getBaseContext(), "Recording Stopped", Toast.LENGTH_SHORT).show();
            }
        });
    }
    @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();
    }
}
imso
Developer
Developer
 
Posts: 49
Joined: Mon Mar 21, 2011 10:47 am

Re: How to create a Video play button to stay invisible?

Postby imso » Sat Apr 02, 2011 5:45 am

If it is surfaceview how should implement the click function that is like youtube, how should i do it? Can you please help me i'm really at a lost here...
imso
Developer
Developer
 
Posts: 49
Joined: Mon Mar 21, 2011 10:47 am

Re: How to create a Video play button to stay invisible?

Postby strider2023 » Mon Apr 04, 2011 5:40 am

strider2023
Senior Developer
Senior Developer
 
Posts: 126
Joined: Tue Mar 02, 2010 6:34 am
Location: Chennai, India

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 12 guests