├── .gitignore ├── External WebVTT Example.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── External WebVTT Example ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── CustomResourceLoaderDelegate.swift ├── CustomVTTPlayer.swift ├── Info.plist └── ViewController.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /External WebVTT Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 638330D8219F16B50063E39E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638330D7219F16B50063E39E /* AppDelegate.swift */; }; 11 | 638330DA219F16B50063E39E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638330D9219F16B50063E39E /* ViewController.swift */; }; 12 | 638330DD219F16B50063E39E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 638330DB219F16B50063E39E /* Main.storyboard */; }; 13 | 638330DF219F16B60063E39E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 638330DE219F16B60063E39E /* Assets.xcassets */; }; 14 | 638330E2219F16B60063E39E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 638330E0219F16B60063E39E /* LaunchScreen.storyboard */; }; 15 | 638330EA219F174C0063E39E /* CustomVTTPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 638330E9219F174C0063E39E /* CustomVTTPlayer.swift */; }; 16 | 63A454FD21FA26A00092E1C4 /* CustomResourceLoaderDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63A454FC21FA26A00092E1C4 /* CustomResourceLoaderDelegate.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 638330D4219F16B50063E39E /* External WebVTT Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "External WebVTT Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 638330D7219F16B50063E39E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 638330D9219F16B50063E39E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | 638330DC219F16B50063E39E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | 638330DE219F16B60063E39E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 638330E1219F16B60063E39E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | 638330E3219F16B60063E39E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | 638330E9219F174C0063E39E /* CustomVTTPlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomVTTPlayer.swift; sourceTree = ""; }; 28 | 63A454FC21FA26A00092E1C4 /* CustomResourceLoaderDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomResourceLoaderDelegate.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 638330D1219F16B50063E39E /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 638330CB219F16B50063E39E = { 43 | isa = PBXGroup; 44 | children = ( 45 | 638330D6219F16B50063E39E /* External WebVTT Example */, 46 | 638330D5219F16B50063E39E /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 638330D5219F16B50063E39E /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 638330D4219F16B50063E39E /* External WebVTT Example.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 638330D6219F16B50063E39E /* External WebVTT Example */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 638330E9219F174C0063E39E /* CustomVTTPlayer.swift */, 62 | 638330D7219F16B50063E39E /* AppDelegate.swift */, 63 | 638330D9219F16B50063E39E /* ViewController.swift */, 64 | 638330DB219F16B50063E39E /* Main.storyboard */, 65 | 638330DE219F16B60063E39E /* Assets.xcassets */, 66 | 638330E0219F16B60063E39E /* LaunchScreen.storyboard */, 67 | 638330E3219F16B60063E39E /* Info.plist */, 68 | 63A454FC21FA26A00092E1C4 /* CustomResourceLoaderDelegate.swift */, 69 | ); 70 | path = "External WebVTT Example"; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | 638330D3219F16B50063E39E /* External WebVTT Example */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = 638330E6219F16B60063E39E /* Build configuration list for PBXNativeTarget "External WebVTT Example" */; 79 | buildPhases = ( 80 | 638330D0219F16B50063E39E /* Sources */, 81 | 638330D1219F16B50063E39E /* Frameworks */, 82 | 638330D2219F16B50063E39E /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = "External WebVTT Example"; 89 | productName = "External WebVTT Example"; 90 | productReference = 638330D4219F16B50063E39E /* External WebVTT Example.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | 638330CC219F16B50063E39E /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | LastSwiftUpdateCheck = 1010; 100 | LastUpgradeCheck = 1010; 101 | ORGANIZATIONNAME = "Joris Weimar"; 102 | TargetAttributes = { 103 | 638330D3219F16B50063E39E = { 104 | CreatedOnToolsVersion = 10.1; 105 | }; 106 | }; 107 | }; 108 | buildConfigurationList = 638330CF219F16B50063E39E /* Build configuration list for PBXProject "External WebVTT Example" */; 109 | compatibilityVersion = "Xcode 9.3"; 110 | developmentRegion = en; 111 | hasScannedForEncodings = 0; 112 | knownRegions = ( 113 | en, 114 | Base, 115 | ); 116 | mainGroup = 638330CB219F16B50063E39E; 117 | productRefGroup = 638330D5219F16B50063E39E /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | 638330D3219F16B50063E39E /* External WebVTT Example */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXResourcesBuildPhase section */ 127 | 638330D2219F16B50063E39E /* Resources */ = { 128 | isa = PBXResourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | 638330E2219F16B60063E39E /* LaunchScreen.storyboard in Resources */, 132 | 638330DF219F16B60063E39E /* Assets.xcassets in Resources */, 133 | 638330DD219F16B50063E39E /* Main.storyboard in Resources */, 134 | ); 135 | runOnlyForDeploymentPostprocessing = 0; 136 | }; 137 | /* End PBXResourcesBuildPhase section */ 138 | 139 | /* Begin PBXSourcesBuildPhase section */ 140 | 638330D0219F16B50063E39E /* Sources */ = { 141 | isa = PBXSourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | 638330EA219F174C0063E39E /* CustomVTTPlayer.swift in Sources */, 145 | 638330DA219F16B50063E39E /* ViewController.swift in Sources */, 146 | 63A454FD21FA26A00092E1C4 /* CustomResourceLoaderDelegate.swift in Sources */, 147 | 638330D8219F16B50063E39E /* AppDelegate.swift in Sources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXSourcesBuildPhase section */ 152 | 153 | /* Begin PBXVariantGroup section */ 154 | 638330DB219F16B50063E39E /* Main.storyboard */ = { 155 | isa = PBXVariantGroup; 156 | children = ( 157 | 638330DC219F16B50063E39E /* Base */, 158 | ); 159 | name = Main.storyboard; 160 | sourceTree = ""; 161 | }; 162 | 638330E0219F16B60063E39E /* LaunchScreen.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 638330E1219F16B60063E39E /* Base */, 166 | ); 167 | name = LaunchScreen.storyboard; 168 | sourceTree = ""; 169 | }; 170 | /* End PBXVariantGroup section */ 171 | 172 | /* Begin XCBuildConfiguration section */ 173 | 638330E4219F16B60063E39E /* Debug */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | CLANG_ANALYZER_NONNULL = YES; 178 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 179 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 180 | CLANG_CXX_LIBRARY = "libc++"; 181 | CLANG_ENABLE_MODULES = YES; 182 | CLANG_ENABLE_OBJC_ARC = YES; 183 | CLANG_ENABLE_OBJC_WEAK = YES; 184 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_COMMA = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 190 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 191 | CLANG_WARN_EMPTY_BODY = YES; 192 | CLANG_WARN_ENUM_CONVERSION = YES; 193 | CLANG_WARN_INFINITE_RECURSION = YES; 194 | CLANG_WARN_INT_CONVERSION = YES; 195 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 197 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 198 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 199 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 200 | CLANG_WARN_STRICT_PROTOTYPES = YES; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | CODE_SIGN_IDENTITY = "iPhone Developer"; 206 | COPY_PHASE_STRIP = NO; 207 | DEBUG_INFORMATION_FORMAT = dwarf; 208 | ENABLE_STRICT_OBJC_MSGSEND = YES; 209 | ENABLE_TESTABILITY = YES; 210 | GCC_C_LANGUAGE_STANDARD = gnu11; 211 | GCC_DYNAMIC_NO_PIC = NO; 212 | GCC_NO_COMMON_BLOCKS = YES; 213 | GCC_OPTIMIZATION_LEVEL = 0; 214 | GCC_PREPROCESSOR_DEFINITIONS = ( 215 | "DEBUG=1", 216 | "$(inherited)", 217 | ); 218 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 219 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 220 | GCC_WARN_UNDECLARED_SELECTOR = YES; 221 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 222 | GCC_WARN_UNUSED_FUNCTION = YES; 223 | GCC_WARN_UNUSED_VARIABLE = YES; 224 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 225 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 226 | MTL_FAST_MATH = YES; 227 | ONLY_ACTIVE_ARCH = YES; 228 | SDKROOT = iphoneos; 229 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 230 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 231 | }; 232 | name = Debug; 233 | }; 234 | 638330E5219F16B60063E39E /* Release */ = { 235 | isa = XCBuildConfiguration; 236 | buildSettings = { 237 | ALWAYS_SEARCH_USER_PATHS = NO; 238 | CLANG_ANALYZER_NONNULL = YES; 239 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 240 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 241 | CLANG_CXX_LIBRARY = "libc++"; 242 | CLANG_ENABLE_MODULES = YES; 243 | CLANG_ENABLE_OBJC_ARC = YES; 244 | CLANG_ENABLE_OBJC_WEAK = YES; 245 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 246 | CLANG_WARN_BOOL_CONVERSION = YES; 247 | CLANG_WARN_COMMA = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 250 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 251 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 252 | CLANG_WARN_EMPTY_BODY = YES; 253 | CLANG_WARN_ENUM_CONVERSION = YES; 254 | CLANG_WARN_INFINITE_RECURSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 257 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 258 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 259 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 260 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 261 | CLANG_WARN_STRICT_PROTOTYPES = YES; 262 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 263 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 264 | CLANG_WARN_UNREACHABLE_CODE = YES; 265 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 266 | CODE_SIGN_IDENTITY = "iPhone Developer"; 267 | COPY_PHASE_STRIP = NO; 268 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 269 | ENABLE_NS_ASSERTIONS = NO; 270 | ENABLE_STRICT_OBJC_MSGSEND = YES; 271 | GCC_C_LANGUAGE_STANDARD = gnu11; 272 | GCC_NO_COMMON_BLOCKS = YES; 273 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 274 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 275 | GCC_WARN_UNDECLARED_SELECTOR = YES; 276 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 277 | GCC_WARN_UNUSED_FUNCTION = YES; 278 | GCC_WARN_UNUSED_VARIABLE = YES; 279 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 280 | MTL_ENABLE_DEBUG_INFO = NO; 281 | MTL_FAST_MATH = YES; 282 | SDKROOT = iphoneos; 283 | SWIFT_COMPILATION_MODE = wholemodule; 284 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 285 | VALIDATE_PRODUCT = YES; 286 | }; 287 | name = Release; 288 | }; 289 | 638330E7219F16B60063E39E /* Debug */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 293 | CODE_SIGN_STYLE = Automatic; 294 | DEVELOPMENT_TEAM = V66EK59R3L; 295 | INFOPLIST_FILE = "External WebVTT Example/Info.plist"; 296 | LD_RUNPATH_SEARCH_PATHS = ( 297 | "$(inherited)", 298 | "@executable_path/Frameworks", 299 | ); 300 | PRODUCT_BUNDLE_IDENTIFIER = "com.clavicode.External-WebVTT-Example"; 301 | PRODUCT_NAME = "$(TARGET_NAME)"; 302 | SWIFT_VERSION = 4.2; 303 | TARGETED_DEVICE_FAMILY = "1,2"; 304 | }; 305 | name = Debug; 306 | }; 307 | 638330E8219F16B60063E39E /* Release */ = { 308 | isa = XCBuildConfiguration; 309 | buildSettings = { 310 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 311 | CODE_SIGN_STYLE = Automatic; 312 | DEVELOPMENT_TEAM = V66EK59R3L; 313 | INFOPLIST_FILE = "External WebVTT Example/Info.plist"; 314 | LD_RUNPATH_SEARCH_PATHS = ( 315 | "$(inherited)", 316 | "@executable_path/Frameworks", 317 | ); 318 | PRODUCT_BUNDLE_IDENTIFIER = "com.clavicode.External-WebVTT-Example"; 319 | PRODUCT_NAME = "$(TARGET_NAME)"; 320 | SWIFT_VERSION = 4.2; 321 | TARGETED_DEVICE_FAMILY = "1,2"; 322 | }; 323 | name = Release; 324 | }; 325 | /* End XCBuildConfiguration section */ 326 | 327 | /* Begin XCConfigurationList section */ 328 | 638330CF219F16B50063E39E /* Build configuration list for PBXProject "External WebVTT Example" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | 638330E4219F16B60063E39E /* Debug */, 332 | 638330E5219F16B60063E39E /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | 638330E6219F16B60063E39E /* Build configuration list for PBXNativeTarget "External WebVTT Example" */ = { 338 | isa = XCConfigurationList; 339 | buildConfigurations = ( 340 | 638330E7219F16B60063E39E /* Debug */, 341 | 638330E8219F16B60063E39E /* Release */, 342 | ); 343 | defaultConfigurationIsVisible = 0; 344 | defaultConfigurationName = Release; 345 | }; 346 | /* End XCConfigurationList section */ 347 | }; 348 | rootObject = 638330CC219F16B50063E39E /* Project object */; 349 | } 350 | -------------------------------------------------------------------------------- /External WebVTT Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /External WebVTT Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /External WebVTT Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // External WebVTT Example 4 | // 5 | // Created by Joris Weimar on 16/11/2018. 6 | // Copyright © 2018 Joris Weimar. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /External WebVTT Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /External WebVTT Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /External WebVTT Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /External WebVTT Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /External WebVTT Example/CustomResourceLoaderDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomResourceLoaderDelegate.swift 3 | // External WebVTT Example 4 | // 5 | // Created by Joris Weimar on 24/01/2019. 6 | // Copyright © 2019 Joris Weimar. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import AVFoundation 11 | 12 | /** 13 | A custom resource loader delegate that will manipulate the .m3u8 and inject 14 | the VTT for us. 15 | */ 16 | 17 | class CustomResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate { 18 | static let mainScheme = "mainm3u8" 19 | private let fragmentsScheme = "fragmentsm3u8" 20 | private let subtitlesScheme = "subtitlesm3u8" 21 | private let extInfPrefix = "#EXTINF:" 22 | private var m3u8URL: URL 23 | private var vttURL: URL 24 | private var m3u8String: String? = nil 25 | private var playlistDuration: Double = 0.0 26 | 27 | init(m3u8URL: URL, vttURL: URL) { 28 | self.m3u8URL = m3u8URL 29 | self.vttURL = vttURL 30 | super.init() 31 | } 32 | 33 | func resourceLoader(_ resourceLoader: AVAssetResourceLoader, 34 | shouldWaitForLoadingOfRequestedResource 35 | loadingRequest: AVAssetResourceLoadingRequest) -> Bool { 36 | guard let scheme = loadingRequest.request.url?.scheme else { 37 | return false 38 | } 39 | 40 | switch (scheme) { 41 | case CustomResourceLoaderDelegate.mainScheme: 42 | return handleMainRequest(loadingRequest) 43 | case fragmentsScheme: 44 | return handleFragments(loadingRequest) 45 | case subtitlesScheme: 46 | return handleSubtitles(loadingRequest) 47 | default: 48 | return false 49 | } 50 | } 51 | 52 | func handleMainRequest(_ request: AVAssetResourceLoadingRequest) -> Bool { 53 | let task = URLSession.shared.dataTask(with: m3u8URL) { 54 | [weak self] (data, response, error) in 55 | guard error == nil, 56 | let data = data else { 57 | request.finishLoading(with: error) 58 | return 59 | } 60 | self?.processPlaylistWithData(data) 61 | self?.finishRequestWithMainPlaylist(request) 62 | } 63 | task.resume() 64 | return true 65 | } 66 | 67 | func handleFragments(_ request: AVAssetResourceLoadingRequest) -> Bool { 68 | let data = m3u8String!.data(using: .utf8)! 69 | request.dataRequest?.respond(with: data) 70 | request.finishLoading() 71 | return true 72 | } 73 | 74 | func handleSubtitles(_ request: AVAssetResourceLoadingRequest) -> Bool { 75 | let subtitlem3u8 = getSubtitlem3u8WithDuration(playlistDuration) 76 | let data = subtitlem3u8.data(using: .utf8)! 77 | request.dataRequest?.respond(with: data) 78 | request.finishLoading() 79 | return true 80 | } 81 | 82 | func getDurationForEXTINFLine(_ line: String) -> Double { 83 | let components = line.components(separatedBy: ":") 84 | return Double(components[1].dropLast())! 85 | } 86 | 87 | func processPlaylistWithData(_ data: Data) { 88 | guard let string = String(data: data, encoding: .utf8) else { return } 89 | let lines = string.components(separatedBy: "\n") 90 | var newLines = [String]() 91 | var iterator = lines.makeIterator() 92 | playlistDuration = 0.0 93 | while let line = iterator.next() { 94 | newLines.append(line) 95 | if line.hasPrefix(extInfPrefix) { // Process each fragment 96 | playlistDuration += getDurationForEXTINFLine(line) 97 | if let newLine = iterator.next() { // Next line contains path 98 | newLines.append(appendBasePath(newLine)) 99 | } 100 | } 101 | } 102 | m3u8String = newLines.joined(separator: "\n") 103 | } 104 | 105 | func appendBasePath(_ string: String) -> String { 106 | var components = URLComponents(string: m3u8URL.absoluteString) 107 | components?.query = nil 108 | let path = components!.url!.deletingLastPathComponent().absoluteString 109 | return path + string 110 | } 111 | 112 | func finishRequestWithMainPlaylist(_ request: AVAssetResourceLoadingRequest) { 113 | let mainm3u8 = getMainm3u8() 114 | let data = mainm3u8.data(using: .utf8)! 115 | request.dataRequest?.respond(with: data) 116 | request.finishLoading() 117 | } 118 | 119 | func getMainm3u8() -> String { 120 | let mainm3u8 = """ 121 | #EXTM3U 122 | #EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=NO,FORCED=NO,URI="subtitlesm3u8://foo",LANGUAGE="en" 123 | #EXT-X-STREAM-INF:BANDWIDTH=1280000,SUBTITLES="subs" 124 | fragmentsm3u8://foo 125 | """ 126 | return mainm3u8 127 | } 128 | 129 | func getSubtitlem3u8WithDuration(_ duration: Double) -> String { 130 | let durationString = String(format: "%.3f", duration) 131 | let intDuration = Int(duration) 132 | let subtitlem3u8 = """ 133 | #EXTM3U 134 | #EXT-X-VERSION:3 135 | #EXT-X-MEDIA-SEQUENCE:1 136 | #EXT-X-PLAYLIST-TYPE:VOD 137 | #EXT-X-ALLOW-CACHE:NO 138 | #EXT-X-TARGETDURATION:\(intDuration) 139 | #EXTINF:\(durationString), no desc 140 | \(vttURL.absoluteString) 141 | #EXT-X-ENDLIST 142 | """ 143 | return subtitlem3u8 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /External WebVTT Example/CustomVTTPlayer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CustomResourceLoaderDelegate.swift 3 | // External WebVTT 4 | // 5 | // Created by Joris Weimar on 1/24/2019. 6 | // Copyright © 2019 Joris Weimar. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import AVFoundation 11 | 12 | class CustomVTTPlayer: AVPlayer { 13 | private var loaderQueue = DispatchQueue(label: "resourceLoader") 14 | private var m3u8URL: URL 15 | private var delegate: CustomResourceLoaderDelegate 16 | 17 | init?(m3u8URL: URL, vttURL: URL) { 18 | self.m3u8URL = m3u8URL 19 | self.delegate = CustomResourceLoaderDelegate(m3u8URL: m3u8URL, 20 | vttURL: vttURL) 21 | super.init() 22 | let customScheme = CustomResourceLoaderDelegate.mainScheme 23 | guard let customURL = replaceURLWithScheme(customScheme, 24 | url: m3u8URL) else { 25 | return nil 26 | } 27 | let asset = AVURLAsset(url: customURL) 28 | asset.resourceLoader.setDelegate(delegate, queue: loaderQueue) 29 | let playerItem = AVPlayerItem(asset: asset) 30 | self.replaceCurrentItem(with: playerItem) 31 | } 32 | 33 | required init(coder: NSCoder) { 34 | fatalError("NSCoding not supported") 35 | } 36 | 37 | func replaceURLWithScheme(_ scheme: String, url: URL) -> URL? { 38 | let urlString = url.absoluteString 39 | guard let index = urlString.firstIndex(of: ":") else { return nil } 40 | let rest = urlString[index...] 41 | let newUrlString = scheme + rest 42 | return URL(string: newUrlString) 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /External WebVTT Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /External WebVTT Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // External WebVTT Example 4 | // 5 | // Created by Joris Weimar on 16/11/2018. 6 | // Copyright © 2018 Joris Weimar. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AVKit 11 | 12 | class ViewController: UIViewController { 13 | let m3u8URL = URL(string: "https://somedomain.com/playlist.m3u8")! 14 | let vttURL = URL(string: "https://somedomain.com/subtitles.vtt")! 15 | 16 | @IBAction func playMovie(_ sender: Any) { 17 | let player = CustomVTTPlayer(m3u8URL: m3u8URL, vttURL: vttURL) 18 | let vc = AVPlayerViewController() 19 | vc.player = player 20 | present(vc, animated: true) 21 | } 22 | 23 | } 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 jbweimar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # external-webvtt-example 2 | Supporting HLS with External WebVTT Closed Captions 3 | 4 | https://jorisweimar.com/programming/supporting-external-webvtt-subtitles-in-avplayer/ 5 | 6 | Disclaimer: the code is a proof of concept and mostly deals with the happy case. Use at your own risk. 7 | --------------------------------------------------------------------------------