android how to resize video width and height in surface view for media player

耗尽温柔 提交于 2019-12-04 08:38:19

I used TextureView instead of surface view (it allows to rotate video) and set its setScale{X|Y}() appropriately in:

@Override
public void onVideoSizeChanged(MediaPlayer mp, int w, int h) {
    if (w > 0 && h > 0) {
        RelativeLayout.LayoutParams l;
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        l = new RelativeLayout.LayoutParams(metrics.heightPixels, metrics.widthPixels);
        l.addRule(RelativeLayout.CENTER_IN_PARENT, -1);
        float scale = (metrics.heightPixels * 1.0f) / (metrics.widthPixels * 1.0f);
        videoView.setScaleX(scale);
        videoView.setLayoutParams(l);
        Log.d(YourApp.TAG, "video size: " + mp.getVideoWidth() + "x" + mp.getVideoHeight() + " vertical scale: " + scale);
    }
}

Note that I have rotated my video, this is why I set scale for X.

Hi arpit i was also working on the same devices as you have mentioned for playing video files, I to got the same problem while applying controls to video player (Abstract method not available).

As per my R&D on this topic i come to conclusion that the Customized android OS and the hardware of these devices are not compatible for each other as they are of very poor quality as compared to Samsung devices, so many of methods though they are in android OS but not supported by such devices.

So i think there is no solutions for such problems, in these devices.

plz try to focus using standard devices while developing any project. this may help you a lot.

Thanks. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!