问题
The Chromecast developer docs say both WebVTT and TTML are Supported Media Types: https://developers.google.com/cast/supported_media_types
I see captions when using a WebVTT file in a "track" tag within a video element:
<video id="vid" src="http://myurl">
<track kind="captions" src="http://10.16.236.23/test.vtt" srclang="en" label="English" default>
</video>
But when I try to do the same using a valid TTML file, I don't see captions:
<video id="vid" src="http://myurl">
<track kind="captions" src="test.ttml" srclang="en" label="English" default>
</video>
When I inspect the video element in the debugger console, for the WebVTT example I can see
document.getElementById('vid').textTracks[0].cues.length;
16
but for TTML:
document.getElementById('vid').textTracks[0].cues.length;
0
I am on the right track with this or is TTML supported in a different way? Maybe my TTML syntax is not supported by Chromecast?
回答1:
Unlike webVTT, TTML is not natively supported. If you need to support that in your app, you can simply write a Javascript parser to parse the file and add the cues to your video element in javascript using methods such as addTextTrack(), etc.
回答2:
According to the Cast Player API, Chromecast now supports WebVTT, TTML1, and CEA-608 (Line 21 Captions) caption formats. Just pass in the CaptionsType
enum for your caption format into the player's enableCaptions() method.
来源:https://stackoverflow.com/questions/19572313/does-chromecast-support-ttml