in eCommerce/Views/Player/PlayerView.swift [360:382]
func player(_ player: IVSPlayer, didOutputCue cue: IVSCue) {
switch cue {
case let textMetadataCue as IVSTextMetadataCue:
print("ℹ Received Timed Metadata (\(textMetadataCue.textDescription)): \(textMetadataCue.text)")
guard let jsonData = textMetadataCue.text.data(using: .utf8) else {
return
}
do {
let json = try jsonDecoder.decode([String: String].self, from: jsonData)
if let id = json["productId"], let product = products.first(where: { $0.id == id }) {
if receivedProductsLine.last != product {
receivedProductsLine.append(product)
}
}
} catch {
print("Could not decode productId: \(error)")
}
case let textCue as IVSTextCue:
print("ℹ Received Text Cue: “\(textCue.text)”")
default:
print("ℹ Received unknown cue (type \(cue.type))")
}
}