-1

Hello guys im gonna explain what i did and what the issue im having

first i created a layout: video_background.xml

    <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

    <!--background video in the login layout-->
            <VideoView
                android:id="@+id/bg_video"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_gravity="center" />
</RelativeLayout>

then included the video_background.xml layout to the login layout:

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/video_background" />

then in the LoginActivity.java i created

private VideoView mVideoView;

then on onCreate i added this code :

//to play a video on the login background
    mVideoView = (VideoView) findViewById(R.id.bg_video);



Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.background_video);
    mVideoView.setVideoURI(uri);
    mVideoView.start();

    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mediaPlayer) {
            mediaPlayer.setLooping(true);
        }
    });

Finally at res i dropped the mp4 video raw.background_video.mp4

now every thing works good but not as expected not exactly like Spotify Music App login video background and not like LYFT App video background, the difference is if music player is playing on my phone and i start my App the music player will stop the music because the video player will start on my app, my issue i dont want the music to stop or the radio i dont want my app to take over, like LYFT and Spotify if i start anyone of them the music at the phone will not stop and LYFT or Spotify will play the video background without taking over im not sure if LYFT and Spotify they are playing a video or a GIF image at the background?, note my app video does not have a sound its muted video. any help please or good ideas?

Ridha Rezzag
  • 3,672
  • 1
  • 34
  • 39
  • 1
    Does this answer your question? [android: video as background view](https://stackoverflow.com/questions/7074600/android-video-as-background-view) – Zeone line Aug 09 '21 at 03:46

1 Answers1

1

Use a GIF :D

Since you don't have sound, a GIF sounds good especially if it ends up being smaller than the MP4.

Otherwise I think you'd have to mess with how audio gets routed. I'd avoid that if possible.

DataDino
  • 1,507
  • 1
  • 15
  • 30