I have a VideoView inside a RecyclerView. I want to eventually have a list of videos to play on a Recyclerview. I decided to start out with one video, then move on to having mul
the problem is with
android:layout_width="wrap_content"
android:layout_height="wrap_content"
before the video is loaded their values are 0 to solve this problem can use set minHeight to 1dp and layout_width to match_parent and this will do the trick, you do not need fixed width and height.
I was stuck on this for far too long as well. After searching everywhere and still struggling I looked at my older code base with the exact same code bar one difference. The VideoView
was having its height programatically set. android:layout_height="wrap_content"
doesn't appear to make a height adjustment.
So I used a self made utility method to get the screen width and set the height to be in a 16:9 ratio like so. (Maybe just set your height and width to some arbitrary numbers first to see if it's the issue)
public static int getScreenWidth(Context c) {
int screenWidth = 0; // this is part of the class not the method
if (screenWidth == 0) {
WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
screenWidth = size.x;
}
return screenWidth;
}
Then all it takes is to set the VideoViews height as such
holder.mVideoView.getLayoutParams().height = getScreenWidth(mContext) * 9 /16;
NOTE: My width is set to match_parent
, so wrap_content
may also fail there too.
Hope this helps.