@@ -47,7 +47,8 @@ class SwitchableGlobalPlayer {
4747 StreamSubscription <double ?>? _volumeSubscription;
4848 StreamSubscription <bool >? _isCompleteSubscription;
4949 StreamSubscription <PiPStatus >? _pipSubscription;
50-
50+ double _realWidth = 0 ;
51+ double _realHeight = 0 ;
5152 // Getter(安全访问)
5253 UnifiedPlayer ? get currentPlayer => _currentPlayer;
5354
@@ -154,16 +155,39 @@ class SwitchableGlobalPlayer {
154155 );
155156 }
156157
158+ double get _currentVideoRatio {
159+ // 使用缓存的真实宽高进行判断
160+ if (_realWidth > 0 && _realHeight > 0 ) {
161+ return _realWidth / _realHeight;
162+ }
163+ // 如果视频尚未解析出宽高,使用保底比例
164+ return isVerticalVideo.value ? (9 / 16 ) : (16 / 9 );
165+ }
166+
157167 void showAppFloating (LiveRoom room) {
158168 floatingManager.disposeFloating (_floatTag);
159- double baseWidth = Platform .isWindows ? 300.0 : 200.0 ;
160- double ratio = isVerticalVideo.value ? (9 / 16 ) : (16 / 9 );
161- double floatHeight = baseWidth / ratio;
169+ double maxSide = Platform .isWindows ? 350.0 : 220.0 ;
170+
171+ double ratio = _currentVideoRatio;
172+ double floatWidth;
173+ double floatHeight;
174+
175+ if (ratio >= 1 ) {
176+ floatWidth = maxSide;
177+ floatHeight = maxSide / ratio;
178+ } else {
179+ floatHeight = maxSide * 1.2 ;
180+ floatWidth = floatHeight * ratio;
181+ if (floatWidth < 120 ) {
182+ floatWidth = 120 ;
183+ floatHeight = floatWidth / ratio;
184+ }
185+ }
162186 floatingManager.createFloating (
163187 _floatTag,
164188 FloatingOverlay (
165189 Container (
166- width: baseWidth ,
190+ width: floatWidth ,
167191 height: floatHeight,
168192 clipBehavior: Clip .antiAlias,
169193 decoration: BoxDecoration (
@@ -343,7 +367,12 @@ class SwitchableGlobalPlayer {
343367 final orientationStream = CombineLatestStream .combine2 <int ?, int ?, bool >(
344368 width.where ((w) => w != null && w > 0 ),
345369 height.where ((h) => h != null && h > 0 ),
346- (w, h) => h! >= w! ,
370+ (w, h) {
371+ _realWidth = w! .toDouble ();
372+ _realHeight = h! .toDouble ();
373+
374+ return _realHeight >= _realWidth;
375+ },
347376 );
348377
349378 _orientationSubscription = orientationStream.listen ((isVertical) {
0 commit comments