Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android VideoView SplashScreen

This is my splash.java, and I am using my videoView as the contentView. Is there any way that I can center the video inside the videoView which is the contentView?

Or what is the better thing to do?

package com.android;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.VideoView;

public class Splash extends Activity
{
    VideoView vidHolder;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        try
        {
            vidHolder = new VideoView(this);
            setContentView(vidHolder);
            Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.splash);
            vidHolder.setVideoURI(video);
            vidHolder.setOnCompletionListener(new OnCompletionListener()
            {
                public void onCompletion(MediaPlayer mp) {
                    jump();
            }});
            vidHolder.start();

        } catch(Exception ex) {
            jump();
        }
    }

    private void jump()
    {
        if(isFinishing())
            return;
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }
}
like image 421
Lendl Leyba Avatar asked Oct 21 '13 08:10

Lendl Leyba


People also ask

What is SplashScreen in Android?

Android Splash Screen is the first screen visible to the user when the application's launched. Splash screen is one of the most vital screens in the application since it's the user's first experience with the application.

How do I make a splash screen app for Android?

The most straightforward way to create a simple splash screen was to create a dedicated theme overriding android:windowBackground with a drawable containing branding colors or a bitmap of a logo. The theme was set as an attribute of the launcher activity in AndroidManifest. xml.


1 Answers

Use a layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
  <VideoView android:id="@+id/myvideo"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerInParent="true"/>
</RelativeLayout>

Notice: you didn't ask for it, but your code is from an example seen elsewhere that will feature the infamous black flash before and after the video. You need to add vidHolder.setZOrderOnTop(true); to avoid that (after #setVideoUri).

like image 105
Guillaume Cottenceau Avatar answered Sep 27 '22 18:09

Guillaume Cottenceau