我使用以下代码播放视频。但是当我运行该程序时,它会显示一个白色屏幕。请指教。我使用媒体播放器播放视频。当我使用视频观看它没有问题时播放:
MediaPlayer mediaPlayer;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean pausing=false;
VideoView mVideoView;
Button play,stop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
getWindow().setFormat(PixelFormat.UNKNOWN);
// VideoView m=(VideoView)findViewById(R.id.videoView1);
// String uriPath="android.resource://com.example.videoplayerthurs/"+R.raw.a;
// Uri uri=Uri.parse(uriPath);
// m.setVideoURI(uri);
// m.requestFocus();
// m.start();
surfaceView = (SurfaceView) findViewById(R.id.surfaceView1);
play=(Button)findViewById(R.id.button1);
stop=(Button)findViewById(R.id.button2);
play.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
// VideoView mVideoView= (VideoView)findViewById(R.id.videoView1);
// String uriPath="android.resource://lk.sliit.androidvideoplayer/"+R.raw.a;
//
// Uri uri=Uri.parse(uriPath);
// mVideoView.setVideoURI(uri);
// mVideoView.requestFocus();
// mVideoView.start();
mediaPlayer=MediaPlayer.create(VideoActivity.this, R.raw.a);
surfaceHolder=surfaceView.getHolder();
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.start();
}
});
}