Capture Video : Video « Media « Android






Capture Video

  

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <Button
    android:id="@+id/capture"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Take a Video"
  />
  <TextView
    android:id="@+id/file"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  />
</LinearLayout>
package app.test;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MyActivity extends Activity {
    
    private static final int REQUEST_VIDEO = 100;
    
    Button captureButton;
    TextView text;
    File destination;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        captureButton = (Button)findViewById(R.id.capture);
        captureButton.setOnClickListener(listener);
        
        text = (TextView)findViewById(R.id.file);
        
        destination = new File(Environment.getExternalStorageDirectory(),"myVideo");
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == REQUEST_VIDEO && resultCode == Activity.RESULT_OK) {
            String location = data.getData().toString();
            text.setText(location);
        }
    }
    
    private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destination));
            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
            startActivityForResult(intent, REQUEST_VIDEO);
        }
    };
}

   
    
  








Related examples in the same category

1.Record video
2.Store image and video
3.Load video file from local file system
4.Uri for local video file
5.Custom Video Player
6.Get Video size
7.Display video with VideoView
8.Using MediaController to control Video
9.Play video from Youtube.com
10.Video Gallery
11.View Video with VideoView
12.Video Capture
13.Video Capture with Metadata
14.VideoView Demo