I am trying to play a video in background of sign-in page of my android app but it cant display anything on the screen. Only black screen appears when launching the app.
This is my code with no errors but still, it doesn't play video in the background.
I have checked, video is available in Raw folder.
XML is also provided below.
package in.niya.foodiezone.foodiezone;
import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class backmov extends Activity implements SurfaceHolder.Callback {
private MediaPlayer mp=null;
SurfaceView mSurface=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mp=new MediaPlayer();
mSurface=(SurfaceView)findViewById(R.id.surface);
mSurface.getHolder().addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
Uri video=
Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.signin);
mp.setDataSource(video);
mp.prepare();
int videoWidth=mp.getVideoWidth();
int videoHeight=mp.getVideoHeight();
int screenWidth=getWindowManager().getDefaultDisplay().getWidth();
android.view.ViewGroup.LayoutParams lp=mSurface.getLayoutParams();
lp.width=screenWidth;
lp.height=(int)(((float)videoHeight/(float)videoWidth)*(float)screenWidth);
mSurface.setLayoutParams(lp);
mp.setDisplay(holder);
mp.start();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
mp.stop();
}
}
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Home">
<SurfaceView
android:id="@+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>