问题
On iOS/TVOS, is it possible to load a remote .vtt file from a URL and use it as a subtitle track with a remote HLS video also loaded from a URL (as opposed to the VTT being specified within the m3u8 playlist)?
pseudocode:
AVAsset* video_asset = AVAsset( "http://video.m3u8" );
AVAsset* subtitle_asset = AVAsset( "http://subtitle.vtt" );
AVPlayer player = player.playVideoWithSubtitle( video_asset, subtitle_asset );
player.play().
Edit:
The docs mention using AVAsset for subtitles, but does anyone actually have an example? I can only find examples regarding adding strings as subtitles rather than loading a remote VTT.
回答1:
I've posted a solution over here: https://stackoverflow.com/a/37945178/171933 Basically you need to use an AVMutableComposition
to join the video with the subtitles and then play back that composition.
回答2:
According to the docs, this is possible
AVAsset is an abstract class to represent timed audiovisual media such as videos and sounds. Each asset contains a collection of tracks that are intended to be presented or processed together, each of a uniform media type, including but not limited to audio, video, text, closed captions, and subtitles.
You should use AVMutableComposition
to combine assets then. You would combine asset with the video with an asset with subtitles. Docs:
You can insert AVAsset objects into an AVMutableComposition object in order to assemble audiovisual constructs from one or more source assets.
来源:https://stackoverflow.com/questions/35879678/avurlasset-and-webvtts