VideoView in different screen sizes

China☆狼群 提交于 2019-12-06 07:09:17

问题


I'm trying to insert a video for different sizes of screen. What I want it's a good resolution and without distortion. I have 2 videos for large and tiny screens. But I don't know how to insert them.

I thought it was like insert images from drawables files (hdpi, ldpi, etc) where you add the image in the resolution folder that you want. But I dont know if happens the same with videos or not.

Please help me to insert both videos to different resolutions!

Thanks!


回答1:


A Drawable, as far as Android is concerned is any kind of graphic/image/icon... But a video doesn't fall in that category. For that matter, you'll have to place it at the "./assets/" folder. Therefore, videos aren't automatically selected according to the screen size.

However, even if the videos are in a different folder, you can load them programmatically at the onCreate() method, like this:

Display mDisplay = getWindowManager().getDefaultDisplay(); 
int w = mDisplay.getWidth();
int h = mDisplay.getHeight();

if (w < 480 || h < 800) {
    mVideoView.setVideoPath(...your video in assets, of low resolution...);;
} else {
    mVideoView.setVideoPath(...your video in assets, of high resolution...);
}
...

With this or a similar method, you can load different videos, according to the user resolution, in a way that is even more precise than the ldpi/mdpi/etc method.



来源:https://stackoverflow.com/questions/13574612/videoview-in-different-screen-sizes

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