- Integrating video file in android app as app background
- <VideoView
- android:id="@+id/video"
- android:layout_width="320px"
- android:layout_height="240px"
- android:layout_gravity="center"
- android:background="@raw/hp"
- />
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- VideoView video=(VideoView) findViewById(R.id.video);
- video.start();
- }
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/home_container"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <SurfaceView
- android:id="@+id/surface"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:paddingTop="10dip" />
- </framelayout>
- public class YourMovieActivity extends Activity implements SurfaceHolder.Callback {
- private MediaPlayer mp = null;
- //...
- SurfaceView mSurfaceView=null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- mp = new MediaPlayer();
- mSurfaceView = (SurfaceView) findViewById(R.id.surface);
- //...
- }
- }
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- }
- @Override
- public void surfaceCreated(SurfaceHolder holder) {
- Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
- + R.raw.your_raw_file);
- mp.setDataSource(video);
- mp.prepare();
- //Get the dimensions of the video
- int videoWidth = mp.getVideoHeight();
- int videoHeight = mp.getVideoWidth();
- //Get the width of the screen
- int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
- //Get the SurfaceView layout parameters
- android.view.ViewGroup.LayoutParams lp = mSurfaceView.getLayoutParams();
- //Set the width of the SurfaceView to the width of the screen
- lp.width = screenWidth;
- //Set the height of the SurfaceView to match the aspect ratio of the video
- //be sure to cast these as floats otherwise the calculation will likely be 0
- lp.height = (int) (((float)videoHeight.height / (float)videoWidth.width) * (float)screenWidth);
- //Commit the layout parameters
- mSurfaceView.setLayoutParams(lp);
- //Start video
- mp.start();
- }