使用VideoView显示视频时出现android黑屏 [英] android-black screen on displaying video by using VideoView
问题描述
这是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
<VideoView
android:id="@+id/geoloc_anim"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top|center"
android:visibility="visible" />
<FrameLayout
android:id="@+id/placeholder"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</FrameLayout>
</LinearLayout>
这是我的活动代码:
public class MainActivity extends ActionBarActivity implements OnPreparedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();
VideoView mVideoView = (VideoView) findViewById(R.id.videoview);
Uri uri = Uri.parse("android.resource://" + getPackageName()+"/raw/lst2");
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.setZOrderOnTop(true);
mVideoView.start();
}
@Override
public void onPrepared(MediaPlayer mp) {
mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
View placeholder = (View) findViewById(R.id.placeholder);
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
// video started; hide the placeholder.
placeholder.setVisibility(View.GONE);
return true;
}
return false;
}
});
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
}
public void surfaceCreated(SurfaceHolder holder) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
}
它在android 4.2上工作正常,但在android 2.3上工作不正常.在android 2.3上,它第一次打开时可以找到,但是在关闭应用程序并再次打开时,出现黑屏,如下所示:
It works fine on android 4.2 but it doesn't work properly on android 2.3 . on android 2.3 , the first time it opens it works find but when close the app and open it again ,a black screen comes , something like this :
大约一分钟后,它从黑屏变为白屏,但仍然没有任何播放.
and after one minute or so , it goes from a black screen to a white screen but still nothing plays .
您能帮我解决这个问题吗?
Could you help me to solve this problem ?
推荐答案
答案很晚.但是肯定可以帮助任何人.
Very late answer. But surely it helps anyone.
设置 videoView.setZOrderOnTop(true).
https://developer.android.com/reference/android/view/SurfaceView.html#setZOrderOnTop(boolean)
videoView.setVideoURI(Uri.parse(uriString));
videoView.setZOrderOnTop(true);//this line solve the problem
videoView.start();
这篇关于使用VideoView显示视频时出现android黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!