0% found this document useful (0 votes)
15 views2 pages

Prac23 2

The document shows code for recording a video using various camera methods in Android. It includes XML layout code with a VideoView and record button. The Java code initializes these, starts the camera on button click, and returns the video to display in the VideoView.

Uploaded by

ajinkya.n.mote
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Prac23 2

The document shows code for recording a video using various camera methods in Android. It includes XML layout code with a VideoView and record button. The Java code initializes these, starts the camera on button click, and returns the video to display in the VideoView.

Uploaded by

ajinkya.n.mote
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Practical No: 23

Q.2write a program to record a video using various camera methods


AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- creating a video view on below line -->
<VideoView
android:id="@+id/videoView"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/idBtnRecordVideo"
android:layout_margin="5dp" />
<!-- creating a button to record a video on below line -->
<Button
android:id="@+id/idBtnRecordVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:text="Record Video"
android:textAllCaps="false" />
</RelativeLayout>
.java file
package com.example.java_test_application;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {

// creating variables on below line.


private Button recordVideoBtn;
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initializing variables on below line.
recordVideoBtn = findViewById(R.id.idBtnRecordVideo);
videoView = findViewById(R.id.videoView);

// adding click listener for recording button.


recordVideoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// on below line opening an intent to capture a video.
Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
// on below line starting an activity for result.
startActivityForResult(i, 1);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 1) {
// on below line setting video uri for our video view.
videoView.setVideoURI(data.getData());
// on below line starting a video view
videoView.start();
}
}
}

You might also like