Android的VideoView黑屏 [英] Android VideoView black screen

查看:3114
本文介绍了Android的VideoView黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方式来获得的start()方法运行之前在VideoView摆脱讨厌的黑初始画面。

我曾尝试与小部件的背景图片,但它不工作按预期的方式在所有。 我也试着将第一帧的图像中的VideoView顶部的视频和星星()方法后隐藏它。 在prepared监听器添加到开始播放视频,然后隐藏图像。这个工作,但有一个在过渡可怕的忽悠,我不知道如何摆脱它。


感谢您的答复。添加的MediaController没有任何影响的。该问题仍然存在(我仍然看到黑色闪烁),我不希望有视频监控可见。 我的code是这样的:

  VideoView vSurface =(VideoView)findViewById(R.id.surfaceView1);
    vSurface.setVideoURI(Uri.parse(android.resource://com.mypackage/+ R.raw.video1));
    vSurface.setVisibility(View.VISIBLE);
    vSurface.setOn preparedListener(本);
    vSurface.setDrawingCacheEnabled(真正的);
    vSurface.setOnErrorListener(本);
 

解决方案

我得到了同样的问题,我发现了一个解决方案。它有点哈克,但它做的伎俩。 所以基本上你需要把你的VideoView成的FrameLayout。 在videoview你需要添加其他的FrameLayout与视频的背景,当你的视频被加载并准备打你隐藏的占位符。

 <的FrameLayout
  机器人:ID =@ + ID / frameLayout1
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT
  机器人:layout_gravity =中心
  机器人:layout_marginTop =50dip>

  < VideoView
    机器人:ID =@ + ID / geoloc_anim
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =172dip机器人:layout_gravity =顶|中心的Andr​​oid版本:能见度=看见/>

  <的FrameLayout
      机器人:ID =@ + ID /占位符
      机器人:layout_width =FILL_PARENT
      机器人:layout_height =FILL_PARENT机器人:背景=@可绘制/ fondvert_anim>
  < /的FrameLayout>
 

在你的活动,你需要实现在preparedListener并添加此

  //当视频准备播放时调用
公共无效于prepared(MediaPlayer的MP){

    查看占位符=(查看)findViewById(R.id.placeholder);

    placeholder.setVisibility(View.GONE);
}
 

所以当视频已经准备好,我们隐藏我们的占位符和招避免了黑色闪烁屏幕。

希望这帮助别人。

I have been looking for a way to get rid of the nasty black initial screen on a VideoView before the start() method is run.

I have tried with background image on the widget but it doesnt work as expected at all. I have also tried putting an image of the first frame in the video on top of the VideoView and hiding it after the stars() method. Adding an onPrepared listener to start the video and then hide the image. This works but there is a horrible flicker in the transition and i don't know how to get rid of it.


Thanks for your reply. Adding the MediaController had no effect at all. The problem persists (I still see the black flicker) and I dont want to have the video controls visible at all. My code looks like this:

    VideoView vSurface= (VideoView) findViewById(R.id.surfaceView1);
    vSurface.setVideoURI(Uri.parse("android.resource://com.mypackage/" + R.raw.video1));
    vSurface.setVisibility(View.VISIBLE);
    vSurface.setOnPreparedListener(this);
    vSurface.setDrawingCacheEnabled(true);
    vSurface.setOnErrorListener(this);

解决方案

I got the same problem and i found a solution. Its a little bit hacky but it do the trick. So basically you need to put your VideoView into a FrameLayout. Over the videoview you need to add another FrameLayout with the background of your video and when your video is loaded and ready to play you hide the placeholder.

<FrameLayout
  android:id="@+id/frameLayout1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_gravity="center"
  android:layout_marginTop="50dip" >

  <VideoView
    android:id="@+id/geoloc_anim"
    android:layout_width="fill_parent"
    android:layout_height="172dip" android:layout_gravity="top|center" android:visibility="visible"/>

  <FrameLayout
      android:id="@+id/placeholder"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" android:background="@drawable/fondvert_anim">
  </FrameLayout>

In your activity you need to implements OnPreparedListener and add this

//Called when the video is ready to play
public void onPrepared(MediaPlayer mp) {

    View placeholder = (View) findViewById(R.id.placeholder);

    placeholder.setVisibility(View.GONE);
}

So when the video is ready we hide our placeholder and that trick avoid the black flicker screen.

Hope this help someone.

这篇关于Android的VideoView黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆