Video Capture Intent
package app.test;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.VideoView;
public class Test extends Activity implements OnClickListener {
public static int VIDEO_CAPTURED = 1;
Button captureVideoButton;
Button playVideoButton;
VideoView videoView;
Uri videoFileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
captureVideoButton = (Button) this.findViewById(R.id.CaptureVideoButton);
playVideoButton = (Button) this.findViewById(R.id.PlayVideoButton);
captureVideoButton.setOnClickListener(this);
playVideoButton.setOnClickListener(this);
playVideoButton.setEnabled(false);
videoView = (VideoView) this.findViewById(R.id.VideoView);
}
public void onClick(View v) {
if (v == captureVideoButton) {
Intent captureVideoIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(captureVideoIntent, VIDEO_CAPTURED);
} else if (v == playVideoButton) {
videoView.setVideoURI(videoFileUri);
videoView.start();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == VIDEO_CAPTURED) {
videoFileUri = data.getData();
playVideoButton.setEnabled(true);
}
}
}
//main.xml
<?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:text="Capture Video" android:id="@+id/CaptureVideoButton" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="Play Video" android:id="@+id/PlayVideoButton" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<VideoView android:id="@+id/VideoView" android:layout_width="wrap_content" android:layout_height="wrap_content"></VideoView>
</LinearLayout>
Related examples in the same category