@@ -858,7 +858,8 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
858858 borderSize : Float ,
859859 borderColor : String ,
860860 bgColor : String ,
861- bgOpacity : Int
861+ bgOpacity : Int ,
862+ subtitlePosition : Int = 100
862863 ) {
863864 activity.runOnUiThread {
864865 // 1. Non-ASS subtitles: CaptionStyleCompat on SubtitleView
@@ -885,6 +886,25 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
885886 val fraction = fontSize / 720f
886887 subtitleView?.setFractionalTextSize(fraction)
887888
889+ // Subtitle position: adjust gravity and bottom padding
890+ val clampedPosition = subtitlePosition.coerceIn(0 , 100 )
891+ val gravity = when {
892+ clampedPosition <= 33 -> Gravity .TOP
893+ clampedPosition <= 66 -> Gravity .CENTER
894+ else -> Gravity .BOTTOM
895+ }
896+ (subtitleView?.layoutParams as ? FrameLayout .LayoutParams )?.let { params ->
897+ params.gravity = gravity or Gravity .CENTER_HORIZONTAL
898+ subtitleView?.layoutParams = params
899+ }
900+ // Fine-grained positioning within bottom region via bottom padding fraction
901+ if (clampedPosition > 66 ) {
902+ val bottomFraction = (100 - clampedPosition) / 100f
903+ subtitleView?.setBottomPaddingFraction(bottomFraction)
904+ } else {
905+ subtitleView?.setBottomPaddingFraction(0f )
906+ }
907+
888908 // 2. ASS subtitles: font scale via libass
889909 // MPV default sub-font-size is 38
890910 val defaultSize = 38f
@@ -895,7 +915,7 @@ class ExoPlayerCore(private val activity: Activity) : Player.Listener {
895915 Log .w(TAG , " Failed to set ASS font scale: ${e.message} " )
896916 }
897917
898- Log .d(TAG , " setSubtitleStyle: fontSize=$fontSize , textColor=$textColor , borderSize=$borderSize , bgOpacity=$bgOpacity , assScale=$scale " )
918+ Log .d(TAG , " setSubtitleStyle: fontSize=$fontSize , textColor=$textColor , borderSize=$borderSize , bgOpacity=$bgOpacity , position= $subtitlePosition , assScale=$scale " )
899919 }
900920 }
901921
0 commit comments