【问题标题】:Black screen during video playback in Android在 Android 中播放视频时出现黑屏
【发布时间】: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


    【解决方案1】:

    您应该使用线程播放视频并使用处理程序显示图像,或者您可以使用 AsyncTask 来解决黑屏问题。我遇到了同样的问题并使用线程和处理程序摆脱了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      相关资源
      最近更新 更多