0

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>
Procrastinator
  • 2,526
  • 30
  • 27
  • 36
  • 1
    try this link https://stackoverflow.com/a/8830491/1548824 – akhilesh0707 Oct 05 '17 at 12:51
  • I have already seen your given link.... I was getting some errors as mentioned in the given link... https://stackoverflow.com/questions/39909268/cannot-resolve-method-setdatasourceandroid-net-uri so I used the suggestion available there that fixed the error but can't able to play background video. – Nitish Yadav Oct 05 '17 at 12:54

0 Answers0