@@ -87,12 +87,19 @@ public void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
8787 heightMeasureSpec = tempSpec ;
8888 }
8989
90- int width = View .getDefaultSize (mVideoWidth , widthMeasureSpec );
90+ int realWidth = mVideoWidth ;
91+
92+ if (mVideoSarNum != 0 && mVideoSarDen != 0 ) {
93+ double pixelWidthHeightRatio = mVideoSarNum / (mVideoSarDen / 1.0 );
94+ realWidth = (int ) (pixelWidthHeightRatio * mVideoWidth );
95+ }
96+
97+ int width = View .getDefaultSize (realWidth , widthMeasureSpec );
9198 int height = View .getDefaultSize (mVideoHeight , heightMeasureSpec );
9299 if (mCurrentAspectRatio == GSYVideoType .SCREEN_MATCH_FULL ) {
93100 width = widthMeasureSpec ;
94101 height = heightMeasureSpec ;
95- } else if (mVideoWidth > 0 && mVideoHeight > 0 ) {
102+ } else if (realWidth > 0 && mVideoHeight > 0 ) {
96103 int widthSpecMode = View .MeasureSpec .getMode (widthMeasureSpec );
97104 int widthSpecSize = View .MeasureSpec .getSize (widthMeasureSpec );
98105 int heightSpecMode = View .MeasureSpec .getMode (heightMeasureSpec );
@@ -126,7 +133,7 @@ public void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
126133 case GSYVideoType .SCREEN_TYPE_FULL :
127134 //case GSYVideoType.AR_ASPECT_WRAP_CONTENT:
128135 default :
129- displayAspectRatio = (float ) mVideoWidth / (float ) mVideoHeight ;
136+ displayAspectRatio = (float ) realWidth / (float ) mVideoHeight ;
130137 if (mVideoSarNum > 0 && mVideoSarDen > 0 )
131138 displayAspectRatio = displayAspectRatio * mVideoSarNum / mVideoSarDen ;
132139 break ;
@@ -164,7 +171,7 @@ public void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
164171 default :
165172 if (shouldBeWider ) {
166173 // too wide, fix width
167- width = Math .min (mVideoWidth , widthSpecSize );
174+ width = Math .min (realWidth , widthSpecSize );
168175 height = (int ) (width / displayAspectRatio );
169176 } else {
170177 // too high, fix height
@@ -179,42 +186,42 @@ public void doMeasure(int widthMeasureSpec, int heightMeasureSpec) {
179186 height = heightSpecSize ;
180187
181188 // for compatibility, we adjust size based on aspect ratio
182- if (mVideoWidth * height < width * mVideoHeight ) {
189+ if (realWidth * height < width * mVideoHeight ) {
183190 //Log.i("@@@", "image too wide, correcting");
184- width = height * mVideoWidth / mVideoHeight ;
185- } else if (mVideoWidth * height > width * mVideoHeight ) {
191+ width = height * realWidth / mVideoHeight ;
192+ } else if (realWidth * height > width * mVideoHeight ) {
186193 //Log.i("@@@", "image too tall, correcting");
187- height = width * mVideoHeight / mVideoWidth ;
194+ height = width * mVideoHeight / realWidth ;
188195 }
189196 } else if (widthSpecMode == View .MeasureSpec .EXACTLY ) {
190197 // only the width is fixed, adjust the height to match aspect ratio if possible
191198 width = widthSpecSize ;
192- height = width * mVideoHeight / mVideoWidth ;
199+ height = width * mVideoHeight / realWidth ;
193200 if (heightSpecMode == View .MeasureSpec .AT_MOST && height > heightSpecSize ) {
194201 // couldn't match aspect ratio within the constraints
195202 height = heightSpecSize ;
196203 }
197204 } else if (heightSpecMode == View .MeasureSpec .EXACTLY ) {
198205 // only the height is fixed, adjust the width to match aspect ratio if possible
199206 height = heightSpecSize ;
200- width = height * mVideoWidth / mVideoHeight ;
207+ width = height * realWidth / mVideoHeight ;
201208 if (widthSpecMode == View .MeasureSpec .AT_MOST && width > widthSpecSize ) {
202209 // couldn't match aspect ratio within the constraints
203210 width = widthSpecSize ;
204211 }
205212 } else {
206213 // neither the width nor the height are fixed, try to use actual video size
207- width = mVideoWidth ;
214+ width = realWidth ;
208215 height = mVideoHeight ;
209216 if (heightSpecMode == View .MeasureSpec .AT_MOST && height > heightSpecSize ) {
210217 // too tall, decrease both width and height
211218 height = heightSpecSize ;
212- width = height * mVideoWidth / mVideoHeight ;
219+ width = height * realWidth / mVideoHeight ;
213220 }
214221 if (widthSpecMode == View .MeasureSpec .AT_MOST && width > widthSpecSize ) {
215222 // too wide, decrease both width and height
216223 width = widthSpecSize ;
217- height = width * mVideoHeight / mVideoWidth ;
224+ height = width * mVideoHeight / realWidth ;
218225 }
219226 }
220227 } else {
0 commit comments