Widget Recent Post No.

header ads

How to make Background video in android studio


 Step 1 MAIN.xml

<?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"

    android:orientation="vertical"

    tools:context=".MainActivity">





    <VideoView

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:id="@+id/videoview"

        android:layout_alignParentBottom="true"

        android:layout_alignParentTop="true"

        />



    <RelativeLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent">



        <ImageView

            android:id="@+id/onboarding_icon_id"

            android:layout_width="80dp"

            android:layout_height="80dp"

            android:layout_centerHorizontal="true"

            android:layout_marginTop="120dp"

            android:src="@drawable/rklogo" />



    </RelativeLayout>



    <androidx.viewpager.widget.ViewPager

        android:id="@+id/onboarding_viewpager_id"

        android:layout_width="fill_parent"

        android:layout_height="match_parent"

        android:layout_weight="150"

        tools:ignore="SpeakableTextPresentCheck">


    </androidx.viewpager.widget.ViewPager>



    <RelativeLayout

        android:layout_width="match_parent"

        android:layout_height="10dp"

        android:layout_weight="10"

        android:orientation="horizontal">



        <Button

            android:id="@+id/back_button_id"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentStart="true"

            android:layout_alignParentLeft="true"

            android:layout_centerVertical="true"

            android:background="@android:color/transparent"

            android:textColor="#fff"

            tools:ignore="TouchTargetSizeCheck,SpeakableTextPresentCheck" />



        <Button

            android:id="@+id/next_button_id"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_alignParentEnd="true"

            android:layout_alignParentRight="true"

            android:layout_centerVertical="true"

            android:background="@android:color/transparent"

            android:textColor="#fff"

            tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />


    </RelativeLayout>



    <RelativeLayout

        android:id="@+id/header"


        android:layout_width="wrap_content"

        android:layout_height="wrap_content">


        <TextView

            android:id="@+id/skip"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="310dp"

            android:layout_marginTop="40dp"


            android:text="Skip >>"

            android:textColor="#fff"

            android:textSize="15dp" />

    </RelativeLayout>


    <!-- Footer aligned to bottom -->


    <RelativeLayout

        android:id="@+id/footer"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_alignParentBottom="true"

        android:layout_marginBottom="40dp"

        android:gravity="center"

        android:padding="15dp">



        <TextView

            android:id="@+id/login"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:text="LOG IN"

            android:textColor="#fff"

            android:textSize="15sp" />


        <View

            android:layout_width="1dp"

            android:layout_height="30dp"

            android:layout_marginLeft="120dp"

            android:layout_marginTop="2dp"

            android:background="#fff" />


        <TextView

            android:id="@+id/reg"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="200dp"

            android:text="SIGN UP"

            android:textColor="#fff"

            android:textSize="15sp" />



    </RelativeLayout>


</RelativeLayout>


Step 2 MAIN.JAVA


package in.learncodewithrk.googlelogin;


import androidx.appcompat.app.AppCompatActivity;


import android.media.MediaPlayer;

import android.net.Uri;

import android.os.Bundle;

import android.widget.VideoView;


public class MainActivity extends AppCompatActivity {


    VideoView videoView;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);





        videoView=findViewById(R.id.videoview);

        Uri uri= Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.video);

        videoView.setVideoURI(uri);

        videoView.start();


        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override

            public void onPrepared(MediaPlayer mp) {

                mp.setLooping(true);

            }

        });

    }


    @Override

    protected void onResume() {

        videoView.resume();

        super.onResume();

    }


    @Override

    protected void onRestart() {

        videoView.start();

        super.onRestart();

    }


    @Override

    protected void onPause() {

        videoView.suspend();

        super.onPause();

    }


    @Override

    protected void onDestroy() {

        videoView.stopPlayback();

        super.onDestroy();

    }

}

Source : https://user-images.githubusercontent.com/71060268/144556317-62c8b186-7a06-40c9-a244-bc383c6b9f7c.png

GITHUB :https://github.com/LearncodeWithRk/Background-video

Post a Comment

0 Comments