How to play video in background in Sketchware:
Hi everyone today we present a new lesson
This lesson is about how you can play video in background inside your application using Sketchware by following this Steps.
First Step:
Create a New project and add linear 1 ( for playing the video) and Linear2 for adding others things like ( button, image, textview......,)
Second step:
Open side List and lock for "Resources", click on it and add new file with name "raw" , and put in this file the video you want to play in background.
Third step:
Go back to "Oncreat", and add block from Operateur with name "add scour",
And put this code on it:
String path = "android.resource://" +
getPackageName() + "/" +
R.raw.video_file;
final VideoView vd = new VideoView(Splash2Activity.this);
vd.setLayoutParams(new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.MATCH_PARENT));
vd.setVideoURI(Uri.parse(path));
vd.requestFocus();
vd.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
@Override
public void onPrepared(MediaPlayer _mediaPlayer){
vd.start();
}
});
vd.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
vd.start();
} });
//this layout will conatin your video view
RelativeLayout rl = new RelativeLayout(this);
//this layout will contain your widgets which are to be shown on video
RelativeLayout rl2 = new RelativeLayout(this);
rl2.addView(vd, -1,-1);
linear1.removeAllViews();
rl.addView(rl2, -1,-1);
rl.addView(linear2, -1,-1);
linear1.addView(rl,-1,-1);
//this property will all the video to be played in full screen
DisplayMetrics metrics DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) vd.getLayoutParams();
params.addRule(android.widget.RelativeLayout.ALIGN_PARENT_TOP, android.widget.RelativeLayout.TRUE);
params.addRule(android.widget.RelativeLayout.ALIGN_PARENT_START, android.widget.RelativeLayout.TRUE);
params.addRule(android.widget.RelativeLayout.ALIGN_PARENT_END, android.widget.RelativeLayout.TRUE);
params.addRule(android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM, android.widget.RelativeLayout.TRUE);
vd.requestLayout();
Watch the video for more understanding:
Comments
Post a Comment