开发者

Black screen during video playback in Android

I'm playing a video using android media player & also showing an animation on the top of the video using another layer. (The video file is present on the sdcard.)

The animation is basically a cropped image which is being synchronized with video (TranslateAnimation).

Whenever I tap on the button to play the video, I experience a black screen momentarily with the cropped image in the center, then the video & animation both start. I want to avoid this somehow by loading the video first & then imposing the image on the top.

How can I achieve this? Or is there any better way?

Following are the relevant code snippets:

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();
        }
    };


You should use thread to play video and show image using handler or u can use AsyncTask to solve the black screen problem. I faced the same problem and got rid off using thread and handler.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜