mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-02-03 19:22:32 +00:00
feat(mpv): add opaque subtitle background with adjustable opacity (iOS only)
This commit is contained in:
@@ -195,7 +195,8 @@ final class MPVLayerRenderer {
|
||||
// CRITICAL: This option MUST be set immediately after vo=avfoundation, before hwdec options.
|
||||
// On tvOS, moving this elsewhere causes the app to freeze when exiting the player.
|
||||
// - iOS: "yes" for PiP subtitle support (subtitles baked into video)
|
||||
// - tvOS: "no" to prevent gray tint + frame drops with subtitles
|
||||
// - tvOS: "no" - composite OSD breaks subtitle rendering entirely on tvOS
|
||||
// Note: This means subtitle styling (background colors) won't work on tvOS
|
||||
#if os(tvOS)
|
||||
checkError(mpv_set_option_string(handle, "avfoundation-composite-osd", "no"))
|
||||
#else
|
||||
@@ -820,7 +821,22 @@ final class MPVLayerRenderer {
|
||||
func setSubtitleFontSize(_ size: Int) {
|
||||
setProperty(name: "sub-font-size", value: String(size))
|
||||
}
|
||||
|
||||
|
||||
func setSubtitleBackgroundColor(_ color: String) {
|
||||
setProperty(name: "sub-back-color", value: color)
|
||||
}
|
||||
|
||||
func setSubtitleBorderStyle(_ style: String) {
|
||||
// "outline-and-shadow" (default) or "background-box" (enables background color)
|
||||
setProperty(name: "sub-border-style", value: style)
|
||||
}
|
||||
|
||||
func setSubtitleAssOverride(_ mode: String) {
|
||||
// Controls whether to override ASS subtitle styles
|
||||
// "no" = keep ASS styles, "force" = override with user settings
|
||||
setProperty(name: "sub-ass-override", value: mode)
|
||||
}
|
||||
|
||||
// MARK: - Audio Track Controls
|
||||
|
||||
func getAudioTracks() -> [[String: Any]] {
|
||||
|
||||
@@ -157,7 +157,19 @@ public class MpvPlayerModule: Module {
|
||||
AsyncFunction("setSubtitleFontSize") { (view: MpvPlayerView, size: Int) in
|
||||
view.setSubtitleFontSize(size)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("setSubtitleBackgroundColor") { (view: MpvPlayerView, color: String) in
|
||||
view.setSubtitleBackgroundColor(color)
|
||||
}
|
||||
|
||||
AsyncFunction("setSubtitleBorderStyle") { (view: MpvPlayerView, style: String) in
|
||||
view.setSubtitleBorderStyle(style)
|
||||
}
|
||||
|
||||
AsyncFunction("setSubtitleAssOverride") { (view: MpvPlayerView, mode: String) in
|
||||
view.setSubtitleAssOverride(mode)
|
||||
}
|
||||
|
||||
// Audio track functions
|
||||
AsyncFunction("getAudioTracks") { (view: MpvPlayerView) -> [[String: Any]] in
|
||||
return view.getAudioTracks()
|
||||
|
||||
@@ -319,6 +319,18 @@ class MpvPlayerView: ExpoView {
|
||||
renderer?.setSubtitleFontSize(size)
|
||||
}
|
||||
|
||||
func setSubtitleBackgroundColor(_ color: String) {
|
||||
renderer?.setSubtitleBackgroundColor(color)
|
||||
}
|
||||
|
||||
func setSubtitleBorderStyle(_ style: String) {
|
||||
renderer?.setSubtitleBorderStyle(style)
|
||||
}
|
||||
|
||||
func setSubtitleAssOverride(_ mode: String) {
|
||||
renderer?.setSubtitleAssOverride(mode)
|
||||
}
|
||||
|
||||
// MARK: - Video Scaling
|
||||
|
||||
func setZoomedToFill(_ zoomed: Bool) {
|
||||
|
||||
@@ -95,6 +95,11 @@ export interface MpvPlayerViewRef {
|
||||
setSubtitleAlignX: (alignment: "left" | "center" | "right") => Promise<void>;
|
||||
setSubtitleAlignY: (alignment: "top" | "center" | "bottom") => Promise<void>;
|
||||
setSubtitleFontSize: (size: number) => Promise<void>;
|
||||
setSubtitleBackgroundColor: (color: string) => Promise<void>;
|
||||
setSubtitleBorderStyle: (
|
||||
style: "outline-and-shadow" | "background-box",
|
||||
) => Promise<void>;
|
||||
setSubtitleAssOverride: (mode: "no" | "force") => Promise<void>;
|
||||
// Audio controls
|
||||
getAudioTracks: () => Promise<AudioTrack[]>;
|
||||
setAudioTrack: (trackId: number) => Promise<void>;
|
||||
|
||||
@@ -84,6 +84,17 @@ export default React.forwardRef<MpvPlayerViewRef, MpvPlayerViewProps>(
|
||||
setSubtitleFontSize: async (size: number) => {
|
||||
await nativeRef.current?.setSubtitleFontSize(size);
|
||||
},
|
||||
setSubtitleBackgroundColor: async (color: string) => {
|
||||
await nativeRef.current?.setSubtitleBackgroundColor(color);
|
||||
},
|
||||
setSubtitleBorderStyle: async (
|
||||
style: "outline-and-shadow" | "background-box",
|
||||
) => {
|
||||
await nativeRef.current?.setSubtitleBorderStyle(style);
|
||||
},
|
||||
setSubtitleAssOverride: async (mode: "no" | "force") => {
|
||||
await nativeRef.current?.setSubtitleAssOverride(mode);
|
||||
},
|
||||
// Audio controls
|
||||
getAudioTracks: async () => {
|
||||
return await nativeRef.current?.getAudioTracks();
|
||||
|
||||
Reference in New Issue
Block a user