【发布时间】:2011-03-14 08:28:33
【问题描述】:
我正在使用 android 媒体播放器播放视频,并且还使用另一个图层在视频顶部显示动画。 (视频文件存在于 sdcard 上。)
动画基本上是与视频同步的裁剪图像(TranslateAnimation)。
当我点击按钮播放视频时,我会暂时遇到黑屏,裁剪后的图像在中间,然后视频和动画都开始了。我想通过先加载视频然后将图像强加在顶部来以某种方式避免这种情况。
我怎样才能做到这一点?或者有没有更好的办法?
以下是相关代码sn-ps:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videolayer);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
try{
Intent myint = this.getIntent();
photoPath = myint.getStringExtra("photo_path");
large_bitmap_path = myint.getStringExtra("large_bitmap_path");
bitmap_path = myint.getStringExtra("bitmap_path");
imv1 = (ImageView)findViewById(R.id.imv1);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFile(photoPath, options);
imv1.setImageBitmap(bitmap);
getWindowManager().getDefaultDisplay().getMetrics(dm);
videoView = (VideoView) findViewById(R.id.VideoView);
File f=new File(Environment.getExternalStorageDirectory(), "videos/"+Videoid[GalleryVideo.galleryVideoCounter]+".m4v");
Uri video = Uri.parse(f.getAbsolutePath());
videoView.setVideoURI(video);
videoView.setOnPreparedListener(this);
videoView.setOnCompletionListener(video_listener);
videoView.start();
lower = (View)findViewById(R.id.lower);
middle = (View)findViewById(R.id.middle);
upper = (View)findViewById(R.id.upper);
upper.setVisibility(4);
.......
RelativeLayout ll = (RelativeLayout) findViewById(R.id.LinearLayout01);
ll.setOnTouchListener(video_tap);
startTime = System.currentTimeMillis();
} catch(Exception e){
e.printStackTrace();
}
}
.................
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
videoHeight = videoView.getMeasuredHeight();
videoWidth = videoView.getMeasuredWidth();
displayWidth = getApplicationContext().getResources().getDisplayMetrics().widthPixels;
displayHeight = getApplicationContext().getResources().getDisplayMetrics().heightPixels;
//video is ready for play, now start animation
anim_start = 1;
launchAnimation();
}
private Runnable resumeAnim =new Runnable() {
public void run() {
launchAnimation();
}
};
【问题讨论】:
标签: android animation android-layout media-player layer