Add video in android studio , how to add video in android app
Main activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<VideoView
android:id="@+id/vdview"
android:layout_width="0dp"
android:layout_height="320dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.051"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cricket"
app:layout_constraintVertical_bias="0.052" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5sp"
android:text="123"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.088"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/cricket"
app:layout_constraintVertical_bias="0.052" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="284dp"
android:orientation="vertical"
android:paddingLeft="10sp"
android:paddingRight="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cricket"
app:layout_constraintVertical_bias="0.653">
<TextView
android:id="@+id/textView3"
android:layout_width="262dp"
android:layout_height="40dp"
android:layout_marginTop="8sp"
android:text="Amit: very nice video"
android:textSize="20sp" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="8sp"
android:text="Vijay: thank you sir"
android:textSize="20sp" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="8sp"
android:text="Suresh: nice techniques"
android:textSize="20sp" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="8sp"
android:text="Puja: Thanks sir for making video"
android:textSize="20sp" />
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="8sp"
android:text="Namrta: thanks you sir"
android:textSize="20sp" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Main activity java
package com.example.ourtube;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView myview = findViewById(R.id.vdview);
myview.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.butter);
MediaController mediaController = new MediaController(this);
myview.setMediaController(mediaController);
mediaController.setAnchorView(myview);
myview.start();
}
}