我在单击按钮时打开一个活动,如果我单击按钮,下一个活动是从服务器播放视频,它发生黑色,5-6 秒后它开始播放视频,如何避免黑屏。?
这是我的代码:
mPreview=new SurfaceView(getApplicationContext());
l1.addView(mPreview);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();
以下内容为表面混凝土法。
path = "http://www.pixintro.com/upload/video/Benetton.mp4";
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(Environment.getExternalStorageDirectory()+"/Benetton.mp4");
mMediaPlayer.setDataSource(path);
mMediaPlayer.setDisplay(holder);
mMediaPlayer.prepare();
mMediaPlayer.setOnBufferingUpdateListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnVideoSizeChangedListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
public void onPrepared(MediaPlayer mediaplayer){
mIsVideoReadyToBePlayed = true;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown){
holder.setFixedSize(mVideoWidth, mVideoHeight);
mMediaPlayer.start();
}
}