Wednesday, 17 August 2016

Android Camera Video Capture

In this example capturing video by inbuild camera in android and save captured video on sdcard. Using camera intent to record video and after record the video again come back on activity and show captured video path on activity.








activity_main.xml
-----------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
android:paddingBottom="@dimen/activity_vertical_margin"
   
android:paddingLeft="@dimen/activity_horizontal_margin"
   
android:paddingRight="@dimen/activity_horizontal_margin"
   
android:paddingTop="@dimen/activity_vertical_margin"
   
android:orientation="vertical"
   
tools:context="com.sgp.anil.statusbarnotification.MainActivity">


    <
Button
       
android:layout_width="wrap_content"
       
android:layout_height="wrap_content"
       
android:text="Video capture"
       
android:onClick="vcapture"
       
android:id="@+id/button_videocap"
       
android:layout_gravity="center_horizontal" />

    <
VideoView
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
        
android:id="@+id/videoView" />
</
LinearLayout>
MainActivity.Java
package com.sgp.anil.cameravideocapture;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {
    VideoView
videoview;
    Uri
uriVideo = null;

   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);

       
videoview = (VideoView) findViewById(R.id.videoView);
    }

   
   
public void vcapture(View v) {
        Intent int_video_camera =
new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
        startActivityForResult(int_video_camera,
1);
    }

   
@Override
   
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       
uriVideo = data.getData();
        MediaController media_Controller =
new MediaController(MainActivity.this);
        videoview.setMediaController(media_Controller);
       
videoview.setVideoURI(uriVideo);
       
videoview.start();
       
super.onActivityResult(requestCode, resultCode, data);
    }
}






No comments:

Post a Comment