Trouble getting video to play on Recyclerview

前端 未结 2 782
北恋
北恋 2021-02-06 09:52

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

相关标签:
2条回答
  • 2021-02-06 10:26

    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.

    0 讨论(0)
  • 2021-02-06 10:48

    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.

    0 讨论(0)
提交回复
热议问题