├── .DS_Store ├── .gitignore ├── LICENSE ├── README.md ├── SULoader.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── SULoader ├── AppDelegate.h ├── AppDelegate.m ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── SULoader │ ├── Category │ │ ├── NSString+SULoader.h │ │ ├── NSString+SULoader.m │ │ ├── NSURL+SULoader.h │ │ ├── NSURL+SULoader.m │ │ └── SULoaderCategory.h │ ├── SUFileHandle.h │ ├── SUFileHandle.m │ ├── SUPlayer.h │ ├── SUPlayer.m │ ├── SURequestTask.h │ ├── SURequestTask.m │ ├── SUResourceLoader.h │ └── SUResourceLoader.m ├── ViewController.h ├── ViewController.m ├── main.m ├── p1393354_128k.jpg ├── p1458183_128k.jpg ├── p190415_128k.jpg └── p966452_128k.jpg ├── SULoaderTests ├── Info.plist └── SULoaderTests.m └── SULoaderUITests ├── Info.plist └── SULoaderUITests.m /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaMingShen/SUCacheLoader/3678f57bb69ae3419156ddec5fd21596dc9d0dce/.DS_Store -------------------------------------------------------------------------------- /.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 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | # CocoaPods 31 | # 32 | # We recommend against adding the Pods directory to your .gitignore. However 33 | # you should judge for yourself, the pros and cons are mentioned at: 34 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 35 | # 36 | # Pods/ 37 | 38 | # Carthage 39 | # 40 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 41 | # Carthage/Checkouts 42 | 43 | Carthage/Build 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 51 | 52 | fastlane/report.xml 53 | fastlane/screenshots 54 | 55 | #Code Injection 56 | # 57 | # After new code Injection tools there's a generated folder /iOSInjectionProject 58 | # https://github.com/johnno1962/injectionforxcode 59 | 60 | iOSInjectionProject/ 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 KevinSu 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 | # SUCacheLoader 2 | SUCacheLoader 3 | -------------------------------------------------------------------------------- /SULoader.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | B11566D31D22208A00B16498 /* SUPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = B11566D01D22208A00B16498 /* SUPlayer.m */; }; 11 | B11566D41D22208A00B16498 /* SUResourceLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = B11566D21D22208A00B16498 /* SUResourceLoader.m */; }; 12 | B11566D71D2220C700B16498 /* NSURL+SULoader.m in Sources */ = {isa = PBXBuildFile; fileRef = B11566D61D2220C700B16498 /* NSURL+SULoader.m */; }; 13 | B11566DB1D22241300B16498 /* SURequestTask.m in Sources */ = {isa = PBXBuildFile; fileRef = B11566DA1D22241300B16498 /* SURequestTask.m */; }; 14 | B135ED031D1D079800A67702 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B135ED021D1D079800A67702 /* main.m */; }; 15 | B135ED061D1D079800A67702 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B135ED051D1D079800A67702 /* AppDelegate.m */; }; 16 | B135ED091D1D079800A67702 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B135ED081D1D079800A67702 /* ViewController.m */; }; 17 | B135ED0C1D1D079800A67702 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B135ED0A1D1D079800A67702 /* Main.storyboard */; }; 18 | B135ED0E1D1D079800A67702 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B135ED0D1D1D079800A67702 /* Assets.xcassets */; }; 19 | B135ED111D1D079800A67702 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B135ED0F1D1D079800A67702 /* LaunchScreen.storyboard */; }; 20 | B135ED1C1D1D079800A67702 /* SULoaderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B135ED1B1D1D079800A67702 /* SULoaderTests.m */; }; 21 | B135ED271D1D079800A67702 /* SULoaderUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = B135ED261D1D079800A67702 /* SULoaderUITests.m */; }; 22 | B155B27A1D224ECA00F255B8 /* SUFileHandle.m in Sources */ = {isa = PBXBuildFile; fileRef = B155B2791D224ECA00F255B8 /* SUFileHandle.m */; }; 23 | B155B27D1D22573E00F255B8 /* NSString+SULoader.m in Sources */ = {isa = PBXBuildFile; fileRef = B155B27C1D22573E00F255B8 /* NSString+SULoader.m */; }; 24 | B1B3007E1D25299F00471358 /* p190415_128k.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B1B3007B1D25299F00471358 /* p190415_128k.jpg */; }; 25 | B1B3007F1D25299F00471358 /* p1393354_128k.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B1B3007C1D25299F00471358 /* p1393354_128k.jpg */; }; 26 | B1B300801D25299F00471358 /* p1458183_128k.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B1B3007D1D25299F00471358 /* p1458183_128k.jpg */; }; 27 | B1BC78441D23BC8900297120 /* p966452_128k.jpg in Resources */ = {isa = PBXBuildFile; fileRef = B1BC78421D23BC8900297120 /* p966452_128k.jpg */; }; 28 | /* End PBXBuildFile section */ 29 | 30 | /* Begin PBXContainerItemProxy section */ 31 | B135ED181D1D079800A67702 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = B135ECF61D1D079800A67702 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = B135ECFD1D1D079800A67702; 36 | remoteInfo = SULoader; 37 | }; 38 | B135ED231D1D079800A67702 /* PBXContainerItemProxy */ = { 39 | isa = PBXContainerItemProxy; 40 | containerPortal = B135ECF61D1D079800A67702 /* Project object */; 41 | proxyType = 1; 42 | remoteGlobalIDString = B135ECFD1D1D079800A67702; 43 | remoteInfo = SULoader; 44 | }; 45 | /* End PBXContainerItemProxy section */ 46 | 47 | /* Begin PBXFileReference section */ 48 | B11566CF1D22208A00B16498 /* SUPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPlayer.h; sourceTree = ""; }; 49 | B11566D01D22208A00B16498 /* SUPlayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUPlayer.m; sourceTree = ""; }; 50 | B11566D11D22208A00B16498 /* SUResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUResourceLoader.h; sourceTree = ""; }; 51 | B11566D21D22208A00B16498 /* SUResourceLoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUResourceLoader.m; sourceTree = ""; }; 52 | B11566D51D2220C700B16498 /* NSURL+SULoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+SULoader.h"; sourceTree = ""; }; 53 | B11566D61D2220C700B16498 /* NSURL+SULoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+SULoader.m"; sourceTree = ""; }; 54 | B11566D81D22213E00B16498 /* SULoaderCategory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULoaderCategory.h; sourceTree = ""; }; 55 | B11566D91D22241300B16498 /* SURequestTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SURequestTask.h; sourceTree = ""; }; 56 | B11566DA1D22241300B16498 /* SURequestTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SURequestTask.m; sourceTree = ""; }; 57 | B135ECFE1D1D079800A67702 /* SULoader.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SULoader.app; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | B135ED021D1D079800A67702 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 59 | B135ED041D1D079800A67702 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 60 | B135ED051D1D079800A67702 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 61 | B135ED071D1D079800A67702 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 62 | B135ED081D1D079800A67702 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 63 | B135ED0B1D1D079800A67702 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 64 | B135ED0D1D1D079800A67702 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 65 | B135ED101D1D079800A67702 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 66 | B135ED121D1D079800A67702 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 67 | B135ED171D1D079800A67702 /* SULoaderTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SULoaderTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 68 | B135ED1B1D1D079800A67702 /* SULoaderTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SULoaderTests.m; sourceTree = ""; }; 69 | B135ED1D1D1D079800A67702 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 70 | B135ED221D1D079800A67702 /* SULoaderUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SULoaderUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 71 | B135ED261D1D079800A67702 /* SULoaderUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SULoaderUITests.m; sourceTree = ""; }; 72 | B135ED281D1D079800A67702 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 73 | B155B2781D224ECA00F255B8 /* SUFileHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUFileHandle.h; sourceTree = ""; }; 74 | B155B2791D224ECA00F255B8 /* SUFileHandle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUFileHandle.m; sourceTree = ""; }; 75 | B155B27B1D22573E00F255B8 /* NSString+SULoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+SULoader.h"; sourceTree = ""; }; 76 | B155B27C1D22573E00F255B8 /* NSString+SULoader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+SULoader.m"; sourceTree = ""; }; 77 | B1B3007B1D25299F00471358 /* p190415_128k.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = p190415_128k.jpg; sourceTree = ""; }; 78 | B1B3007C1D25299F00471358 /* p1393354_128k.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = p1393354_128k.jpg; sourceTree = ""; }; 79 | B1B3007D1D25299F00471358 /* p1458183_128k.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = p1458183_128k.jpg; sourceTree = ""; }; 80 | B1BC78421D23BC8900297120 /* p966452_128k.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = p966452_128k.jpg; sourceTree = ""; }; 81 | /* End PBXFileReference section */ 82 | 83 | /* Begin PBXFrameworksBuildPhase section */ 84 | B135ECFB1D1D079800A67702 /* Frameworks */ = { 85 | isa = PBXFrameworksBuildPhase; 86 | buildActionMask = 2147483647; 87 | files = ( 88 | ); 89 | runOnlyForDeploymentPostprocessing = 0; 90 | }; 91 | B135ED141D1D079800A67702 /* Frameworks */ = { 92 | isa = PBXFrameworksBuildPhase; 93 | buildActionMask = 2147483647; 94 | files = ( 95 | ); 96 | runOnlyForDeploymentPostprocessing = 0; 97 | }; 98 | B135ED1F1D1D079800A67702 /* Frameworks */ = { 99 | isa = PBXFrameworksBuildPhase; 100 | buildActionMask = 2147483647; 101 | files = ( 102 | ); 103 | runOnlyForDeploymentPostprocessing = 0; 104 | }; 105 | /* End PBXFrameworksBuildPhase section */ 106 | 107 | /* Begin PBXGroup section */ 108 | B11566CE1D22200300B16498 /* Category */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | B11566D81D22213E00B16498 /* SULoaderCategory.h */, 112 | B11566D51D2220C700B16498 /* NSURL+SULoader.h */, 113 | B11566D61D2220C700B16498 /* NSURL+SULoader.m */, 114 | B155B27B1D22573E00F255B8 /* NSString+SULoader.h */, 115 | B155B27C1D22573E00F255B8 /* NSString+SULoader.m */, 116 | ); 117 | path = Category; 118 | sourceTree = ""; 119 | }; 120 | B135ECF51D1D079800A67702 = { 121 | isa = PBXGroup; 122 | children = ( 123 | B135ED001D1D079800A67702 /* SULoader */, 124 | B135ED1A1D1D079800A67702 /* SULoaderTests */, 125 | B135ED251D1D079800A67702 /* SULoaderUITests */, 126 | B135ECFF1D1D079800A67702 /* Products */, 127 | ); 128 | sourceTree = ""; 129 | }; 130 | B135ECFF1D1D079800A67702 /* Products */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | B135ECFE1D1D079800A67702 /* SULoader.app */, 134 | B135ED171D1D079800A67702 /* SULoaderTests.xctest */, 135 | B135ED221D1D079800A67702 /* SULoaderUITests.xctest */, 136 | ); 137 | name = Products; 138 | sourceTree = ""; 139 | }; 140 | B135ED001D1D079800A67702 /* SULoader */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | B135ED341D1D07AA00A67702 /* SULoader */, 144 | B135ED041D1D079800A67702 /* AppDelegate.h */, 145 | B135ED051D1D079800A67702 /* AppDelegate.m */, 146 | B135ED071D1D079800A67702 /* ViewController.h */, 147 | B135ED081D1D079800A67702 /* ViewController.m */, 148 | B135ED0A1D1D079800A67702 /* Main.storyboard */, 149 | B135ED0D1D1D079800A67702 /* Assets.xcassets */, 150 | B135ED0F1D1D079800A67702 /* LaunchScreen.storyboard */, 151 | B135ED121D1D079800A67702 /* Info.plist */, 152 | B135ED011D1D079800A67702 /* Supporting Files */, 153 | ); 154 | path = SULoader; 155 | sourceTree = ""; 156 | }; 157 | B135ED011D1D079800A67702 /* Supporting Files */ = { 158 | isa = PBXGroup; 159 | children = ( 160 | B1B3007B1D25299F00471358 /* p190415_128k.jpg */, 161 | B1B3007C1D25299F00471358 /* p1393354_128k.jpg */, 162 | B1B3007D1D25299F00471358 /* p1458183_128k.jpg */, 163 | B1BC78421D23BC8900297120 /* p966452_128k.jpg */, 164 | B135ED021D1D079800A67702 /* main.m */, 165 | ); 166 | name = "Supporting Files"; 167 | sourceTree = ""; 168 | }; 169 | B135ED1A1D1D079800A67702 /* SULoaderTests */ = { 170 | isa = PBXGroup; 171 | children = ( 172 | B135ED1B1D1D079800A67702 /* SULoaderTests.m */, 173 | B135ED1D1D1D079800A67702 /* Info.plist */, 174 | ); 175 | path = SULoaderTests; 176 | sourceTree = ""; 177 | }; 178 | B135ED251D1D079800A67702 /* SULoaderUITests */ = { 179 | isa = PBXGroup; 180 | children = ( 181 | B135ED261D1D079800A67702 /* SULoaderUITests.m */, 182 | B135ED281D1D079800A67702 /* Info.plist */, 183 | ); 184 | path = SULoaderUITests; 185 | sourceTree = ""; 186 | }; 187 | B135ED341D1D07AA00A67702 /* SULoader */ = { 188 | isa = PBXGroup; 189 | children = ( 190 | B11566CF1D22208A00B16498 /* SUPlayer.h */, 191 | B11566D01D22208A00B16498 /* SUPlayer.m */, 192 | B11566D11D22208A00B16498 /* SUResourceLoader.h */, 193 | B11566D21D22208A00B16498 /* SUResourceLoader.m */, 194 | B11566D91D22241300B16498 /* SURequestTask.h */, 195 | B11566DA1D22241300B16498 /* SURequestTask.m */, 196 | B155B2781D224ECA00F255B8 /* SUFileHandle.h */, 197 | B155B2791D224ECA00F255B8 /* SUFileHandle.m */, 198 | B11566CE1D22200300B16498 /* Category */, 199 | ); 200 | path = SULoader; 201 | sourceTree = ""; 202 | }; 203 | /* End PBXGroup section */ 204 | 205 | /* Begin PBXNativeTarget section */ 206 | B135ECFD1D1D079800A67702 /* SULoader */ = { 207 | isa = PBXNativeTarget; 208 | buildConfigurationList = B135ED2B1D1D079800A67702 /* Build configuration list for PBXNativeTarget "SULoader" */; 209 | buildPhases = ( 210 | B135ECFA1D1D079800A67702 /* Sources */, 211 | B135ECFB1D1D079800A67702 /* Frameworks */, 212 | B135ECFC1D1D079800A67702 /* Resources */, 213 | ); 214 | buildRules = ( 215 | ); 216 | dependencies = ( 217 | ); 218 | name = SULoader; 219 | productName = SULoader; 220 | productReference = B135ECFE1D1D079800A67702 /* SULoader.app */; 221 | productType = "com.apple.product-type.application"; 222 | }; 223 | B135ED161D1D079800A67702 /* SULoaderTests */ = { 224 | isa = PBXNativeTarget; 225 | buildConfigurationList = B135ED2E1D1D079800A67702 /* Build configuration list for PBXNativeTarget "SULoaderTests" */; 226 | buildPhases = ( 227 | B135ED131D1D079800A67702 /* Sources */, 228 | B135ED141D1D079800A67702 /* Frameworks */, 229 | B135ED151D1D079800A67702 /* Resources */, 230 | ); 231 | buildRules = ( 232 | ); 233 | dependencies = ( 234 | B135ED191D1D079800A67702 /* PBXTargetDependency */, 235 | ); 236 | name = SULoaderTests; 237 | productName = SULoaderTests; 238 | productReference = B135ED171D1D079800A67702 /* SULoaderTests.xctest */; 239 | productType = "com.apple.product-type.bundle.unit-test"; 240 | }; 241 | B135ED211D1D079800A67702 /* SULoaderUITests */ = { 242 | isa = PBXNativeTarget; 243 | buildConfigurationList = B135ED311D1D079800A67702 /* Build configuration list for PBXNativeTarget "SULoaderUITests" */; 244 | buildPhases = ( 245 | B135ED1E1D1D079800A67702 /* Sources */, 246 | B135ED1F1D1D079800A67702 /* Frameworks */, 247 | B135ED201D1D079800A67702 /* Resources */, 248 | ); 249 | buildRules = ( 250 | ); 251 | dependencies = ( 252 | B135ED241D1D079800A67702 /* PBXTargetDependency */, 253 | ); 254 | name = SULoaderUITests; 255 | productName = SULoaderUITests; 256 | productReference = B135ED221D1D079800A67702 /* SULoaderUITests.xctest */; 257 | productType = "com.apple.product-type.bundle.ui-testing"; 258 | }; 259 | /* End PBXNativeTarget section */ 260 | 261 | /* Begin PBXProject section */ 262 | B135ECF61D1D079800A67702 /* Project object */ = { 263 | isa = PBXProject; 264 | attributes = { 265 | LastUpgradeCheck = 0700; 266 | ORGANIZATIONNAME = "万众科技"; 267 | TargetAttributes = { 268 | B135ECFD1D1D079800A67702 = { 269 | CreatedOnToolsVersion = 7.0; 270 | }; 271 | B135ED161D1D079800A67702 = { 272 | CreatedOnToolsVersion = 7.0; 273 | TestTargetID = B135ECFD1D1D079800A67702; 274 | }; 275 | B135ED211D1D079800A67702 = { 276 | CreatedOnToolsVersion = 7.0; 277 | TestTargetID = B135ECFD1D1D079800A67702; 278 | }; 279 | }; 280 | }; 281 | buildConfigurationList = B135ECF91D1D079800A67702 /* Build configuration list for PBXProject "SULoader" */; 282 | compatibilityVersion = "Xcode 3.2"; 283 | developmentRegion = English; 284 | hasScannedForEncodings = 0; 285 | knownRegions = ( 286 | en, 287 | Base, 288 | ); 289 | mainGroup = B135ECF51D1D079800A67702; 290 | productRefGroup = B135ECFF1D1D079800A67702 /* Products */; 291 | projectDirPath = ""; 292 | projectRoot = ""; 293 | targets = ( 294 | B135ECFD1D1D079800A67702 /* SULoader */, 295 | B135ED161D1D079800A67702 /* SULoaderTests */, 296 | B135ED211D1D079800A67702 /* SULoaderUITests */, 297 | ); 298 | }; 299 | /* End PBXProject section */ 300 | 301 | /* Begin PBXResourcesBuildPhase section */ 302 | B135ECFC1D1D079800A67702 /* Resources */ = { 303 | isa = PBXResourcesBuildPhase; 304 | buildActionMask = 2147483647; 305 | files = ( 306 | B135ED111D1D079800A67702 /* LaunchScreen.storyboard in Resources */, 307 | B1BC78441D23BC8900297120 /* p966452_128k.jpg in Resources */, 308 | B1B3007E1D25299F00471358 /* p190415_128k.jpg in Resources */, 309 | B1B300801D25299F00471358 /* p1458183_128k.jpg in Resources */, 310 | B135ED0E1D1D079800A67702 /* Assets.xcassets in Resources */, 311 | B135ED0C1D1D079800A67702 /* Main.storyboard in Resources */, 312 | B1B3007F1D25299F00471358 /* p1393354_128k.jpg in Resources */, 313 | ); 314 | runOnlyForDeploymentPostprocessing = 0; 315 | }; 316 | B135ED151D1D079800A67702 /* Resources */ = { 317 | isa = PBXResourcesBuildPhase; 318 | buildActionMask = 2147483647; 319 | files = ( 320 | ); 321 | runOnlyForDeploymentPostprocessing = 0; 322 | }; 323 | B135ED201D1D079800A67702 /* Resources */ = { 324 | isa = PBXResourcesBuildPhase; 325 | buildActionMask = 2147483647; 326 | files = ( 327 | ); 328 | runOnlyForDeploymentPostprocessing = 0; 329 | }; 330 | /* End PBXResourcesBuildPhase section */ 331 | 332 | /* Begin PBXSourcesBuildPhase section */ 333 | B135ECFA1D1D079800A67702 /* Sources */ = { 334 | isa = PBXSourcesBuildPhase; 335 | buildActionMask = 2147483647; 336 | files = ( 337 | B135ED091D1D079800A67702 /* ViewController.m in Sources */, 338 | B11566D71D2220C700B16498 /* NSURL+SULoader.m in Sources */, 339 | B135ED061D1D079800A67702 /* AppDelegate.m in Sources */, 340 | B11566D41D22208A00B16498 /* SUResourceLoader.m in Sources */, 341 | B155B27D1D22573E00F255B8 /* NSString+SULoader.m in Sources */, 342 | B11566DB1D22241300B16498 /* SURequestTask.m in Sources */, 343 | B155B27A1D224ECA00F255B8 /* SUFileHandle.m in Sources */, 344 | B11566D31D22208A00B16498 /* SUPlayer.m in Sources */, 345 | B135ED031D1D079800A67702 /* main.m in Sources */, 346 | ); 347 | runOnlyForDeploymentPostprocessing = 0; 348 | }; 349 | B135ED131D1D079800A67702 /* Sources */ = { 350 | isa = PBXSourcesBuildPhase; 351 | buildActionMask = 2147483647; 352 | files = ( 353 | B135ED1C1D1D079800A67702 /* SULoaderTests.m in Sources */, 354 | ); 355 | runOnlyForDeploymentPostprocessing = 0; 356 | }; 357 | B135ED1E1D1D079800A67702 /* Sources */ = { 358 | isa = PBXSourcesBuildPhase; 359 | buildActionMask = 2147483647; 360 | files = ( 361 | B135ED271D1D079800A67702 /* SULoaderUITests.m in Sources */, 362 | ); 363 | runOnlyForDeploymentPostprocessing = 0; 364 | }; 365 | /* End PBXSourcesBuildPhase section */ 366 | 367 | /* Begin PBXTargetDependency section */ 368 | B135ED191D1D079800A67702 /* PBXTargetDependency */ = { 369 | isa = PBXTargetDependency; 370 | target = B135ECFD1D1D079800A67702 /* SULoader */; 371 | targetProxy = B135ED181D1D079800A67702 /* PBXContainerItemProxy */; 372 | }; 373 | B135ED241D1D079800A67702 /* PBXTargetDependency */ = { 374 | isa = PBXTargetDependency; 375 | target = B135ECFD1D1D079800A67702 /* SULoader */; 376 | targetProxy = B135ED231D1D079800A67702 /* PBXContainerItemProxy */; 377 | }; 378 | /* End PBXTargetDependency section */ 379 | 380 | /* Begin PBXVariantGroup section */ 381 | B135ED0A1D1D079800A67702 /* Main.storyboard */ = { 382 | isa = PBXVariantGroup; 383 | children = ( 384 | B135ED0B1D1D079800A67702 /* Base */, 385 | ); 386 | name = Main.storyboard; 387 | sourceTree = ""; 388 | }; 389 | B135ED0F1D1D079800A67702 /* LaunchScreen.storyboard */ = { 390 | isa = PBXVariantGroup; 391 | children = ( 392 | B135ED101D1D079800A67702 /* Base */, 393 | ); 394 | name = LaunchScreen.storyboard; 395 | sourceTree = ""; 396 | }; 397 | /* End PBXVariantGroup section */ 398 | 399 | /* Begin XCBuildConfiguration section */ 400 | B135ED291D1D079800A67702 /* Debug */ = { 401 | isa = XCBuildConfiguration; 402 | buildSettings = { 403 | ALWAYS_SEARCH_USER_PATHS = NO; 404 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 405 | CLANG_CXX_LIBRARY = "libc++"; 406 | CLANG_ENABLE_MODULES = YES; 407 | CLANG_ENABLE_OBJC_ARC = YES; 408 | CLANG_WARN_BOOL_CONVERSION = YES; 409 | CLANG_WARN_CONSTANT_CONVERSION = YES; 410 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 411 | CLANG_WARN_EMPTY_BODY = YES; 412 | CLANG_WARN_ENUM_CONVERSION = YES; 413 | CLANG_WARN_INT_CONVERSION = YES; 414 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 415 | CLANG_WARN_UNREACHABLE_CODE = YES; 416 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 417 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 418 | COPY_PHASE_STRIP = NO; 419 | DEBUG_INFORMATION_FORMAT = dwarf; 420 | ENABLE_STRICT_OBJC_MSGSEND = YES; 421 | ENABLE_TESTABILITY = YES; 422 | GCC_C_LANGUAGE_STANDARD = gnu99; 423 | GCC_DYNAMIC_NO_PIC = NO; 424 | GCC_NO_COMMON_BLOCKS = YES; 425 | GCC_OPTIMIZATION_LEVEL = 0; 426 | GCC_PREPROCESSOR_DEFINITIONS = ( 427 | "DEBUG=1", 428 | "$(inherited)", 429 | ); 430 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 431 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 432 | GCC_WARN_UNDECLARED_SELECTOR = YES; 433 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 434 | GCC_WARN_UNUSED_FUNCTION = YES; 435 | GCC_WARN_UNUSED_VARIABLE = YES; 436 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 437 | MTL_ENABLE_DEBUG_INFO = YES; 438 | ONLY_ACTIVE_ARCH = YES; 439 | SDKROOT = iphoneos; 440 | TARGETED_DEVICE_FAMILY = "1,2"; 441 | }; 442 | name = Debug; 443 | }; 444 | B135ED2A1D1D079800A67702 /* Release */ = { 445 | isa = XCBuildConfiguration; 446 | buildSettings = { 447 | ALWAYS_SEARCH_USER_PATHS = NO; 448 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 449 | CLANG_CXX_LIBRARY = "libc++"; 450 | CLANG_ENABLE_MODULES = YES; 451 | CLANG_ENABLE_OBJC_ARC = YES; 452 | CLANG_WARN_BOOL_CONVERSION = YES; 453 | CLANG_WARN_CONSTANT_CONVERSION = YES; 454 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 455 | CLANG_WARN_EMPTY_BODY = YES; 456 | CLANG_WARN_ENUM_CONVERSION = YES; 457 | CLANG_WARN_INT_CONVERSION = YES; 458 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 459 | CLANG_WARN_UNREACHABLE_CODE = YES; 460 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 461 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 462 | COPY_PHASE_STRIP = NO; 463 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 464 | ENABLE_NS_ASSERTIONS = NO; 465 | ENABLE_STRICT_OBJC_MSGSEND = YES; 466 | GCC_C_LANGUAGE_STANDARD = gnu99; 467 | GCC_NO_COMMON_BLOCKS = YES; 468 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 469 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 470 | GCC_WARN_UNDECLARED_SELECTOR = YES; 471 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 472 | GCC_WARN_UNUSED_FUNCTION = YES; 473 | GCC_WARN_UNUSED_VARIABLE = YES; 474 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 475 | MTL_ENABLE_DEBUG_INFO = NO; 476 | SDKROOT = iphoneos; 477 | TARGETED_DEVICE_FAMILY = "1,2"; 478 | VALIDATE_PRODUCT = YES; 479 | }; 480 | name = Release; 481 | }; 482 | B135ED2C1D1D079800A67702 /* Debug */ = { 483 | isa = XCBuildConfiguration; 484 | buildSettings = { 485 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 486 | DEVELOPMENT_TEAM = ""; 487 | INFOPLIST_FILE = SULoader/Info.plist; 488 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 489 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 490 | PRODUCT_BUNDLE_IDENTIFIER = com.KevinSu.CacheLoader; 491 | PRODUCT_NAME = "$(TARGET_NAME)"; 492 | }; 493 | name = Debug; 494 | }; 495 | B135ED2D1D1D079800A67702 /* Release */ = { 496 | isa = XCBuildConfiguration; 497 | buildSettings = { 498 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 499 | DEVELOPMENT_TEAM = ""; 500 | INFOPLIST_FILE = SULoader/Info.plist; 501 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 502 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 503 | PRODUCT_BUNDLE_IDENTIFIER = com.KevinSu.CacheLoader; 504 | PRODUCT_NAME = "$(TARGET_NAME)"; 505 | }; 506 | name = Release; 507 | }; 508 | B135ED2F1D1D079800A67702 /* Debug */ = { 509 | isa = XCBuildConfiguration; 510 | buildSettings = { 511 | BUNDLE_LOADER = "$(TEST_HOST)"; 512 | INFOPLIST_FILE = SULoaderTests/Info.plist; 513 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 514 | PRODUCT_BUNDLE_IDENTIFIER = com.WanZhongLife.SULoaderTests; 515 | PRODUCT_NAME = "$(TARGET_NAME)"; 516 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SULoader.app/SULoader"; 517 | }; 518 | name = Debug; 519 | }; 520 | B135ED301D1D079800A67702 /* Release */ = { 521 | isa = XCBuildConfiguration; 522 | buildSettings = { 523 | BUNDLE_LOADER = "$(TEST_HOST)"; 524 | INFOPLIST_FILE = SULoaderTests/Info.plist; 525 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 526 | PRODUCT_BUNDLE_IDENTIFIER = com.WanZhongLife.SULoaderTests; 527 | PRODUCT_NAME = "$(TARGET_NAME)"; 528 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SULoader.app/SULoader"; 529 | }; 530 | name = Release; 531 | }; 532 | B135ED321D1D079800A67702 /* Debug */ = { 533 | isa = XCBuildConfiguration; 534 | buildSettings = { 535 | INFOPLIST_FILE = SULoaderUITests/Info.plist; 536 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 537 | PRODUCT_BUNDLE_IDENTIFIER = com.WanZhongLife.SULoaderUITests; 538 | PRODUCT_NAME = "$(TARGET_NAME)"; 539 | TEST_TARGET_NAME = SULoader; 540 | USES_XCTRUNNER = YES; 541 | }; 542 | name = Debug; 543 | }; 544 | B135ED331D1D079800A67702 /* Release */ = { 545 | isa = XCBuildConfiguration; 546 | buildSettings = { 547 | INFOPLIST_FILE = SULoaderUITests/Info.plist; 548 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 549 | PRODUCT_BUNDLE_IDENTIFIER = com.WanZhongLife.SULoaderUITests; 550 | PRODUCT_NAME = "$(TARGET_NAME)"; 551 | TEST_TARGET_NAME = SULoader; 552 | USES_XCTRUNNER = YES; 553 | }; 554 | name = Release; 555 | }; 556 | /* End XCBuildConfiguration section */ 557 | 558 | /* Begin XCConfigurationList section */ 559 | B135ECF91D1D079800A67702 /* Build configuration list for PBXProject "SULoader" */ = { 560 | isa = XCConfigurationList; 561 | buildConfigurations = ( 562 | B135ED291D1D079800A67702 /* Debug */, 563 | B135ED2A1D1D079800A67702 /* Release */, 564 | ); 565 | defaultConfigurationIsVisible = 0; 566 | defaultConfigurationName = Release; 567 | }; 568 | B135ED2B1D1D079800A67702 /* Build configuration list for PBXNativeTarget "SULoader" */ = { 569 | isa = XCConfigurationList; 570 | buildConfigurations = ( 571 | B135ED2C1D1D079800A67702 /* Debug */, 572 | B135ED2D1D1D079800A67702 /* Release */, 573 | ); 574 | defaultConfigurationIsVisible = 0; 575 | defaultConfigurationName = Release; 576 | }; 577 | B135ED2E1D1D079800A67702 /* Build configuration list for PBXNativeTarget "SULoaderTests" */ = { 578 | isa = XCConfigurationList; 579 | buildConfigurations = ( 580 | B135ED2F1D1D079800A67702 /* Debug */, 581 | B135ED301D1D079800A67702 /* Release */, 582 | ); 583 | defaultConfigurationIsVisible = 0; 584 | defaultConfigurationName = Release; 585 | }; 586 | B135ED311D1D079800A67702 /* Build configuration list for PBXNativeTarget "SULoaderUITests" */ = { 587 | isa = XCConfigurationList; 588 | buildConfigurations = ( 589 | B135ED321D1D079800A67702 /* Debug */, 590 | B135ED331D1D079800A67702 /* Release */, 591 | ); 592 | defaultConfigurationIsVisible = 0; 593 | defaultConfigurationName = Release; 594 | }; 595 | /* End XCConfigurationList section */ 596 | }; 597 | rootObject = B135ECF61D1D079800A67702 /* Project object */; 598 | } 599 | -------------------------------------------------------------------------------- /SULoader.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SULoader/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /SULoader/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | /* 46 | - (void)addRequest:(AVAssetResourceLoadingRequest *)loadingRequest{ 47 | //如果loader没有取消 48 | if(self.isCancelled==NO){ 49 | //从指定位置开始请求数据操作 50 | [self startOperationFromOffset:loadingRequest.dataRequest.requestedOffset length:loadingRequest.dataRequest.requestedLength]; 51 | //加入到数组中 52 | [self.pendingRequests addObject:loadingRequest]; 53 | } 54 | //如果已取消 55 | else{ 56 | //如果请求还没完成,则将其取消 57 | if(loadingRequest.isFinished==NO){ 58 | [loadingRequest finishLoadingWithError:[self loaderCancelledError]]; 59 | } 60 | } 61 | } 62 | 63 | - (void)removeRequest:(AVAssetResourceLoadingRequest *)loadingRequest{ 64 | //从数组中移除 65 | [self.pendingRequests removeObject:loadingRequest]; 66 | } 67 | 68 | - (void)cancel{ 69 | //取消标记设置为yes 70 | self.isCancelled = YES; 71 | //取消所有请求 72 | for(AVAssetResourceLoadingRequest *pendingRequest in self.pendingRequests){ 73 | if(pendingRequest.isFinished==NO){ 74 | [pendingRequest finishLoadingWithError:[self loaderCancelledError]]; 75 | } 76 | } 77 | [self.pendingRequests removeAllObjects]; 78 | //取消所有操作 79 | if(self.contentInfoOperation){ 80 | [self.contentInfoOperation cancel]; 81 | self.contentInfoOperation = nil; 82 | } 83 | if(self.dataOperation){ 84 | [self.dataOperation cancel]; 85 | self.dataOperation = nil; 86 | } 87 | //清除缓存 88 | if (self.writingFileHandle != nil){ 89 | [self.writingFileHandle closeFile]; 90 | self.writingFileHandle = nil; 91 | } 92 | if (self.readingFileHandle != nil){ 93 | [self.readingFileHandle closeFile]; 94 | self.readingFileHandle = nil; 95 | } 96 | if (self.cachedFilePath != nil && [[NSFileManager defaultManager] fileExistsAtPath:self.cachedFilePath]){ 97 | [[NSFileManager defaultManager] removeItemAtPath:self.cachedFilePath error:nil]; 98 | } 99 | } 100 | 101 | - (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest { 102 | //1、提取URL 103 | NSURL * resourceURL = loadingRequest.request.URL; 104 | //2、如果是自定义的scheme 105 | if ([resourceURL.scheme isEqualToString:CustomScheme]) { 106 | //3、找到其对应的Loader 107 | NSString * requestKey = resourceURL.absoluteString; 108 | SUResourceLoader * loader = [sResourceLoaders objectForKey:requestKey]; 109 | //4、如果没有找到则新生成一个 110 | if (loader == nil) { 111 | loader = [[SUResourceLoader alloc]initWithResourceURL:resourceURL session:sSession]; 112 | loader.delegate = self; 113 | [sResourceLoaders setObject:loader forKey:resourceURL.absoluteString]; 114 | } 115 | //将请求加入到loader中 116 | [loader addRequest:loadingRequest]; 117 | return YES; 118 | } 119 | return NO; 120 | } 121 | 122 | - (void)resourceLoader:(AVAssetResourceLoader *)resourceLoader didCancelLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest { 123 | //1、提取URL 124 | NSURL * resourceURL = loadingRequest.request.URL; 125 | //2、如果是自定义的scheme 126 | if ([resourceURL.scheme isEqualToString:CustomScheme]) { 127 | //3、找到其对应的Loader 128 | NSString * requestKey = resourceURL.absoluteString; 129 | SUResourceLoader * loader = [sResourceLoaders objectForKey:requestKey]; 130 | //将请求从loader中移除 131 | [loader removeRequest:loadingRequest]; 132 | } 133 | } 134 | */ 135 | 136 | @end 137 | -------------------------------------------------------------------------------- /SULoader/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /SULoader/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 | 27 | 28 | -------------------------------------------------------------------------------- /SULoader/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 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 54 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 88 | 99 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /SULoader/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | UILaunchStoryboardName 31 | LaunchScreen 32 | UIMainStoryboardFile 33 | Main 34 | UIRequiredDeviceCapabilities 35 | 36 | armv7 37 | 38 | UISupportedInterfaceOrientations 39 | 40 | UIInterfaceOrientationPortrait 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UISupportedInterfaceOrientations~ipad 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationPortraitUpsideDown 48 | UIInterfaceOrientationLandscapeLeft 49 | UIInterfaceOrientationLandscapeRight 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /SULoader/SULoader/Category/NSString+SULoader.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+SULoader.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (SULoader) 12 | 13 | /** 14 | * 临时文件路径 15 | */ 16 | + (NSString *)tempFilePath; 17 | 18 | /** 19 | * 缓存文件夹路径 20 | */ 21 | + (NSString *)cacheFolderPath; 22 | 23 | /** 24 | * 获取网址中的文件名 25 | */ 26 | + (NSString *)fileNameWithURL:(NSURL *)url; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /SULoader/SULoader/Category/NSString+SULoader.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+SULoader.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "NSString+SULoader.h" 10 | 11 | @implementation NSString (SULoader) 12 | 13 | + (NSString *)tempFilePath { 14 | return [[NSHomeDirectory( ) stringByAppendingPathComponent:@"tmp"] stringByAppendingPathComponent:@"MusicTemp.mp4"]; 15 | } 16 | 17 | 18 | + (NSString *)cacheFolderPath { 19 | return [[NSHomeDirectory( ) stringByAppendingPathComponent:@"Library"] stringByAppendingPathComponent:@"MusicCaches"]; 20 | } 21 | 22 | + (NSString *)fileNameWithURL:(NSURL *)url { 23 | return [[url.path componentsSeparatedByString:@"/"] lastObject]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /SULoader/SULoader/Category/NSURL+SULoader.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+SULoader.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSURL (SULoader) 12 | 13 | /** 14 | * 自定义scheme 15 | */ 16 | - (NSURL *)customSchemeURL; 17 | 18 | /** 19 | * 还原scheme 20 | */ 21 | - (NSURL *)originalSchemeURL; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /SULoader/SULoader/Category/NSURL+SULoader.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSURL+SULoader.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "NSURL+SULoader.h" 10 | 11 | @implementation NSURL (SULoader) 12 | 13 | - (NSURL *)customSchemeURL { 14 | NSURLComponents * components = [[NSURLComponents alloc] initWithURL:self resolvingAgainstBaseURL:NO]; 15 | components.scheme = @"streaming"; 16 | return [components URL]; 17 | } 18 | 19 | - (NSURL *)originalSchemeURL { 20 | NSURLComponents * components = [[NSURLComponents alloc] initWithURL:self resolvingAgainstBaseURL:NO]; 21 | components.scheme = @"http"; 22 | return [components URL]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /SULoader/SULoader/Category/SULoaderCategory.h: -------------------------------------------------------------------------------- 1 | // 2 | // SULoaderCategory.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #ifndef SULoaderCategory_h 10 | #define SULoaderCategory_h 11 | 12 | #import "NSURL+SULoader.h" 13 | #import "NSString+SULoader.h" 14 | 15 | #endif /* SULoaderCategory_h */ 16 | -------------------------------------------------------------------------------- /SULoader/SULoader/SUFileHandle.h: -------------------------------------------------------------------------------- 1 | // 2 | // SUFileHandle.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SULoaderCategory.h" 11 | 12 | @interface SUFileHandle : NSObject 13 | 14 | /** 15 | * 创建临时文件 16 | */ 17 | + (BOOL)createTempFile; 18 | 19 | /** 20 | * 往临时文件写入数据 21 | */ 22 | + (void)writeTempFileData:(NSData *)data; 23 | 24 | /** 25 | * 读取临时文件数据 26 | */ 27 | + (NSData *)readTempFileDataWithOffset:(NSUInteger)offset length:(NSUInteger)length; 28 | 29 | /** 30 | * 保存临时文件到缓存文件夹 31 | */ 32 | + (void)cacheTempFileWithFileName:(NSString *)name; 33 | 34 | /** 35 | * 是否存在缓存文件 存在:返回文件路径 不存在:返回nil 36 | */ 37 | + (NSString *)cacheFileExistsWithURL:(NSURL *)url; 38 | 39 | /** 40 | * 清空缓存文件 41 | */ 42 | + (BOOL)clearCache; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /SULoader/SULoader/SUFileHandle.m: -------------------------------------------------------------------------------- 1 | // 2 | // SUFileHandle.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "SUFileHandle.h" 10 | 11 | @interface SUFileHandle () 12 | 13 | @property (nonatomic, strong) NSFileHandle * writeFileHandle; 14 | @property (nonatomic, strong) NSFileHandle * readFileHandle; 15 | 16 | @end 17 | 18 | @implementation SUFileHandle 19 | 20 | + (BOOL)createTempFile { 21 | NSFileManager * manager = [NSFileManager defaultManager]; 22 | NSString * path = [NSString tempFilePath]; 23 | if ([manager fileExistsAtPath:path]) { 24 | [manager removeItemAtPath:path error:nil]; 25 | } 26 | return [manager createFileAtPath:path contents:nil attributes:nil]; 27 | } 28 | 29 | + (void)writeTempFileData:(NSData *)data { 30 | NSFileHandle * handle = [NSFileHandle fileHandleForWritingAtPath:[NSString tempFilePath]]; 31 | [handle seekToEndOfFile]; 32 | [handle writeData:data]; 33 | } 34 | 35 | + (NSData *)readTempFileDataWithOffset:(NSUInteger)offset length:(NSUInteger)length { 36 | NSFileHandle * handle = [NSFileHandle fileHandleForReadingAtPath:[NSString tempFilePath]]; 37 | [handle seekToFileOffset:offset]; 38 | return [handle readDataOfLength:length]; 39 | } 40 | 41 | + (void)cacheTempFileWithFileName:(NSString *)name { 42 | NSFileManager * manager = [NSFileManager defaultManager]; 43 | NSString * cacheFolderPath = [NSString cacheFolderPath]; 44 | if (![manager fileExistsAtPath:cacheFolderPath]) { 45 | [manager createDirectoryAtPath:cacheFolderPath withIntermediateDirectories:YES attributes:nil error:nil]; 46 | } 47 | NSString * cacheFilePath = [NSString stringWithFormat:@"%@/%@", cacheFolderPath, name]; 48 | BOOL success = [[NSFileManager defaultManager] copyItemAtPath:[NSString tempFilePath] toPath:cacheFilePath error:nil]; 49 | NSLog(@"cache file : %@", success ? @"success" : @"fail"); 50 | } 51 | 52 | + (NSString *)cacheFileExistsWithURL:(NSURL *)url { 53 | NSString * cacheFilePath = [NSString stringWithFormat:@"%@/%@", [NSString cacheFolderPath], [NSString fileNameWithURL:url]]; 54 | if ([[NSFileManager defaultManager] fileExistsAtPath:cacheFilePath]) { 55 | return cacheFilePath; 56 | } 57 | return nil; 58 | } 59 | 60 | + (BOOL)clearCache { 61 | NSFileManager * manager = [NSFileManager defaultManager]; 62 | return [manager removeItemAtPath:[NSString cacheFolderPath] error:nil]; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /SULoader/SULoader/SUPlayer.h: -------------------------------------------------------------------------------- 1 | // 2 | // SUPlayer.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SUResourceLoader.h" 11 | 12 | typedef NS_ENUM(NSInteger, SUPlayerState) { 13 | SUPlayerStateWaiting, 14 | SUPlayerStatePlaying, 15 | SUPlayerStatePaused, 16 | SUPlayerStateStopped, 17 | SUPlayerStateBuffering, 18 | SUPlayerStateError 19 | }; 20 | 21 | @interface SUPlayer : NSObject 22 | 23 | @property (nonatomic, assign) SUPlayerState state; 24 | @property (nonatomic, assign) CGFloat progress; 25 | @property (nonatomic, assign) CGFloat duration; 26 | @property (nonatomic, assign) CGFloat cacheProgress; 27 | 28 | /** 29 | * 初始化方法,url:歌曲的网络地址或者本地地址 30 | */ 31 | - (instancetype)initWithURL:(NSURL *)url; 32 | 33 | /** 34 | * 播放下一首歌曲,url:歌曲的网络地址或者本地地址 35 | * 逻辑:stop -> replace -> play 36 | */ 37 | - (void)replaceItemWithURL:(NSURL *)url; 38 | 39 | /** 40 | * 播放 41 | */ 42 | - (void)play; 43 | 44 | /** 45 | * 暂停 46 | */ 47 | - (void)pause; 48 | 49 | /** 50 | * 停止 51 | */ 52 | - (void)stop; 53 | 54 | /** 55 | * 正在播放 56 | */ 57 | - (BOOL)isPlaying; 58 | 59 | /** 60 | * 跳到某个时间进度 61 | */ 62 | - (void)seekToTime:(CGFloat)seconds; 63 | 64 | /** 65 | * 当前歌曲缓存情况 YES:已缓存 NO:未缓存(seek过的歌曲都不会缓存) 66 | */ 67 | - (BOOL)currentItemCacheState; 68 | 69 | /** 70 | * 当前歌曲缓存文件完整路径 71 | */ 72 | - (NSString *)currentItemCacheFilePath; 73 | 74 | /** 75 | * 清除缓存 76 | */ 77 | + (BOOL)clearCache; 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /SULoader/SULoader/SUPlayer.m: -------------------------------------------------------------------------------- 1 | // 2 | // SUPlayer.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "SUPlayer.h" 10 | 11 | @interface SUPlayer () 12 | 13 | @property (nonatomic, strong) NSURL * url; 14 | @property (nonatomic, strong) AVPlayer * player; 15 | @property (nonatomic, strong) AVPlayerItem * currentItem; 16 | @property (nonatomic, strong) SUResourceLoader * resourceLoader; 17 | 18 | @property (nonatomic, strong) id timeObserve; 19 | 20 | @end 21 | 22 | 23 | @implementation SUPlayer 24 | 25 | - (instancetype)initWithURL:(NSURL *)url { 26 | if (self == [super init]) { 27 | self.url = url; 28 | [self reloadCurrentItem]; 29 | } 30 | return self; 31 | } 32 | 33 | - (void)reloadCurrentItem { 34 | //Item 35 | if ([self.url.absoluteString hasPrefix:@"http"]) { 36 | //有缓存播放缓存文件 37 | NSString * cacheFilePath = [SUFileHandle cacheFileExistsWithURL:self.url]; 38 | if (cacheFilePath) { 39 | NSURL * url = [NSURL fileURLWithPath:cacheFilePath]; 40 | self.currentItem = [AVPlayerItem playerItemWithURL:url]; 41 | NSLog(@"有缓存,播放缓存文件"); 42 | }else { 43 | //没有缓存播放网络文件 44 | self.resourceLoader = [[SUResourceLoader alloc]init]; 45 | self.resourceLoader.delegate = self; 46 | 47 | AVURLAsset * asset = [AVURLAsset URLAssetWithURL:[self.url customSchemeURL] options:nil]; 48 | [asset.resourceLoader setDelegate:self.resourceLoader queue:dispatch_get_main_queue()]; 49 | self.currentItem = [AVPlayerItem playerItemWithAsset:asset]; 50 | NSLog(@"无缓存,播放网络文件"); 51 | } 52 | }else { 53 | self.currentItem = [AVPlayerItem playerItemWithURL:self.url]; 54 | NSLog(@"播放本地文件"); 55 | } 56 | //Player 57 | self.player = [AVPlayer playerWithPlayerItem:self.currentItem]; 58 | 59 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionInterrupted:) name:AVAudioSessionInterruptionNotification object:nil]; 60 | 61 | //Observer 62 | [self addObserver]; 63 | 64 | //State 65 | _state = SUPlayerStateWaiting; 66 | } 67 | 68 | - (void)replaceItemWithURL:(NSURL *)url { 69 | self.url = url; 70 | [self reloadCurrentItem]; 71 | } 72 | 73 | 74 | - (void)play { 75 | if (self.state == SUPlayerStatePaused || self.state == SUPlayerStateWaiting) { 76 | [self.player play]; 77 | } 78 | } 79 | 80 | 81 | - (void)pause { 82 | if (self.state == SUPlayerStatePlaying) { 83 | [self.player pause]; 84 | } 85 | } 86 | 87 | - (BOOL)isPlaying{ 88 | if (self.state == SUPlayerStatePlaying) { 89 | return YES; 90 | } 91 | return NO; 92 | } 93 | 94 | - (void)stop { 95 | if (self.state == SUPlayerStateStopped) { 96 | return; 97 | } 98 | [self.player pause]; 99 | [self.resourceLoader stopLoading]; 100 | [self removeObserver]; 101 | self.resourceLoader = nil; 102 | self.currentItem = nil; 103 | self.player = nil; 104 | self.progress = 0.0; 105 | self.duration = 0.0; 106 | self.state = SUPlayerStateStopped; 107 | } 108 | 109 | - (void)seekToTime:(CGFloat)seconds { 110 | if (self.state == SUPlayerStatePlaying || self.state == SUPlayerStatePaused) { 111 | // 暂停后滑动slider后 暂停播放状态 112 | // 播放中后滑动slider后 自动播放状态 113 | // [self.player pause]; 114 | self.resourceLoader.seekRequired = YES; 115 | [self.player seekToTime:CMTimeMakeWithSeconds(seconds, NSEC_PER_SEC) completionHandler:^(BOOL finished) { 116 | NSLog(@"seekComplete!!"); 117 | if ([self isPlaying]) { 118 | [self.player play]; 119 | } 120 | }];; 121 | } 122 | } 123 | 124 | #pragma mark - NSNotification 打断处理 125 | 126 | - (void)audioSessionInterrupted:(NSNotification *)notification{ 127 | //通知类型 128 | NSDictionary * info = notification.userInfo; 129 | // AVAudioSessionInterruptionTypeBegan == 130 | if ([[info objectForKey:AVAudioSessionInterruptionTypeKey] integerValue] == 1) { 131 | [self.player pause]; 132 | }else{ 133 | [self.player play]; 134 | } 135 | } 136 | 137 | 138 | #pragma mark - KVO 139 | - (void)addObserver { 140 | AVPlayerItem * songItem = self.currentItem; 141 | //播放完成 142 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished) name:AVPlayerItemDidPlayToEndTimeNotification object:songItem]; 143 | //播放进度 144 | __weak typeof(self) weakSelf = self; 145 | self.timeObserve = [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1.0, 1.0) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) { 146 | CGFloat current = CMTimeGetSeconds(time); 147 | CGFloat total = CMTimeGetSeconds(songItem.duration); 148 | weakSelf.duration = total; 149 | weakSelf.progress = current / total; 150 | }]; 151 | [self.player addObserver:self forKeyPath:@"rate" options:NSKeyValueObservingOptionNew context:nil]; 152 | [songItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil]; 153 | [songItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; 154 | [songItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil]; 155 | [songItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil]; 156 | } 157 | 158 | - (void)removeObserver { 159 | AVPlayerItem * songItem = self.currentItem; 160 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 161 | if (self.timeObserve) { 162 | [self.player removeTimeObserver:self.timeObserve]; 163 | self.timeObserve = nil; 164 | } 165 | [songItem removeObserver:self forKeyPath:@"status"]; 166 | [songItem removeObserver:self forKeyPath:@"loadedTimeRanges"]; 167 | [songItem removeObserver:self forKeyPath:@"playbackBufferEmpty"]; 168 | [songItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"]; 169 | [self.player removeObserver:self forKeyPath:@"rate"]; 170 | [self.player replaceCurrentItemWithPlayerItem:nil]; 171 | } 172 | 173 | /** 174 | * 通过KVO监控播放器状态 175 | */ 176 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 177 | AVPlayerItem * songItem = object; 178 | if ([keyPath isEqualToString:@"loadedTimeRanges"]) { 179 | NSArray * array = songItem.loadedTimeRanges; 180 | CMTimeRange timeRange = [array.firstObject CMTimeRangeValue]; //本次缓冲的时间范围 181 | NSTimeInterval totalBuffer = CMTimeGetSeconds(timeRange.start) + CMTimeGetSeconds(timeRange.duration); //缓冲总长度 182 | NSLog(@"共缓冲%.2f",totalBuffer); 183 | } 184 | if ([keyPath isEqualToString:@"rate"]) { 185 | if (self.player.rate == 0.0) { 186 | _state = SUPlayerStatePaused; 187 | }else { 188 | _state = SUPlayerStatePlaying; 189 | } 190 | } 191 | } 192 | 193 | - (void)playbackFinished { 194 | NSLog(@"播放完成"); 195 | [self stop]; 196 | } 197 | 198 | #pragma mark - SULoaderDelegate 199 | - (void)loader:(SUResourceLoader *)loader cacheProgress:(CGFloat)progress { 200 | self.cacheProgress = progress; 201 | } 202 | 203 | #pragma mark - Property Set 204 | - (void)setProgress:(CGFloat)progress { 205 | [self willChangeValueForKey:@"progress"]; 206 | _progress = progress; 207 | [self didChangeValueForKey:@"progress"]; 208 | } 209 | 210 | - (void)setState:(SUPlayerState)state { 211 | [self willChangeValueForKey:@"progress"]; 212 | _state = state; 213 | [self didChangeValueForKey:@"progress"]; 214 | } 215 | 216 | - (void)setCacheProgress:(CGFloat)cacheProgress { 217 | [self willChangeValueForKey:@"progress"]; 218 | _cacheProgress = cacheProgress; 219 | [self didChangeValueForKey:@"progress"]; 220 | } 221 | 222 | - (void)setDuration:(CGFloat)duration { 223 | if (duration != _duration && !isnan(duration)) { 224 | [self willChangeValueForKey:@"duration"]; 225 | NSLog(@"duration %f",duration); 226 | _duration = duration; 227 | [self didChangeValueForKey:@"duration"]; 228 | } 229 | } 230 | 231 | #pragma mark - CacheFile 232 | - (BOOL)currentItemCacheState { 233 | if ([self.url.absoluteString hasPrefix:@"http"]) { 234 | if (self.resourceLoader) { 235 | return self.resourceLoader.cacheFinished; 236 | } 237 | return YES; 238 | } 239 | return NO; 240 | } 241 | 242 | - (NSString *)currentItemCacheFilePath { 243 | if (![self currentItemCacheState]) { 244 | return nil; 245 | } 246 | return [NSString stringWithFormat:@"%@/%@", [NSString cacheFolderPath], [NSString fileNameWithURL:self.url]];; 247 | } 248 | 249 | + (BOOL)clearCache { 250 | [SUFileHandle clearCache]; 251 | return YES; 252 | } 253 | 254 | @end 255 | -------------------------------------------------------------------------------- /SULoader/SULoader/SURequestTask.h: -------------------------------------------------------------------------------- 1 | // 2 | // SURequestTask.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "SUFileHandle.h" 11 | 12 | #define RequestTimeout 10.0 13 | 14 | @class SURequestTask; 15 | @protocol SURequestTaskDelegate 16 | 17 | @required 18 | - (void)requestTaskDidUpdateCache; //更新缓冲进度代理方法 19 | 20 | @optional 21 | - (void)requestTaskDidReceiveResponse; 22 | - (void)requestTaskDidFinishLoadingWithCache:(BOOL)cache; 23 | - (void)requestTaskDidFailWithError:(NSError *)error; 24 | 25 | @end 26 | 27 | @interface SURequestTask : NSObject 28 | 29 | @property (nonatomic, weak) id delegate; 30 | @property (nonatomic, strong) NSURL * requestURL; //请求网址 31 | @property (nonatomic, assign) NSUInteger requestOffset; //请求起始位置 32 | @property (nonatomic, assign) NSUInteger fileLength; //文件长度 33 | @property (nonatomic, assign) NSUInteger cacheLength; //缓冲长度 34 | @property (nonatomic, assign) BOOL cache; //是否缓存文件 35 | @property (nonatomic, assign) BOOL cancel; //是否取消请求 36 | 37 | /** 38 | * 开始请求 39 | */ 40 | - (void)start; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /SULoader/SULoader/SURequestTask.m: -------------------------------------------------------------------------------- 1 | // 2 | // SURequestTask.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/28. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "SURequestTask.h" 10 | 11 | @interface SURequestTask () 12 | 13 | @property (nonatomic, strong) NSURLSession * session; //会话对象 14 | @property (nonatomic, strong) NSURLSessionDataTask * task; //任务 15 | 16 | @end 17 | 18 | @implementation SURequestTask 19 | 20 | - (instancetype)init { 21 | if (self = [super init]) { 22 | [SUFileHandle createTempFile]; 23 | } 24 | return self; 25 | } 26 | 27 | - (void)start { 28 | NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[self.requestURL originalSchemeURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:RequestTimeout]; 29 | if (self.requestOffset > 0) { 30 | [request addValue:[NSString stringWithFormat:@"bytes=%ld-%ld", self.requestOffset, self.fileLength - 1] forHTTPHeaderField:@"Range"]; 31 | } 32 | self.session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]]; 33 | self.task = [self.session dataTaskWithRequest:request]; 34 | [self.task resume]; 35 | } 36 | 37 | - (void)setCancel:(BOOL)cancel { 38 | _cancel = cancel; 39 | [self.task cancel]; 40 | [self.session invalidateAndCancel]; 41 | } 42 | 43 | #pragma mark - NSURLSessionDataDelegate 44 | //服务器响应 45 | - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)response completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler { 46 | if (self.cancel) return; 47 | NSLog(@"response: %@",response); 48 | completionHandler(NSURLSessionResponseAllow); 49 | NSHTTPURLResponse * httpResponse = (NSHTTPURLResponse *)response; 50 | NSString * contentRange = [[httpResponse allHeaderFields] objectForKey:@"Content-Range"]; 51 | NSString * fileLength = [[contentRange componentsSeparatedByString:@"/"] lastObject]; 52 | self.fileLength = fileLength.integerValue > 0 ? fileLength.integerValue : response.expectedContentLength; 53 | 54 | if (self.delegate && [self.delegate respondsToSelector:@selector(requestTaskDidReceiveResponse)]) { 55 | [self.delegate requestTaskDidReceiveResponse]; 56 | } 57 | } 58 | 59 | //服务器返回数据 可能会调用多次 60 | - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data { 61 | if (self.cancel) return; 62 | [SUFileHandle writeTempFileData:data]; 63 | self.cacheLength += data.length; 64 | if (self.delegate && [self.delegate respondsToSelector:@selector(requestTaskDidUpdateCache)]) { 65 | [self.delegate requestTaskDidUpdateCache]; 66 | } 67 | } 68 | 69 | //请求完成会调用该方法,请求失败则error有值 70 | - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { 71 | if (self.cancel) { 72 | NSLog(@"下载取消"); 73 | }else { 74 | if (error) { 75 | if (self.delegate && [self.delegate respondsToSelector:@selector(requestTaskDidFailWithError:)]) { 76 | [self.delegate requestTaskDidFailWithError:error]; 77 | } 78 | }else { 79 | //可以缓存则保存文件 80 | if (self.cache) { 81 | [SUFileHandle cacheTempFileWithFileName:[NSString fileNameWithURL:self.requestURL]]; 82 | } 83 | if (self.delegate && [self.delegate respondsToSelector:@selector(requestTaskDidFinishLoadingWithCache:)]) { 84 | [self.delegate requestTaskDidFinishLoadingWithCache:self.cache]; 85 | } 86 | } 87 | } 88 | } 89 | 90 | @end 91 | -------------------------------------------------------------------------------- /SULoader/SULoader/SUResourceLoader.h: -------------------------------------------------------------------------------- 1 | // 2 | // SULoader.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import "SURequestTask.h" 12 | 13 | #define MimeType @"video/mp4" 14 | 15 | @class SUResourceLoader; 16 | @protocol SULoaderDelegate 17 | 18 | @required 19 | - (void)loader:(SUResourceLoader *)loader cacheProgress:(CGFloat)progress; 20 | 21 | @optional 22 | - (void)loader:(SUResourceLoader *)loader failLoadingWithError:(NSError *)error; 23 | 24 | @end 25 | 26 | @interface SUResourceLoader : NSObject 27 | 28 | @property (nonatomic, weak) id delegate; 29 | @property (atomic, assign) BOOL seekRequired; //Seek标识 30 | @property (nonatomic, assign) BOOL cacheFinished; 31 | 32 | - (void)stopLoading; 33 | 34 | @end 35 | 36 | -------------------------------------------------------------------------------- /SULoader/SULoader/SUResourceLoader.m: -------------------------------------------------------------------------------- 1 | // 2 | // SULoader.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "SUResourceLoader.h" 10 | #import 11 | 12 | @interface SUResourceLoader () 13 | 14 | @property (nonatomic, strong) NSMutableArray * requestList; 15 | @property (nonatomic, strong) SURequestTask * requestTask; 16 | 17 | @end 18 | 19 | @implementation SUResourceLoader 20 | 21 | - (instancetype)init { 22 | if (self = [super init]) { 23 | self.requestList = [NSMutableArray array]; 24 | } 25 | return self; 26 | } 27 | 28 | - (void)stopLoading { 29 | self.requestTask.cancel = YES; 30 | } 31 | 32 | #pragma mark - AVAssetResourceLoaderDelegate 33 | - (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest { 34 | NSLog(@"WaitingLoadingRequest < requestedOffset = %lld, currentOffset = %lld, requestedLength = %ld >", loadingRequest.dataRequest.requestedOffset, loadingRequest.dataRequest.currentOffset, loadingRequest.dataRequest.requestedLength); 35 | [self addLoadingRequest:loadingRequest]; 36 | return YES; 37 | } 38 | 39 | - (void)resourceLoader:(AVAssetResourceLoader *)resourceLoader didCancelLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest { 40 | NSLog(@"CancelLoadingRequest < requestedOffset = %lld, currentOffset = %lld, requestedLength = %ld >", loadingRequest.dataRequest.requestedOffset, loadingRequest.dataRequest.currentOffset, loadingRequest.dataRequest.requestedLength); 41 | [self removeLoadingRequest:loadingRequest]; 42 | } 43 | 44 | #pragma mark - SURequestTaskDelegate 45 | - (void)requestTaskDidUpdateCache { 46 | [self processRequestList]; 47 | if (self.delegate && [self.delegate respondsToSelector:@selector(loader:cacheProgress:)]) { 48 | CGFloat cacheProgress = (CGFloat)self.requestTask.cacheLength / (self.requestTask.fileLength - self.requestTask.requestOffset); 49 | [self.delegate loader:self cacheProgress:cacheProgress]; 50 | } 51 | } 52 | 53 | - (void)requestTaskDidFinishLoadingWithCache:(BOOL)cache { 54 | self.cacheFinished = cache; 55 | } 56 | 57 | - (void)requestTaskDidFailWithError:(NSError *)error { 58 | //加载数据错误的处理 59 | } 60 | 61 | #pragma mark - 处理LoadingRequest 62 | - (void)addLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest { 63 | [self.requestList addObject:loadingRequest]; 64 | @synchronized(self) { 65 | if (self.requestTask) { 66 | if (loadingRequest.dataRequest.requestedOffset >= self.requestTask.requestOffset && 67 | loadingRequest.dataRequest.requestedOffset <= self.requestTask.requestOffset + self.requestTask.cacheLength) { 68 | //数据已经缓存,则直接完成 69 | NSLog(@"数据已经缓存,则直接完成"); 70 | [self processRequestList]; 71 | }else { 72 | //数据还没缓存,则等待数据下载;如果是Seek操作,则重新请求 73 | if (self.seekRequired) { 74 | NSLog(@"Seek操作,则重新请求"); 75 | [self newTaskWithLoadingRequest:loadingRequest cache:NO]; 76 | } 77 | } 78 | }else { 79 | [self newTaskWithLoadingRequest:loadingRequest cache:YES]; 80 | } 81 | } 82 | } 83 | 84 | - (void)newTaskWithLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest cache:(BOOL)cache { 85 | NSUInteger fileLength = 0; 86 | if (self.requestTask) { 87 | fileLength = self.requestTask.fileLength; 88 | self.requestTask.cancel = YES; 89 | } 90 | self.requestTask = [[SURequestTask alloc]init]; 91 | self.requestTask.requestURL = loadingRequest.request.URL; 92 | self.requestTask.requestOffset = loadingRequest.dataRequest.requestedOffset; 93 | self.requestTask.cache = cache; 94 | if (fileLength > 0) { 95 | self.requestTask.fileLength = fileLength; 96 | } 97 | self.requestTask.delegate = self; 98 | [self.requestTask start]; 99 | self.seekRequired = NO; 100 | } 101 | 102 | - (void)removeLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest { 103 | [self.requestList removeObject:loadingRequest]; 104 | } 105 | 106 | - (void)processRequestList { 107 | NSMutableArray * finishRequestList = [NSMutableArray array]; 108 | for (AVAssetResourceLoadingRequest * loadingRequest in self.requestList) { 109 | if ([self finishLoadingWithLoadingRequest:loadingRequest]) { 110 | [finishRequestList addObject:loadingRequest]; 111 | } 112 | } 113 | [self.requestList removeObjectsInArray:finishRequestList]; 114 | } 115 | 116 | - (BOOL)finishLoadingWithLoadingRequest:(AVAssetResourceLoadingRequest *)loadingRequest { 117 | //填充信息 118 | CFStringRef contentType = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)(MimeType), NULL); 119 | loadingRequest.contentInformationRequest.contentType = CFBridgingRelease(contentType); 120 | loadingRequest.contentInformationRequest.byteRangeAccessSupported = YES; 121 | loadingRequest.contentInformationRequest.contentLength = self.requestTask.fileLength; 122 | 123 | //读文件,填充数据 124 | NSUInteger cacheLength = self.requestTask.cacheLength; 125 | NSUInteger requestedOffset = loadingRequest.dataRequest.requestedOffset; 126 | if (loadingRequest.dataRequest.currentOffset != 0) { 127 | requestedOffset = loadingRequest.dataRequest.currentOffset; 128 | } 129 | NSUInteger canReadLength = cacheLength - (requestedOffset - self.requestTask.requestOffset); 130 | NSUInteger respondLength = MIN(canReadLength, loadingRequest.dataRequest.requestedLength); 131 | 132 | // NSLog(@"cacheLength %ld, requestedOffset %lld, currentOffset %lld, canReadLength %ld, requestedLength %ld", cacheLength, loadingRequest.dataRequest.requestedOffset, loadingRequest.dataRequest.currentOffset,canReadLength, loadingRequest.dataRequest.requestedLength); 133 | 134 | [loadingRequest.dataRequest respondWithData:[SUFileHandle readTempFileDataWithOffset:requestedOffset - self.requestTask.requestOffset length:respondLength]]; 135 | 136 | //如果完全响应了所需要的数据,则完成 137 | NSUInteger nowendOffset = requestedOffset + canReadLength; 138 | NSUInteger reqEndOffset = loadingRequest.dataRequest.requestedOffset + loadingRequest.dataRequest.requestedLength; 139 | if (nowendOffset >= reqEndOffset) { 140 | [loadingRequest finishLoading]; 141 | return YES; 142 | } 143 | return NO; 144 | } 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /SULoader/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /SULoader/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "SUPlayer.h" 11 | 12 | // NSURL * url = [[NSBundle mainBundle]URLForResource:@"Take a back" withExtension:@"mp3"]; 13 | // NSURL *url = [NSURL URLWithString:@"http://zyvideo1.oss-cn-qingdao.aliyuncs.com/zyvd/7c/de/04ec95f4fd42d9d01f63b9683ad0"]; 14 | 15 | @interface ViewController () 16 | 17 | @property (nonatomic, strong) SUPlayer * player; 18 | @property (weak, nonatomic) IBOutlet UISlider *progressSlider; 19 | @property (weak, nonatomic) IBOutlet UIImageView *coverIv; 20 | @property (weak, nonatomic) IBOutlet UILabel *songName; 21 | @property (weak, nonatomic) IBOutlet UILabel *currentTime; 22 | @property (weak, nonatomic) IBOutlet UILabel *duration; 23 | @property (weak, nonatomic) IBOutlet UIImageView *bgIv; 24 | @property (nonatomic, assign) NSInteger songIndex; 25 | 26 | @end 27 | 28 | @implementation ViewController 29 | 30 | - (void)viewDidLoad { 31 | [super viewDidLoad]; 32 | 33 | UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]; 34 | UIVisualEffectView * effe = [[UIVisualEffectView alloc]initWithEffect:blur]; 35 | effe.alpha = 0.97; 36 | effe.frame = self.view.bounds; 37 | [self.view insertSubview:effe aboveSubview:self.bgIv]; 38 | 39 | NSURL * url = [NSURL URLWithString:[self songURLList][self.songIndex]]; 40 | self.player = [[SUPlayer alloc]initWithURL:url]; 41 | [self.player addObserver:self forKeyPath:@"progress" options:NSKeyValueObservingOptionNew context:nil]; 42 | [self.player addObserver:self forKeyPath:@"duration" options:NSKeyValueObservingOptionNew context:nil]; 43 | [self.player addObserver:self forKeyPath:@"cacheProgress" options:NSKeyValueObservingOptionNew context:nil]; 44 | [self.player play]; 45 | [self updateSongInfoShow]; 46 | 47 | [self.progressSlider addTarget:self action:@selector(changeProgress:) forControlEvents:UIControlEventTouchUpInside]; 48 | } 49 | 50 | - (void)changeProgress:(UISlider *)slider { 51 | float seekTime = self.player.duration * slider.value; 52 | [self.player seekToTime:seekTime]; 53 | } 54 | 55 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { 56 | if ([keyPath isEqualToString:@"progress"]) { 57 | if (self.progressSlider.state != UIControlStateHighlighted) { 58 | dispatch_async(dispatch_get_main_queue(), ^{ 59 | self.progressSlider.value = self.player.progress; 60 | self.currentTime.text = [self convertStringWithTime:self.player.duration * self.player.progress]; 61 | }); 62 | } 63 | } 64 | if ([keyPath isEqualToString:@"duration"]) { 65 | if (self.player.duration > 0) { 66 | self.duration.text = [self convertStringWithTime:self.player.duration]; 67 | self.duration.hidden = NO; 68 | self.currentTime.hidden = NO; 69 | }else { 70 | self.duration.hidden = YES; 71 | self.currentTime.hidden = YES; 72 | } 73 | } 74 | if ([keyPath isEqualToString:@"cacheProgress"]) { 75 | // NSLog(@"缓存进度:%f", self.player.cacheProgress); 76 | } 77 | } 78 | 79 | - (IBAction)play:(UIButton *)sender { 80 | if (sender.selected) { 81 | [self.player pause]; 82 | }else { 83 | [self.player play]; 84 | } 85 | sender.selected = !sender.selected; 86 | } 87 | 88 | - (IBAction)skipSong:(UIButton *)sender { 89 | self.songIndex ++; 90 | if (self.songIndex >= 4) self.songIndex = 0; 91 | 92 | [self.player stop]; 93 | NSURL * url = [NSURL URLWithString:[self songURLList][self.songIndex]]; 94 | [self.player replaceItemWithURL:url]; 95 | [self.player play]; 96 | [self updateSongInfoShow]; 97 | } 98 | 99 | - (void)updateSongInfoShow { 100 | self.songName.text = [self songNameList][self.songIndex]; 101 | 102 | [UIView transitionWithView:self.bgIv duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ 103 | self.bgIv.image = [UIImage imageNamed:[self songCoverList][self.songIndex]]; 104 | } completion:nil]; 105 | 106 | [UIView transitionWithView:self.coverIv duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ 107 | self.coverIv.image = [UIImage imageNamed:[self songCoverList][self.songIndex]]; 108 | } completion:nil]; 109 | } 110 | 111 | - (NSString *)convertStringWithTime:(float)time { 112 | if (isnan(time)) time = 0.f; 113 | int min = time / 60.0; 114 | int sec = time - min * 60; 115 | NSString * minStr = min > 9 ? [NSString stringWithFormat:@"%d",min] : [NSString stringWithFormat:@"0%d",min]; 116 | NSString * secStr = sec > 9 ? [NSString stringWithFormat:@"%d",sec] : [NSString stringWithFormat:@"0%d",sec]; 117 | NSString * timeStr = [NSString stringWithFormat:@"%@:%@",minStr, secStr]; 118 | return timeStr; 119 | } 120 | 121 | - (NSArray *)songNameList { 122 | return @[@"夏天的味道", @"没那种命", @"不得不爱", @"海阔天空"]; 123 | } 124 | 125 | - (NSArray *)songURLList { 126 | return @[@"http://download.lingyongqian.cn/music/AdagioSostenuto.mp3", 127 | @"http://download.lingyongqian.cn/music/ForElise.mp3", 128 | @"http://mr7.doubanio.com/39ec9c9b5bbac0af7b373d1c62c294a3/1/fm/song/p1393354_128k.mp4", 129 | @"http://mr7.doubanio.com/16c59061a6a82bbb92bdd21e626db152/0/fm/song/p966452_128k.mp4"]; 130 | } 131 | 132 | - (NSArray *)songCoverList { 133 | return @[@"p190415_128k.jpg", @"p1458183_128k.jpg", @"p1393354_128k.jpg", @"p966452_128k.jpg"]; 134 | } 135 | 136 | @end 137 | -------------------------------------------------------------------------------- /SULoader/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SULoader 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /SULoader/p1393354_128k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaMingShen/SUCacheLoader/3678f57bb69ae3419156ddec5fd21596dc9d0dce/SULoader/p1393354_128k.jpg -------------------------------------------------------------------------------- /SULoader/p1458183_128k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaMingShen/SUCacheLoader/3678f57bb69ae3419156ddec5fd21596dc9d0dce/SULoader/p1458183_128k.jpg -------------------------------------------------------------------------------- /SULoader/p190415_128k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaMingShen/SUCacheLoader/3678f57bb69ae3419156ddec5fd21596dc9d0dce/SULoader/p190415_128k.jpg -------------------------------------------------------------------------------- /SULoader/p966452_128k.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DaMingShen/SUCacheLoader/3678f57bb69ae3419156ddec5fd21596dc9d0dce/SULoader/p966452_128k.jpg -------------------------------------------------------------------------------- /SULoaderTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SULoaderTests/SULoaderTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SULoaderTests.m 3 | // SULoaderTests 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SULoaderTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SULoaderTests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | // Put setup code here. This method is called before the invocation of each test method in the class. 20 | } 21 | 22 | - (void)tearDown { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | [super tearDown]; 25 | } 26 | 27 | - (void)testExample { 28 | // This is an example of a functional test case. 29 | // Use XCTAssert and related functions to verify your tests produce the correct results. 30 | } 31 | 32 | - (void)testPerformanceExample { 33 | // This is an example of a performance test case. 34 | [self measureBlock:^{ 35 | // Put the code you want to measure the time of here. 36 | }]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /SULoaderUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SULoaderUITests/SULoaderUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // SULoaderUITests.m 3 | // SULoaderUITests 4 | // 5 | // Created by 万众科技 on 16/6/24. 6 | // Copyright © 2016年 万众科技. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SULoaderUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation SULoaderUITests 16 | 17 | - (void)setUp { 18 | [super setUp]; 19 | 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | 22 | // In UI tests it is usually best to stop immediately when a failure occurs. 23 | self.continueAfterFailure = NO; 24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 25 | [[[XCUIApplication alloc] init] launch]; 26 | 27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 28 | } 29 | 30 | - (void)tearDown { 31 | // Put teardown code here. This method is called after the invocation of each test method in the class. 32 | [super tearDown]; 33 | } 34 | 35 | - (void)testExample { 36 | // Use recording to get started writing UI tests. 37 | // Use XCTAssert and related functions to verify your tests produce the correct results. 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------