Header Ads

Header ADS

SplashVideo android studio

                                                               JAVA

package com.splashvideo.splash;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.MotionEvent;
import android.widget.VideoView;

import java.util.Locale;



public class SplashActivity extends Activity implements Runnable {
public String USER_LANGUAGES = "user_langu";
private VideoView videoView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_splash);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String userlango = preferences.getString(USER_LANGUAGES , "en");

Locale locale = new Locale(userlango);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

videoView = (VideoView) findViewById(R.id.splashvideoView);
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.islamicwikipedia);
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (isFinishing())
return;
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();

}
});
}

try {
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion

(MediaPlayer mp) {

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(SplashActivity.this);
String userlango = preferences.getString(USER_LANGUAGES , "en");
if (userlango !=null) {
Locale locale = new Locale(userlango);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
}

jump();
}
});
videoView.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();
}

@Override
public void run() {
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}

@Override
protected void onStart() {
super.onStart();

}

@Override
protected void onStop() {
super.onStop();

}

}


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

<VideoView
android:id="@+id/splashvideoView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>




    Download this source code 

    


No comments

Powered by Blogger.