2010-09-20 74 views

回答

5

您可以使用show()方法,從包含您VideoView您的活動的OnCreate方法來顯示,但不是因爲VideoView尚未連接到SurfaceHolder(或類似的東西)。你將不得不使用一個類似的過程:

public class ActivityPreHomeVideo extends Activity implements SurfaceHolder.Callback{ 

    private VideoView mVideoView; 
    private MediaController mMediaController; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.videolayout); 
     mVideoView = (VideoView) findViewById(R.id.videolayout_video); 

     mMediaController = new MediaController(this); 
     mMediaController.setMediaPlayer(mVideoView); 
     mMediaController.setAnchorView(mVideoView); 
     mVideoView.setMediaController(mMediaController); 

     //Set a callback when the VideoView is displayed 
     mVideoView.getHolder().addCallback(this); 

     mVideoView.setVideoPath("http://.../your_video.mp4"); 
    } 

    @Override 
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 
    } 

    @Override 
    public void surfaceCreated(SurfaceHolder holder) { 
     // Display the mediaController for 3 seconds 
     mMediaController.show(); 
    } 

    @Override 
    public void surfaceDestroyed(SurfaceHolder holder) { 
    } 
} 

希望這將有助於。

相關問題