iostvoswebvtt

AVUrlAsset and WebVTTs


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.


Solution

  • 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.