├── Podfile ├── README.md ├── VideoPlayerExample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── andrii.golovin.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── andrii.golovin.xcuserdatad │ └── xcschemes │ ├── VideoPlayerExample.xcscheme │ └── xcschememanagement.plist └── VideoPlayerExample ├── AGVideoPlayerView ├── AGVideoPlayerView.swift └── LICENSE.md ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json └── video_player_play_icon.imageset │ ├── Contents.json │ └── video_player_play_icon.pdf ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist └── ViewController.swift /Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment the next line to define a global platform for your project 2 | # platform :ios, '9.0' 3 | 4 | target 'VideoPlayerExample' do 5 | # Comment the next line if you're not using Swift and don't want to use dynamic frameworks 6 | use_frameworks! 7 | 8 | # Pods for VideoPlayerView 9 | pod 'PINRemoteImage' 10 | 11 | end 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AGVideoPlayerView 2 | 3 | It's a simple video player view based on AVPlayer with ability to autoplay video when view visible on the screen. 4 | 5 | ## Installing 6 | 7 | 1. Copy AGVideoPlayerView folder to your project. 8 | 2. Create UIView in the storyboard and set AGVideoPlayerView custom class for that view or create AGVideoPlayerView with ```AGVideoPlayerView(frame:)```. 9 | 3. Add PINRemoteImage to your project or replace it in the AGVideoPlayerView class with your implementation. 10 | (PINRemoteImage is required for asynchronous loading and caching of preview images for video.) 11 | 12 | **Sample** 13 | 14 | ``` 15 | let playerView = AGVideoPlayerView(frame: CGRect(x: 0, y: 0, width: 320, height: 240)) 16 | view.addSubview(playerView) 17 | 18 | playerView.videoUrl = URL(string: "http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4") 19 | playerView.previewImageUrl = URL(string: "https://i.ytimg.com/vi/aqz-KE-bpKQ/maxresdefault.jpg") 20 | 21 | playerView.shouldAutoplay = true //Automatically play the video when its view is visible on the screen. false by default. 22 | playerView.shouldAutoRepeat = true //Automatically replay video after playback is complete. false by default. 23 | playerView.showsCustomControls = true //Use AVPlayer's controls or custom. Now custom control view has only "Play" button. Add additional controls if needed. 24 | playerView.isMuted = true //Mute the video. 25 | playerView.minimumVisibilityValueForStartAutoPlay = 0.9 //Value from 0.0 to 1.0, which sets the minimum percentage of the video player's view visibility on the screen to start playback. 26 | playerView.shouldSwitchToFullscreen = true //Default value is 'false'. Automatically switch to full-screen mode when device orientation did change to landscape. 27 | ``` 28 | 29 | ## License 30 | 31 | This project is licensed under the MIT License - see the LICENSE.md file for details. 32 | -------------------------------------------------------------------------------- /VideoPlayerExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 052DC6DB1F2F5644004D7931 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 052DC6DA1F2F5644004D7931 /* AppDelegate.swift */; }; 11 | 052DC6DD1F2F5644004D7931 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 052DC6DC1F2F5644004D7931 /* ViewController.swift */; }; 12 | 052DC6E01F2F5644004D7931 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 052DC6DE1F2F5644004D7931 /* Main.storyboard */; }; 13 | 052DC6E21F2F5644004D7931 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 052DC6E11F2F5644004D7931 /* Assets.xcassets */; }; 14 | 052DC6E51F2F5644004D7931 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 052DC6E31F2F5644004D7931 /* LaunchScreen.storyboard */; }; 15 | 052DC6EF1F2F565B004D7931 /* LICENSE.md in Resources */ = {isa = PBXBuildFile; fileRef = 052DC6ED1F2F565B004D7931 /* LICENSE.md */; }; 16 | 052DC6F01F2F565B004D7931 /* AGVideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 052DC6EE1F2F565B004D7931 /* AGVideoPlayerView.swift */; }; 17 | 052DC6F21F2F566D004D7931 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 052DC6F11F2F566D004D7931 /* Podfile */; }; 18 | 798C16B087BCB158D7315141 /* Pods_VideoPlayerExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C4BEF543B6C746DF951323F1 /* Pods_VideoPlayerExample.framework */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 052DC6D71F2F5644004D7931 /* VideoPlayerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VideoPlayerExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 052DC6DA1F2F5644004D7931 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | 052DC6DC1F2F5644004D7931 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | 052DC6DF1F2F5644004D7931 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 26 | 052DC6E11F2F5644004D7931 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | 052DC6E41F2F5644004D7931 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28 | 052DC6E61F2F5644004D7931 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | 052DC6ED1F2F565B004D7931 /* LICENSE.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = ""; }; 30 | 052DC6EE1F2F565B004D7931 /* AGVideoPlayerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AGVideoPlayerView.swift; sourceTree = ""; }; 31 | 052DC6F11F2F566D004D7931 /* Podfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 32 | 052DC6F31F2F5671004D7931 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = SOURCE_ROOT; }; 33 | 24CB346AED97051837D1B964 /* Pods-VideoPlayerExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VideoPlayerExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-VideoPlayerExample/Pods-VideoPlayerExample.release.xcconfig"; sourceTree = ""; }; 34 | B26DA0593AC8CD33405E7ACE /* Pods-VideoPlayerExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VideoPlayerExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-VideoPlayerExample/Pods-VideoPlayerExample.debug.xcconfig"; sourceTree = ""; }; 35 | C4BEF543B6C746DF951323F1 /* Pods_VideoPlayerExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_VideoPlayerExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | /* End PBXFileReference section */ 37 | 38 | /* Begin PBXFrameworksBuildPhase section */ 39 | 052DC6D41F2F5644004D7931 /* Frameworks */ = { 40 | isa = PBXFrameworksBuildPhase; 41 | buildActionMask = 2147483647; 42 | files = ( 43 | 798C16B087BCB158D7315141 /* Pods_VideoPlayerExample.framework in Frameworks */, 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | /* End PBXFrameworksBuildPhase section */ 48 | 49 | /* Begin PBXGroup section */ 50 | 052DC6CE1F2F5644004D7931 = { 51 | isa = PBXGroup; 52 | children = ( 53 | 052DC6D91F2F5644004D7931 /* VideoPlayerExample */, 54 | 052DC6D81F2F5644004D7931 /* Products */, 55 | 5EBFFBB0466E2419B5F90DDA /* Pods */, 56 | 29F98787EAA406C6801867E0 /* Frameworks */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | 052DC6D81F2F5644004D7931 /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 052DC6D71F2F5644004D7931 /* VideoPlayerExample.app */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | 052DC6D91F2F5644004D7931 /* VideoPlayerExample */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 052DC6EC1F2F565B004D7931 /* AGVideoPlayerView */, 72 | 052DC6DA1F2F5644004D7931 /* AppDelegate.swift */, 73 | 052DC6DC1F2F5644004D7931 /* ViewController.swift */, 74 | 052DC6DE1F2F5644004D7931 /* Main.storyboard */, 75 | 052DC6E11F2F5644004D7931 /* Assets.xcassets */, 76 | 052DC6E31F2F5644004D7931 /* LaunchScreen.storyboard */, 77 | 052DC6F11F2F566D004D7931 /* Podfile */, 78 | 052DC6F31F2F5671004D7931 /* README.md */, 79 | 052DC6E61F2F5644004D7931 /* Info.plist */, 80 | ); 81 | path = VideoPlayerExample; 82 | sourceTree = ""; 83 | }; 84 | 052DC6EC1F2F565B004D7931 /* AGVideoPlayerView */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 052DC6ED1F2F565B004D7931 /* LICENSE.md */, 88 | 052DC6EE1F2F565B004D7931 /* AGVideoPlayerView.swift */, 89 | ); 90 | path = AGVideoPlayerView; 91 | sourceTree = ""; 92 | }; 93 | 29F98787EAA406C6801867E0 /* Frameworks */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | C4BEF543B6C746DF951323F1 /* Pods_VideoPlayerExample.framework */, 97 | ); 98 | name = Frameworks; 99 | sourceTree = ""; 100 | }; 101 | 5EBFFBB0466E2419B5F90DDA /* Pods */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | B26DA0593AC8CD33405E7ACE /* Pods-VideoPlayerExample.debug.xcconfig */, 105 | 24CB346AED97051837D1B964 /* Pods-VideoPlayerExample.release.xcconfig */, 106 | ); 107 | name = Pods; 108 | sourceTree = ""; 109 | }; 110 | /* End PBXGroup section */ 111 | 112 | /* Begin PBXNativeTarget section */ 113 | 052DC6D61F2F5644004D7931 /* VideoPlayerExample */ = { 114 | isa = PBXNativeTarget; 115 | buildConfigurationList = 052DC6E91F2F5644004D7931 /* Build configuration list for PBXNativeTarget "VideoPlayerExample" */; 116 | buildPhases = ( 117 | BFBD76A97E4B839E7A0AF286 /* [CP] Check Pods Manifest.lock */, 118 | 052DC6D31F2F5644004D7931 /* Sources */, 119 | 052DC6D41F2F5644004D7931 /* Frameworks */, 120 | 052DC6D51F2F5644004D7931 /* Resources */, 121 | 370914FCC24978816B59516F /* [CP] Embed Pods Frameworks */, 122 | 7EC9DFB1E2FEA5856BC09DBC /* [CP] Copy Pods Resources */, 123 | ); 124 | buildRules = ( 125 | ); 126 | dependencies = ( 127 | ); 128 | name = VideoPlayerExample; 129 | productName = VideoPlayerExample; 130 | productReference = 052DC6D71F2F5644004D7931 /* VideoPlayerExample.app */; 131 | productType = "com.apple.product-type.application"; 132 | }; 133 | /* End PBXNativeTarget section */ 134 | 135 | /* Begin PBXProject section */ 136 | 052DC6CF1F2F5644004D7931 /* Project object */ = { 137 | isa = PBXProject; 138 | attributes = { 139 | LastSwiftUpdateCheck = 0830; 140 | LastUpgradeCheck = 0830; 141 | ORGANIZATIONNAME = "Andrey Golovin"; 142 | TargetAttributes = { 143 | 052DC6D61F2F5644004D7931 = { 144 | CreatedOnToolsVersion = 8.3.3; 145 | ProvisioningStyle = Automatic; 146 | }; 147 | }; 148 | }; 149 | buildConfigurationList = 052DC6D21F2F5644004D7931 /* Build configuration list for PBXProject "VideoPlayerExample" */; 150 | compatibilityVersion = "Xcode 3.2"; 151 | developmentRegion = English; 152 | hasScannedForEncodings = 0; 153 | knownRegions = ( 154 | en, 155 | Base, 156 | ); 157 | mainGroup = 052DC6CE1F2F5644004D7931; 158 | productRefGroup = 052DC6D81F2F5644004D7931 /* Products */; 159 | projectDirPath = ""; 160 | projectRoot = ""; 161 | targets = ( 162 | 052DC6D61F2F5644004D7931 /* VideoPlayerExample */, 163 | ); 164 | }; 165 | /* End PBXProject section */ 166 | 167 | /* Begin PBXResourcesBuildPhase section */ 168 | 052DC6D51F2F5644004D7931 /* Resources */ = { 169 | isa = PBXResourcesBuildPhase; 170 | buildActionMask = 2147483647; 171 | files = ( 172 | 052DC6F21F2F566D004D7931 /* Podfile in Resources */, 173 | 052DC6E51F2F5644004D7931 /* LaunchScreen.storyboard in Resources */, 174 | 052DC6E21F2F5644004D7931 /* Assets.xcassets in Resources */, 175 | 052DC6EF1F2F565B004D7931 /* LICENSE.md in Resources */, 176 | 052DC6E01F2F5644004D7931 /* Main.storyboard in Resources */, 177 | ); 178 | runOnlyForDeploymentPostprocessing = 0; 179 | }; 180 | /* End PBXResourcesBuildPhase section */ 181 | 182 | /* Begin PBXShellScriptBuildPhase section */ 183 | 370914FCC24978816B59516F /* [CP] Embed Pods Frameworks */ = { 184 | isa = PBXShellScriptBuildPhase; 185 | buildActionMask = 2147483647; 186 | files = ( 187 | ); 188 | inputPaths = ( 189 | "${SRCROOT}/Pods/Target Support Files/Pods-VideoPlayerExample/Pods-VideoPlayerExample-frameworks.sh", 190 | "${BUILT_PRODUCTS_DIR}/FLAnimatedImage/FLAnimatedImage.framework", 191 | "${BUILT_PRODUCTS_DIR}/PINCache/PINCache.framework", 192 | "${BUILT_PRODUCTS_DIR}/PINRemoteImage/PINRemoteImage.framework", 193 | ); 194 | name = "[CP] Embed Pods Frameworks"; 195 | outputPaths = ( 196 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FLAnimatedImage.framework", 197 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINCache.framework", 198 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PINRemoteImage.framework", 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | shellPath = /bin/sh; 202 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VideoPlayerExample/Pods-VideoPlayerExample-frameworks.sh\"\n"; 203 | showEnvVarsInLog = 0; 204 | }; 205 | 7EC9DFB1E2FEA5856BC09DBC /* [CP] Copy Pods Resources */ = { 206 | isa = PBXShellScriptBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | ); 210 | inputPaths = ( 211 | ); 212 | name = "[CP] Copy Pods Resources"; 213 | outputPaths = ( 214 | ); 215 | runOnlyForDeploymentPostprocessing = 0; 216 | shellPath = /bin/sh; 217 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-VideoPlayerExample/Pods-VideoPlayerExample-resources.sh\"\n"; 218 | showEnvVarsInLog = 0; 219 | }; 220 | BFBD76A97E4B839E7A0AF286 /* [CP] Check Pods Manifest.lock */ = { 221 | isa = PBXShellScriptBuildPhase; 222 | buildActionMask = 2147483647; 223 | files = ( 224 | ); 225 | inputPaths = ( 226 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 227 | "${PODS_ROOT}/Manifest.lock", 228 | ); 229 | name = "[CP] Check Pods Manifest.lock"; 230 | outputPaths = ( 231 | "$(DERIVED_FILE_DIR)/Pods-VideoPlayerExample-checkManifestLockResult.txt", 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | shellPath = /bin/sh; 235 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 236 | showEnvVarsInLog = 0; 237 | }; 238 | /* End PBXShellScriptBuildPhase section */ 239 | 240 | /* Begin PBXSourcesBuildPhase section */ 241 | 052DC6D31F2F5644004D7931 /* Sources */ = { 242 | isa = PBXSourcesBuildPhase; 243 | buildActionMask = 2147483647; 244 | files = ( 245 | 052DC6DD1F2F5644004D7931 /* ViewController.swift in Sources */, 246 | 052DC6DB1F2F5644004D7931 /* AppDelegate.swift in Sources */, 247 | 052DC6F01F2F565B004D7931 /* AGVideoPlayerView.swift in Sources */, 248 | ); 249 | runOnlyForDeploymentPostprocessing = 0; 250 | }; 251 | /* End PBXSourcesBuildPhase section */ 252 | 253 | /* Begin PBXVariantGroup section */ 254 | 052DC6DE1F2F5644004D7931 /* Main.storyboard */ = { 255 | isa = PBXVariantGroup; 256 | children = ( 257 | 052DC6DF1F2F5644004D7931 /* Base */, 258 | ); 259 | name = Main.storyboard; 260 | sourceTree = ""; 261 | }; 262 | 052DC6E31F2F5644004D7931 /* LaunchScreen.storyboard */ = { 263 | isa = PBXVariantGroup; 264 | children = ( 265 | 052DC6E41F2F5644004D7931 /* Base */, 266 | ); 267 | name = LaunchScreen.storyboard; 268 | sourceTree = ""; 269 | }; 270 | /* End PBXVariantGroup section */ 271 | 272 | /* Begin XCBuildConfiguration section */ 273 | 052DC6E71F2F5644004D7931 /* Debug */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ALWAYS_SEARCH_USER_PATHS = NO; 277 | CLANG_ANALYZER_NONNULL = YES; 278 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 279 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 280 | CLANG_CXX_LIBRARY = "libc++"; 281 | CLANG_ENABLE_MODULES = YES; 282 | CLANG_ENABLE_OBJC_ARC = YES; 283 | CLANG_WARN_BOOL_CONVERSION = YES; 284 | CLANG_WARN_CONSTANT_CONVERSION = YES; 285 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 286 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 287 | CLANG_WARN_EMPTY_BODY = YES; 288 | CLANG_WARN_ENUM_CONVERSION = YES; 289 | CLANG_WARN_INFINITE_RECURSION = YES; 290 | CLANG_WARN_INT_CONVERSION = YES; 291 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 292 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 293 | CLANG_WARN_UNREACHABLE_CODE = YES; 294 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 295 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 296 | COPY_PHASE_STRIP = NO; 297 | DEBUG_INFORMATION_FORMAT = dwarf; 298 | ENABLE_STRICT_OBJC_MSGSEND = YES; 299 | ENABLE_TESTABILITY = YES; 300 | GCC_C_LANGUAGE_STANDARD = gnu99; 301 | GCC_DYNAMIC_NO_PIC = NO; 302 | GCC_NO_COMMON_BLOCKS = YES; 303 | GCC_OPTIMIZATION_LEVEL = 0; 304 | GCC_PREPROCESSOR_DEFINITIONS = ( 305 | "DEBUG=1", 306 | "$(inherited)", 307 | ); 308 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 309 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 310 | GCC_WARN_UNDECLARED_SELECTOR = YES; 311 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 312 | GCC_WARN_UNUSED_FUNCTION = YES; 313 | GCC_WARN_UNUSED_VARIABLE = YES; 314 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 315 | MTL_ENABLE_DEBUG_INFO = YES; 316 | ONLY_ACTIVE_ARCH = YES; 317 | SDKROOT = iphoneos; 318 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 319 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 320 | }; 321 | name = Debug; 322 | }; 323 | 052DC6E81F2F5644004D7931 /* Release */ = { 324 | isa = XCBuildConfiguration; 325 | buildSettings = { 326 | ALWAYS_SEARCH_USER_PATHS = NO; 327 | CLANG_ANALYZER_NONNULL = YES; 328 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 329 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 330 | CLANG_CXX_LIBRARY = "libc++"; 331 | CLANG_ENABLE_MODULES = YES; 332 | CLANG_ENABLE_OBJC_ARC = YES; 333 | CLANG_WARN_BOOL_CONVERSION = YES; 334 | CLANG_WARN_CONSTANT_CONVERSION = YES; 335 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 336 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 337 | CLANG_WARN_EMPTY_BODY = YES; 338 | CLANG_WARN_ENUM_CONVERSION = YES; 339 | CLANG_WARN_INFINITE_RECURSION = YES; 340 | CLANG_WARN_INT_CONVERSION = YES; 341 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 342 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 343 | CLANG_WARN_UNREACHABLE_CODE = YES; 344 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 345 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 346 | COPY_PHASE_STRIP = NO; 347 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 348 | ENABLE_NS_ASSERTIONS = NO; 349 | ENABLE_STRICT_OBJC_MSGSEND = YES; 350 | GCC_C_LANGUAGE_STANDARD = gnu99; 351 | GCC_NO_COMMON_BLOCKS = YES; 352 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 353 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 354 | GCC_WARN_UNDECLARED_SELECTOR = YES; 355 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 356 | GCC_WARN_UNUSED_FUNCTION = YES; 357 | GCC_WARN_UNUSED_VARIABLE = YES; 358 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 359 | MTL_ENABLE_DEBUG_INFO = NO; 360 | SDKROOT = iphoneos; 361 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 362 | VALIDATE_PRODUCT = YES; 363 | }; 364 | name = Release; 365 | }; 366 | 052DC6EA1F2F5644004D7931 /* Debug */ = { 367 | isa = XCBuildConfiguration; 368 | baseConfigurationReference = B26DA0593AC8CD33405E7ACE /* Pods-VideoPlayerExample.debug.xcconfig */; 369 | buildSettings = { 370 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 371 | INFOPLIST_FILE = VideoPlayerExample/Info.plist; 372 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 373 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 374 | PRODUCT_BUNDLE_IDENTIFIER = AG.VideoPlayerExample; 375 | PRODUCT_NAME = "$(TARGET_NAME)"; 376 | SWIFT_VERSION = 3.0; 377 | }; 378 | name = Debug; 379 | }; 380 | 052DC6EB1F2F5644004D7931 /* Release */ = { 381 | isa = XCBuildConfiguration; 382 | baseConfigurationReference = 24CB346AED97051837D1B964 /* Pods-VideoPlayerExample.release.xcconfig */; 383 | buildSettings = { 384 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 385 | INFOPLIST_FILE = VideoPlayerExample/Info.plist; 386 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 387 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 388 | PRODUCT_BUNDLE_IDENTIFIER = AG.VideoPlayerExample; 389 | PRODUCT_NAME = "$(TARGET_NAME)"; 390 | SWIFT_VERSION = 3.0; 391 | }; 392 | name = Release; 393 | }; 394 | /* End XCBuildConfiguration section */ 395 | 396 | /* Begin XCConfigurationList section */ 397 | 052DC6D21F2F5644004D7931 /* Build configuration list for PBXProject "VideoPlayerExample" */ = { 398 | isa = XCConfigurationList; 399 | buildConfigurations = ( 400 | 052DC6E71F2F5644004D7931 /* Debug */, 401 | 052DC6E81F2F5644004D7931 /* Release */, 402 | ); 403 | defaultConfigurationIsVisible = 0; 404 | defaultConfigurationName = Release; 405 | }; 406 | 052DC6E91F2F5644004D7931 /* Build configuration list for PBXNativeTarget "VideoPlayerExample" */ = { 407 | isa = XCConfigurationList; 408 | buildConfigurations = ( 409 | 052DC6EA1F2F5644004D7931 /* Debug */, 410 | 052DC6EB1F2F5644004D7931 /* Release */, 411 | ); 412 | defaultConfigurationIsVisible = 0; 413 | defaultConfigurationName = Release; 414 | }; 415 | /* End XCConfigurationList section */ 416 | }; 417 | rootObject = 052DC6CF1F2F5644004D7931 /* Project object */; 418 | } 419 | -------------------------------------------------------------------------------- /VideoPlayerExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VideoPlayerExample.xcodeproj/project.xcworkspace/xcuserdata/andrii.golovin.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AG-iOS/AGVideoPlayerView/122458e67285989bc98fc8c631b088fd90b01d18/VideoPlayerExample.xcodeproj/project.xcworkspace/xcuserdata/andrii.golovin.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /VideoPlayerExample.xcodeproj/xcuserdata/andrii.golovin.xcuserdatad/xcschemes/VideoPlayerExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 69 | 70 | 71 | 72 | 73 | 74 | 80 | 82 | 88 | 89 | 90 | 91 | 93 | 94 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /VideoPlayerExample.xcodeproj/xcuserdata/andrii.golovin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | VideoPlayerExample.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 052DC6D61F2F5644004D7931 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /VideoPlayerExample/AGVideoPlayerView/AGVideoPlayerView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // VideoPlayerView.swift 3 | // 4 | // Created by andrii.golovin on 31.07.17. 5 | // Copyright © 2017 Andrey Golovin. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | import AVKit 10 | import AVFoundation 11 | import PINRemoteImage 12 | 13 | extension Notification.Name { 14 | static let playerDidChangeFullscreenMode = Notification.Name("playerDidEnterFullscreenMode") 15 | } 16 | 17 | class AGVideoPlayerView: UIView { 18 | 19 | //MARK: Public variables 20 | var videoUrl: URL? { 21 | didSet { 22 | prepareVideoPlayer() 23 | } 24 | } 25 | var previewImageUrl: URL? { 26 | didSet { 27 | previewImageView.pin_setImage(from: previewImageUrl, placeholderImage: UIImage()) 28 | previewImageView.isHidden = false 29 | } 30 | } 31 | 32 | //Automatically play the video when its view is visible on the screen. 33 | var shouldAutoplay: Bool = false { 34 | didSet { 35 | if shouldAutoplay { 36 | runTimer() 37 | } else { 38 | removeTimer() 39 | } 40 | } 41 | } 42 | 43 | //Automatically replay video after playback is complete. 44 | var shouldAutoRepeat: Bool = false { 45 | didSet { 46 | if oldValue == shouldAutoRepeat { return } 47 | if shouldAutoRepeat { 48 | NotificationCenter.default.addObserver(self, selector: #selector(itemDidFinishPlaying), name: .AVPlayerItemDidPlayToEndTime, object: nil) 49 | } else { 50 | NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil) 51 | } 52 | } 53 | } 54 | 55 | //Automatically switch to full-screen mode when device orientation did change to landscape. 56 | var shouldSwitchToFullscreen: Bool = false { 57 | didSet { 58 | if oldValue == shouldSwitchToFullscreen { return } 59 | if shouldSwitchToFullscreen { 60 | NotificationCenter.default.addObserver(self, selector: #selector(deviceOrientationDidChange(_:)), name: .UIDeviceOrientationDidChange, object: nil) 61 | } else { 62 | NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil) 63 | } 64 | } 65 | } 66 | 67 | //Use AVPlayer's controls or custom. Now custom control view has only "Play" button. Add additional controls if needed. 68 | var showsCustomControls: Bool = true { 69 | didSet { 70 | playerController.showsPlaybackControls = !showsCustomControls 71 | customControlsContentView.isHidden = !showsCustomControls 72 | } 73 | } 74 | 75 | //Value from 0.0 to 1.0, which sets the minimum percentage of the video player's view visibility on the screen to start playback. 76 | var minimumVisibilityValueForStartAutoPlay: CGFloat = 0.9 77 | 78 | //Mute the video. 79 | var isMuted: Bool = false { 80 | didSet { 81 | playerController.player?.isMuted = isMuted 82 | } 83 | } 84 | 85 | //MARK: Private variables 86 | fileprivate let playerController = AVPlayerViewController() 87 | fileprivate var isPlaying: Bool = false 88 | fileprivate var videoAsset: AVURLAsset? 89 | fileprivate var displayLink: CADisplayLink? 90 | 91 | fileprivate var previewImageView: UIImageView! 92 | fileprivate var customControlsContentView: UIView! 93 | fileprivate var playIcon: UIImageView! 94 | fileprivate var isFullscreen = false 95 | 96 | //MARK: Life cycle 97 | deinit { 98 | NotificationCenter.default.removeObserver(self) 99 | removePlayerObservers() 100 | displayLink?.invalidate() 101 | } 102 | 103 | required override init(frame: CGRect) { 104 | super.init(frame: frame) 105 | setUpView() 106 | } 107 | 108 | required init?(coder aDecoder: NSCoder) { 109 | super.init(coder: aDecoder) 110 | setUpView() 111 | } 112 | 113 | override func willMove(toWindow newWindow: UIWindow?) { 114 | super.willMove(toWindow: newWindow) 115 | if newWindow == nil { 116 | pause() 117 | removeTimer() 118 | } else { 119 | if shouldAutoplay { 120 | runTimer() 121 | } 122 | } 123 | } 124 | } 125 | 126 | //MARK: View configuration 127 | extension AGVideoPlayerView { 128 | fileprivate func setUpView() { 129 | self.backgroundColor = .black 130 | addVideoPlayerView() 131 | configurateControls() 132 | } 133 | 134 | private func addVideoPlayerView() { 135 | playerController.view.frame = self.bounds 136 | playerController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] 137 | playerController.showsPlaybackControls = false 138 | self.insertSubview(playerController.view, at: 0) 139 | } 140 | 141 | private func configurateControls() { 142 | customControlsContentView = UIView(frame: self.bounds) 143 | customControlsContentView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 144 | customControlsContentView.backgroundColor = .clear 145 | 146 | previewImageView = UIImageView(frame: self.bounds) 147 | previewImageView.contentMode = .scaleAspectFit 148 | previewImageView.autoresizingMask = [.flexibleWidth, .flexibleHeight] 149 | previewImageView.clipsToBounds = true 150 | 151 | playIcon = UIImageView(image: UIImage(named:"video_player_play_icon")) 152 | playIcon.isUserInteractionEnabled = true 153 | playIcon.frame = CGRect(x: 0, y: 0, width: 60, height: 60) 154 | playIcon.center = previewImageView!.center 155 | playIcon.autoresizingMask = [.flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin] 156 | 157 | addSubview(previewImageView!) 158 | customControlsContentView?.addSubview(playIcon) 159 | addSubview(customControlsContentView!) 160 | let playAction = UITapGestureRecognizer(target: self, action: #selector(didTapPlay)) 161 | playIcon.addGestureRecognizer(playAction) 162 | let pauseAction = UITapGestureRecognizer(target: self, action: #selector(didTapPause)) 163 | customControlsContentView.addGestureRecognizer(pauseAction) 164 | } 165 | } 166 | 167 | //MARK: Timer part 168 | extension AGVideoPlayerView { 169 | fileprivate func runTimer() { 170 | if displayLink != nil { 171 | displayLink?.isPaused = false 172 | return 173 | } 174 | displayLink = CADisplayLink(target: self, selector: #selector(timerAction)) 175 | if #available(iOS 10.0, *) { 176 | displayLink?.preferredFramesPerSecond = 5 177 | } else { 178 | displayLink?.frameInterval = 5 179 | } 180 | displayLink?.add(to: RunLoop.current, forMode: .commonModes) 181 | } 182 | 183 | fileprivate func removeTimer() { 184 | displayLink?.invalidate() 185 | displayLink = nil 186 | } 187 | 188 | @objc private func timerAction() { 189 | guard videoUrl != nil else { 190 | return 191 | } 192 | if isVisible() { 193 | play() 194 | } else { 195 | pause() 196 | } 197 | } 198 | } 199 | 200 | //MARK: Logic of the view's position search on the app screen. 201 | extension AGVideoPlayerView { 202 | fileprivate func isVisible() -> Bool { 203 | if self.window == nil { 204 | return false 205 | } 206 | let displayBounds = UIScreen.main.bounds 207 | let selfFrame = self.convert(self.bounds, to: UIApplication.shared.keyWindow) 208 | let intersection = displayBounds.intersection(selfFrame) 209 | let visibility = (intersection.width * intersection.height) / (frame.width * frame.height) 210 | return visibility >= minimumVisibilityValueForStartAutoPlay 211 | } 212 | } 213 | 214 | //MARK: Video player part 215 | extension AGVideoPlayerView { 216 | fileprivate func prepareVideoPlayer() { 217 | playerController.player?.removeObserver(self, forKeyPath: "rate") 218 | guard let url = videoUrl else { 219 | videoAsset = nil 220 | playerController.player = nil 221 | return 222 | } 223 | videoAsset = AVURLAsset(url: url) 224 | let item = AVPlayerItem(asset: videoAsset!) 225 | let player = AVPlayer(playerItem: item) 226 | playerController.player = player 227 | addPlayerObservers() 228 | } 229 | 230 | @objc fileprivate func didTapPlay() { 231 | displayLink?.isPaused = false 232 | play() 233 | } 234 | 235 | @objc fileprivate func didTapPause() { 236 | displayLink?.isPaused = true 237 | pause() 238 | } 239 | 240 | fileprivate func play() { 241 | if isPlaying { return } 242 | isPlaying = true 243 | videoAsset?.loadValuesAsynchronously(forKeys: ["playable", "tracks", "duration"], completionHandler: { [weak self] _ in 244 | DispatchQueue.main.async { 245 | if self?.isPlaying == true { 246 | self?.playIcon.isHidden = true 247 | self?.previewImageView.isHidden = true 248 | self?.playerController.player?.play() 249 | } 250 | } 251 | }) 252 | } 253 | 254 | fileprivate func pause() { 255 | if isPlaying { 256 | isPlaying = false 257 | playIcon.isHidden = false 258 | playerController.player?.pause() 259 | } 260 | } 261 | 262 | @objc fileprivate func itemDidFinishPlaying() { 263 | if isPlaying { 264 | playerController.player?.seek(to: kCMTimeZero, toleranceBefore: kCMTimeZero, toleranceAfter: kCMTimeZero) 265 | playerController.player?.play() 266 | } 267 | } 268 | } 269 | 270 | //MARK: Player size observing part 271 | extension AGVideoPlayerView { 272 | fileprivate func addPlayerObservers() { 273 | playerController.player?.addObserver(self, forKeyPath: "rate", options: .new, context: nil) 274 | playerController.contentOverlayView?.addObserver(self, forKeyPath: "bounds", options: .new, context: nil) 275 | } 276 | 277 | fileprivate func removePlayerObservers() { 278 | playerController.player?.removeObserver(self, forKeyPath: "rate") 279 | playerController.contentOverlayView?.removeObserver(self, forKeyPath: "bounds") 280 | } 281 | 282 | override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { 283 | switch keyPath! { 284 | case "rate": 285 | self.previewImageView.isHidden = true 286 | case "bounds": 287 | let fullscreen = playerController.contentOverlayView?.bounds == UIScreen.main.bounds 288 | if isFullscreen != fullscreen { 289 | isFullscreen = fullscreen 290 | NotificationCenter.default.post(name: .playerDidChangeFullscreenMode, object: isFullscreen) 291 | } 292 | default: 293 | break 294 | } 295 | } 296 | } 297 | 298 | //MARK: Device orientation observing 299 | extension AGVideoPlayerView { 300 | @objc fileprivate func deviceOrientationDidChange(_ notification: Notification) { 301 | if isFullscreen || !isVisible() { return } 302 | if let orientation = (notification.object as? UIDevice)?.orientation, orientation == .landscapeLeft || orientation == .landscapeRight { 303 | playerController.forceFullScreenMode() 304 | updateDeviceOrientation(with: orientation) 305 | } 306 | } 307 | 308 | private func updateDeviceOrientation(with orientation: UIDeviceOrientation) { 309 | UIDevice.current.setValue(UIDeviceOrientation.portrait.rawValue, forKey: "orientation") 310 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { 311 | UIDevice.current.setValue(orientation.rawValue, forKey: "orientation") 312 | }) 313 | } 314 | } 315 | 316 | //MARK: AVPlayerViewController extension for force fullscreen mode 317 | extension AVPlayerViewController { 318 | func forceFullScreenMode() { 319 | let selectorName : String = { 320 | if #available(iOS 11, *) { 321 | return "_transitionToFullScreenAnimated:completionHandler:" 322 | } else { 323 | return "_transitionToFullScreenViewControllerAnimated:completionHandler:" 324 | } 325 | }() 326 | let selectorToForceFullScreenMode = NSSelectorFromString(selectorName) 327 | if self.responds(to: selectorToForceFullScreenMode) { 328 | self.perform(selectorToForceFullScreenMode, with: true, with: nil) 329 | } 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /VideoPlayerExample/AGVideoPlayerView/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Andrey Golovin 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 | -------------------------------------------------------------------------------- /VideoPlayerExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // VideoPlayerExample 4 | // 5 | // Created by andrii.golovin on 31.07.17. 6 | // Copyright © 2017 Andrey Golovin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | var shouldAutorotate = false 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | 19 | NotificationCenter.default.addObserver(self, selector: #selector(playerDidChangeFullscreenMode), name: .playerDidChangeFullscreenMode, object: nil) 20 | 21 | return true 22 | } 23 | 24 | func playerDidChangeFullscreenMode(_ notification: Notification) { 25 | guard let isFullscreen = notification.object as? Bool else { 26 | return 27 | } 28 | shouldAutorotate = isFullscreen 29 | if !shouldAutorotate { 30 | UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation") 31 | } 32 | } 33 | 34 | func applicationWillResignActive(_ application: UIApplication) { 35 | // 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. 36 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 37 | } 38 | 39 | func applicationDidEnterBackground(_ application: UIApplication) { 40 | // 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. 41 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 42 | } 43 | 44 | func applicationWillEnterForeground(_ application: UIApplication) { 45 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 46 | } 47 | 48 | func applicationDidBecomeActive(_ application: UIApplication) { 49 | // 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. 50 | } 51 | 52 | func applicationWillTerminate(_ application: UIApplication) { 53 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 54 | } 55 | 56 | func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { 57 | if shouldAutorotate { 58 | return .all 59 | } else { 60 | return .portrait 61 | } 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /VideoPlayerExample/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 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /VideoPlayerExample/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /VideoPlayerExample/Assets.xcassets/video_player_play_icon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "video_player_play_icon.pdf" 6 | } 7 | ], 8 | "info" : { 9 | "version" : 1, 10 | "author" : "xcode" 11 | } 12 | } -------------------------------------------------------------------------------- /VideoPlayerExample/Assets.xcassets/video_player_play_icon.imageset/video_player_play_icon.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AG-iOS/AGVideoPlayerView/122458e67285989bc98fc8c631b088fd90b01d18/VideoPlayerExample/Assets.xcassets/video_player_play_icon.imageset/video_player_play_icon.pdf -------------------------------------------------------------------------------- /VideoPlayerExample/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 | -------------------------------------------------------------------------------- /VideoPlayerExample/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 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 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 | -------------------------------------------------------------------------------- /VideoPlayerExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSAppTransportSecurity 6 | 7 | NSAllowsArbitraryLoads 8 | 9 | 10 | CFBundleDevelopmentRegion 11 | en 12 | CFBundleExecutable 13 | $(EXECUTABLE_NAME) 14 | CFBundleIdentifier 15 | $(PRODUCT_BUNDLE_IDENTIFIER) 16 | CFBundleInfoDictionaryVersion 17 | 6.0 18 | CFBundleName 19 | $(PRODUCT_NAME) 20 | CFBundlePackageType 21 | APPL 22 | CFBundleShortVersionString 23 | 1.0 24 | CFBundleVersion 25 | 1.0 26 | LSRequiresIPhoneOS 27 | 28 | UILaunchStoryboardName 29 | LaunchScreen 30 | UIMainStoryboardFile 31 | Main 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /VideoPlayerExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // 4 | // Created by Andrey Golovin on 17.02.17. 5 | // Copyright © 2017 Andrey Golovin. All rights reserved. 6 | // 7 | 8 | import UIKit 9 | 10 | class MediaCell: UITableViewCell { 11 | @IBOutlet weak var playerView: AGVideoPlayerView! 12 | } 13 | 14 | class ViewController: UIViewController { 15 | 16 | var items: [URL]! 17 | var images: [URL?]! 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | items = [URL(string: "http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4")!, 22 | URL(string: "http://yt-dash-mse-test.commondatastorage.googleapis.com/media/car-20120827-85.mp4")!, 23 | URL(string: "http://yt-dash-mse-test.commondatastorage.googleapis.com/media/oops-20120802-85.mp4")!, 24 | URL(string: "http://yt-dash-mse-test.commondatastorage.googleapis.com/media/motion-20120802-85.mp4")!] 25 | 26 | images = [URL(string: "https://i.ytimg.com/vi/aqz-KE-bpKQ/maxresdefault.jpg"), 27 | URL(string: "http://www.bialystok.pl/resource/video-thumb/192/334/6102/14724/750x415.jpg"), 28 | nil, 29 | nil] 30 | } 31 | 32 | override func didReceiveMemoryWarning() { 33 | super.didReceiveMemoryWarning() 34 | } 35 | } 36 | 37 | extension ViewController: UITableViewDataSource { 38 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 39 | return 50 40 | } 41 | 42 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 43 | let cell = tableView.dequeueReusableCell(withIdentifier: "MediaCell", for: indexPath) as! MediaCell 44 | let index = indexPath.row % 4 45 | let video = items[index] 46 | let image = images[index] 47 | 48 | cell.playerView.videoUrl = video 49 | cell.playerView.previewImageUrl = image 50 | cell.playerView.shouldAutoplay = true 51 | cell.playerView.shouldAutoRepeat = true 52 | cell.playerView.showsCustomControls = false 53 | cell.playerView.shouldSwitchToFullscreen = true 54 | return cell 55 | } 56 | } 57 | --------------------------------------------------------------------------------