我正在使用一个外部类来创建和控制 Android MediaPlayer:
public CycleVideo(String path, Activity activity, FrameLayout container){
this.path = path;
this.activity =activity;
this.container = container;
}
public void prepare(){
AssetFileDescriptor str;
try {
str = activity.getAssets().openFd(path);
mp = new MediaPlayer();
mp.setDataSource(str.getFileDescriptor());
SurfaceView sw = new SurfaceView(activity.getApplicationContext());
sw.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
container.addView(sw);
sw.setVisibility(View.VISIBLE);
mp.setDisplay(sw.getHolder());
mp.prepare();
//for testing - start
mp.setLooping(true);
mp.start();
//for testing - stop
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在主要活动中,我正在使用这个:
FrameLayout container = (FrameLayout)findViewById(R.id.PictureContainerLayout);
CycleVideo v = new CycleVideo("[path to video file in assets]", this, container);
v.prepare();
但是当我启动我的应用程序时,我的活动中的框架布局仍然是空的。并且 Eclipse 的 LogCat 中没有任何错误。我在哪里做错了?