Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video as a Splash Screen instead of Picture

I am doing the Android Programming Tutorial on Splash Screens where you show a picture or text for 5 Seconds than it goes to the Main Application. My Question is..Instead of Text or Pictures I want to display a Video File for 5 Seconds before it goes to the Next page of the Application.

I am not talking about when the Application Loads I am talking about when it is Loaded and you program it to display something on a Separate Java & XML page to display something then move to something else..here is my current code.

@Override
protected void onCreate(Bundle SplashScreen1) {
    // TODO Auto-generated method stub
    super.onCreate(SplashScreen1);
    setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);
            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent openStartingPoint = new Intent("com.Player.Splash.STARTINGPOINT");
                startActivity(openStartingPoint);

            }
        }
    };
    timer.start();

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
}

So What Do I do to make it display a Video Media file without the Start/Stop etc..

like image 734
Jester Avatar asked Nov 22 '11 02:11

Jester


People also ask

How do I make an animated splash screen?

Go to app > java > first package name > right-click > New > Activity > Empty Activity and create another activity and named it as SplashScreen. Edit the activity_splash_screen. xml file and add image, text in the splash screen as per the requirement. Here we are adding an image to the splash screen.


2 Answers

I hope this will help you. You just create a simple VideoView for create a splash screen for the video.

Checkout the source code hear and simple steps what is the best practice to create a splash screen

like image 30
Ashish Dwivedi Avatar answered Sep 29 '22 00:09

Ashish Dwivedi


1) Create SplashScreen.java class.

2) Create a raw folder inside res directory(res/raw).

3) Paste your mp4 video file in this raw folder(if you don't have any sample mp4, you can download from the below link). http://www.mediafire.com/download/p05ki89i2dt5x2x/splash.mp4

4) Then add the following code in your SplashScreen.java class.

public class SplashScreenActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {
        VideoView videoHolder = new VideoView(this);
        setContentView(videoHolder);
        Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.splash);
        videoHolder.setVideoURI(video);

        videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                jump();
            }
        });
        videoHolder.start();
    } catch (Exception ex) {
        jump();
    }
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    jump();
    return true;
}

private void jump() {
    if (isFinishing())
        return;
    startActivity(new Intent(this, MainActivity.class));
    finish();
}

}

Note: splash_activity.xml is not required.

like image 114
Surendar D Avatar answered Sep 28 '22 23:09

Surendar D