Search code examples
androidandroid-studiovideosurfaceviewandroid-videoview

How to play video file on login page(background) in android app?


Look here I want to make the same as vine app has. I tried to implement it by looking some answers at stackoverflow.com. But I could not. What about a size of video and quality? A size of app will increased? If I will use file that inserted in raw folder?


Solution

  • One of my apps contain a video as background. Placed in res/raw/ with 4,9 MB, 750x1334 Pixel, 20 seconds and H.264, AAC codec.

    This of course increases the app size - even if you got minifyEnabled true / shrinkResources true for building the apk.

    Example code (onCreate):

    VideoView videoView = (VideoView) findViewById(R.id.videoView);
    
    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.background_video);
    
    videoView.setDrawingCacheEnabled(true);
    videoView.setVideoURI(uri);
    videoView.requestFocus();
    

    Don't forget to call videoView.pause/start at onPause/onResume