2011-03-14 30 views
3

我正在播放使用android媒體播放器的視頻&也使用另一個圖層在視頻頂部顯示動畫。 (視頻文件存在於SD卡上。)Android中的視頻播放過程中的黑屏

動畫基本上是與視頻同步的裁剪圖像(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(); 
     } 
    }; 

回答

0

您應該使用線程使用處理程序來播放視頻和顯示圖像或u可以使用的AsyncTask解決黑屏問題。我遇到了同樣的問題,並使用線程和處理程序來解決問題。

相關問題