Black screen while playing video in Android

I play the video using the Android media player, and also show the animation at the top of the video using a different layer. (The video file is present on the SD card.)

Animation is basically a cropped image that syncs to video ( TranslateAnimation ).

Whenever I press a button to play a video, I momentarily experience a black screen with a cropped image in the center, then the video and animation begin. I want to somehow avoid this by first uploading the video and then drawing the image on top.

How can i achieve this? Or is there a better way?

The following are 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();
        }
    };
+3
source share
1

, , AsyncTask . .

0

All Articles