Skip to content

Commit 2de92e6

Browse files
committed
feat: adjustable subtitle position
close #426
1 parent 4d50c77 commit 2de92e6

25 files changed

+129
-23
lines changed

android/app/src/main/kotlin/com/edde746/plezy/exoplayer/ExoPlayerCore.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

android/app/src/main/kotlin/com/edde746/plezy/exoplayer/ExoPlayerPlugin.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,15 @@ class ExoPlayerPlugin : FlutterPlugin, MethodChannel.MethodCallHandler,
419419
val borderColor = call.argument<String>("borderColor") ?: "#000000"
420420
val bgColor = call.argument<String>("bgColor") ?: "#000000"
421421
val bgOpacity = call.argument<Number>("bgOpacity")?.toInt() ?: 0
422+
val subtitlePosition = call.argument<Number>("subtitlePosition")?.toInt() ?: 100
422423

423424
if (usingMpvFallback) {
424425
// MPV fallback handles styling via setProperty, no-op here
425426
result.success(null)
426427
return
427428
}
428429

429-
playerCore?.setSubtitleStyle(fontSize, textColor, borderSize, borderColor, bgColor, bgOpacity)
430+
playerCore?.setSubtitleStyle(fontSize, textColor, borderSize, borderColor, bgColor, bgOpacity, subtitlePosition)
430431
result.success(null)
431432
}
432433

lib/i18n/de.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"borderSize": "Rahmengröße",
366366
"borderColor": "Rahmenfarbe",
367367
"backgroundOpacity": "Hintergrunddeckkraft",
368-
"backgroundColor": "Hintergrundfarbe"
368+
"backgroundColor": "Hintergrundfarbe",
369+
"position": "Position"
369370
},
370371
"mpvConfig": {
371372
"title": "MPV-Konfiguration",

lib/i18n/en.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"borderSize": "Border Size",
366366
"borderColor": "Border Color",
367367
"backgroundOpacity": "Background Opacity",
368-
"backgroundColor": "Background Color"
368+
"backgroundColor": "Background Color",
369+
"position": "Position"
369370
},
370371
"mpvConfig": {
371372
"title": "MPV Configuration",

lib/i18n/es.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"borderSize": "Tamaño de Borde",
366366
"borderColor": "Color de Borde",
367367
"backgroundOpacity": "Opacidad de Fondo",
368-
"backgroundColor": "Color de Fondo"
368+
"backgroundColor": "Color de Fondo",
369+
"position": "Position"
369370
},
370371
"mpvConfig": {
371372
"title": "Configuración de MPV",

lib/i18n/fr.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"borderSize": "Taille de la bordure",
366366
"borderColor": "Couleur de la bordure",
367367
"backgroundOpacity": "Opacité d'arrière-plan",
368-
"backgroundColor": "Couleur d'arrière-plan"
368+
"backgroundColor": "Couleur d'arrière-plan",
369+
"position": "Position"
369370
},
370371
"mpvConfig": {
371372
"title": "Configuration MPV",

lib/i18n/it.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"borderSize": "Dimensione bordo",
366366
"borderColor": "Colore bordo",
367367
"backgroundOpacity": "Opacità sfondo",
368-
"backgroundColor": "Colore sfondo"
368+
"backgroundColor": "Colore sfondo",
369+
"position": "Position"
369370
},
370371
"mpvConfig": {
371372
"title": "Configurazione MPV",

lib/i18n/ko.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"borderSize": "테두리 크기",
366366
"borderColor": "테두리 색상",
367367
"backgroundOpacity": "배경 불투명도",
368-
"backgroundColor": "배경색"
368+
"backgroundColor": "배경색",
369+
"position": "Position"
369370
},
370371
"mpvConfig": {
371372
"title": "MPV 설정",

lib/i18n/nl.i18n.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@
365365
"borderSize": "Rand grootte",
366366
"borderColor": "Randkleur",
367367
"backgroundOpacity": "Achtergrond transparantie",
368-
"backgroundColor": "Achtergrondkleur"
368+
"backgroundColor": "Achtergrondkleur",
369+
"position": "Position"
369370
},
370371
"mpvConfig": {
371372
"title": "MPV-configuratie",

lib/i18n/strings.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
/// To regenerate, run: `dart run slang`
55
///
66
/// Locales: 9
7-
/// Strings: 5121 (569 per locale)
7+
/// Strings: 5130 (570 per locale)
88
///
9-
/// Built on 2026-02-08 at 11:03 UTC
9+
/// Built on 2026-02-09 at 17:54 UTC
1010
1111
// coverage:ignore-file
1212
// ignore_for_file: type=lint, unused_import

0 commit comments

Comments
 (0)