Cue
@objcMembers
@objc(BMPCue)
public class Cue : NSObject, NSCopying, @unchecked Sendable
Describes a subtitle cue.
-
The start time of the cue in seconds
Declaration
Swift
public var startTime: TimeInterval
-
The end time of the cue in seconds
Declaration
Swift
public var endTime: TimeInterval
-
The cue text as HTML
Declaration
Swift
public var html: String?
-
The cue text
Declaration
Swift
public var text: String?
-
The original raw text of the cue, as written in the caption file
Limitations:
- For in-manifest subtitle tracks, it will always have the same value as
Cue.text
.
Declaration
Swift
public var rawText: String?
- For in-manifest subtitle tracks, it will always have the same value as
-
The formatted text content of the cue.
This property provides the cue’s text content with attributes in the
UIKitAttributes
format, making it directly usable with UIKit and SwiftUI components that support attributed strings.The supported styles include:
- Foreground color (text color)
- Background color (of the character)
- Underline style
- Italic text style
- Bold text style
Limitation:
- Side-loaded subtitles: for side-loaded subtitles, only color attributes (foreground and background) are supported. Font-related attributes and underline styles are not available for these types of subtitles.
- One font-related attribute at a time: having multiple font-related attributes (italic and bold styles) on the same range is not supported. In this case, only one attribute will be applied.
Usage Example:
import SwiftUI // Use in a SwiftUI `Text` view guard let attributedText = cueEvent.attributedText else { return } Text(AttributedString(attributedText))
Compatibility:
- UIKit: Directly use the
NSAttributedString
withUILabel
,UITextView
, or other UIKit components. - SwiftUI: Convert the
NSAttributedString
toAttributedString
using SwiftUI’s built-in support withAttributedString(attributedText)
, as shown in the usage example above.
Troubleshooting:
- SwiftUI: If the formatting is not working, try scoping the attributes to keep during the conversion:
swift try AttributedString(attributedText, including: \.uiKit)
Declaration
Swift
public var attributedText: NSAttributedString?
-
The cue image
Declaration
Swift
public var image: UIImage?
-
The position of the cue. Only relevant for CEA-captions, provides information about where the cue should be positioned on a grid of 15 character rows times 32 columns
Declaration
Swift
public var position: CuePosition?
-
The region of the cue
Declaration
Swift
public var region: String?
-
The region style of the cue
Declaration
Swift
public var regionStyle: String?
-
The VTT positioning properties for this cue
Declaration
Swift
public var vtt: VttProperties?
-
init(startTime:
endTime: html: text: rawText: attributedText: image: position: region: regionStyle: vttProperties: ) Declaration
Swift
public init( startTime: TimeInterval, endTime: TimeInterval, html: String? = nil, text: String? = nil, rawText: String? = nil, attributedText: NSAttributedString? = nil, image: UIImage? = nil, position: CuePosition? = nil, region: String? = nil, regionStyle: String? = nil, vttProperties: VttProperties? = nil )
Parameters
startTime
The start time of the cue in seconds
endTime
The end time of the cue in seconds
html
The cue text as HTML
text
The cue text
rawText
The original raw text of the cue, as written in the caption file
attributedText
The formatted text content of the cue
image
The cue image
position
The position of the cue. Only relevant for CEA captions
region
The region of the cue
regionStyle
The region style of the cue
vttProperties
The VTT positioning properties for this cue
Return Value
A new subtitle cue