美文网首页
Android VideoView神坑,只有声音没有头像解决方法

Android VideoView神坑,只有声音没有头像解决方法

作者: lhl_012 | 来源:发表于2017-08-07 16:10 被阅读388次

    具体问题就是,只有声音,但是没有画面。据详细测试,发现图像只在父类布局的底部显示,但是只显示一半,我擦擦,瞬间死了的心都有了。Now,Copy你的代码新建Demo,Ok,又没问题了,但是项目中就是有问题。。。

    国内论坛千篇一律,只管BB不讲实际,没法,只有上老外的网站,找到应该是提问问题质量最高的网站-stackoverflow(没有之一),搜索关键字"videoview only audio",出来结果找到下面的代码:

    videoView.setZOrderOnTop(true);
    
    

    this will set the videoview to the top layer; In other words: block everything under it.

    然后测试,完美解决。下面还有回答,代码如下:

    video_view = (VideoView)findViewById(R.id.video_view);
    video_view.setZOrderMediaOverlay(true);
    video_view.setVideoPath("/sdcard/myvideo.mp4");
    video_view.setMediaController(new MediaController(this));
    video_view.start();
    video_view.videoView.setZOrderOnTop(true);
    

    核心还是setZOrderMediaOverlay(true)、setZOrderOnTop(true)

    SurfaceView的源码,源码的这个方法setZOrderMediaOverlay(boolean isMediaOverlay),源码中对这个方法的描述:

    Control whether the surface view‘s surface is placed on top of another regular surface view in the window (but still behind the window itself).This is typically used to place overlays on top of an underlying media surface view.

    Note that this must be set before the surface view‘s containing window is attached to the window manager.

    Calling this overrides any previous call to {@link #setZOrderOnTop}.

    大概的意思就是说控制窗口中表面的视图层是否放置在常规视图层的顶部。

    上面说的那么多,意思就是是不是将SurfaceView放在顶部?毕竟ViewDeoView继承自SurfaceView,显示在顶部没毛病。具体的可以自行google,剩下的也不懂太多了。

    相关文章

      网友评论

          本文标题:Android VideoView神坑,只有声音没有头像解决方法

          本文链接:https://www.haomeiwen.com/subject/pyralxtx.html