【发布时间】:2015-04-19 02:31:38
【问题描述】:
这是我的布局:
<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上,第一次打开它可以找到但是当关闭应用程序并再次打开它时,出现黑屏,如下所示:
大约一分钟后,它从黑屏变为白屏,但仍然没有播放。
你能帮我解决这个问题吗?
【问题讨论】:
-
它在 onPrepared 中进行吗?
-
@varunbhardwaj 感谢您的回复,我登录了,但它没有转到 onPrepared
-
完美!!现在您可以检查原因,因为视频没有准备好,因此视频格式可能存在问题或其他问题
-
对于任何听到声音但看到黑屏的人:只需确保添加 mediaplayer.setDisplay(holder);在surfaceCreated 方法中。