好吧,我的朋友,首先你不能为你的照片设置背景VideoView
并使其在屏幕背景中播放。
请按照我的步骤并付出你的努力,你应该在那里。
从可绘制文件夹中删除视频并将其添加到原始文件夹中。请谷歌搜索如何创建原始文件夹。虽然很简单。并将您的视频文件放入其中。
首先,创建一个SurfaceView
在你的xml中像这样。
<?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>
现在,创建一个如下所示的类,它可以实现SurfaceView
,
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);
mSurfaceView.getHolder().addCallback(this);
//...
}
}
现在您的类将要求添加未实现的方法。只需单击“添加未实现的方法”即可添加这些方法
现在您将能够看到像这样自动生成的方法,
@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.getVideoWidth();
int videoHeight = mp.getVideoHeight();
//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 / (float)videoWidth) * (float)screenWidth);
//Commit the layout parameters
mSurfaceView.setLayoutParams(lp);
//Start video
mp.setDisplay(holder);
mp.start();
}