安卓设备视频播放时出现黑屏问题

3
我正在使用Android媒体播放器播放视频,并使用另一层显示顶部的动画。(视频文件位于sd卡上。)
动画基本上是一个被裁剪的图像,与视频同步(TranslateAnimation)。
每当我点击按钮播放视频时,我会短暂地看到黑屏和中心的裁剪图像,然后视频和动画都开始播放。我希望通过先加载视频,然后在其上方添加图像来避免这种情况。
我该如何实现这一点?或者有更好的方法吗?
以下是相关的代码片段:
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();
        }
    };
1个回答

0

你应该使用线程来播放视频和使用Handler或者可以使用AsyncTask来解决黑屏问题展示图像。我曾经遇到过同样的问题,通过使用线程和Handler解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接