Ijkplayer: 怎样让视频根据宽度来按比例调整高度?

Created on 8 Jun 2016  ·  5Comments  ·  Source: bilibili/ijkplayer

我在IjkVideoView外面包裹了一层relativelayout,relativelayout的宽度设置为match_parent,高度设置为wrap_content,我的想法是视频把宽度撑满,然后根据这个宽度按视频本身来等比例设置高度,这应该怎么实现,因为onMeasure方法已经removed了。

staled

Most helpful comment

@bbcallen 不想解决问题 就别装逼了

All 5 comments

问题自己研究下,解决了,修改了doMeasure方法,不过方法不一定是最合适的。
1.原因是我是一个新闻详细页面,里面放了视频,文字,是包含在一个scrolview里面的,超出了屏幕,
所以在竖屏状态下ijkplayer的surfacerendview的doMeasure方法判断出来的heightSpecMode为UNSPECIFIED,进而heightSpecSize为0,走下来导致在页面中是以视频原始尺寸呈现,而不是我想要的宽度撑满,高度按视频尺寸自适应。
2.在横屏状态下,我是gone掉其他view的从而实现视频全屏,所以播放器还是包含在scrolview(fillViewport=true)里面的。这个时候应该是由于scrollview里面只有ijkplayer这个一个可见控件,几次Measure之后,doMeasure方法里面的heightSpecMode会由UNSPECIFIED变成了at_most的,从而正常全屏显示了。
3.因为surefaceview本身默认包裹的layoutA,ijkplayer指定的width和height都是warp_content的,所以无论在我们本身视频布局中的layoutA的外层layout指不指定尺寸,heightSpecMode和widthSpecMode是不可能有EXACTLY状态出现的,因此感觉doMeasure方法里面的对EXACTLY一些处理是无用的。
因为1,2和3,导致我修改doMeasure方法比较纠结,希望看到官方的做法。
我还想问的是,b站视频横屏全屏是怎么实现的,是不是也是gone掉其他view, 还是另开了一个窗口啥的?给个思路就行,谢谢了~~

Sorry, bilibili is closed source software, I'm not authorized to talk about any technical detail in it.
And, I don't think there are anything different between VideoView and normal view.

你试试通过 setAspectRatio 设置 视频显示模式 试试

@bbcallen 不想解决问题 就别装逼了

Was this page helpful?
0 / 5 - 0 ratings