├── .gitignore ├── LICENSE ├── RCTMediaPlayer.android.js ├── RCTMediaPlayer.ios.js ├── RCTMediaPlayer.xcodeproj └── project.pbxproj ├── RCTMediaPlayerVideo.h ├── RCTMediaPlayerVideo.m ├── RCTMediaPlayerVideoManager.h ├── RCTMediaPlayerVideoManager.m ├── README.md ├── package.json └── src └── RCTMediaPlayerVideo.js /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # node.js 26 | # 27 | node_modules/ 28 | npm-debug.log 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 ImprontaAdvance 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 | 23 | -------------------------------------------------------------------------------- /RCTMediaPlayer.android.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Stub of RCTMediaPlayer for Android. 3 | * 4 | * @providesModule RCTMediaPlayer 5 | * @flow 6 | */ 7 | 'use strict'; 8 | 9 | var warning = require('warning'); 10 | 11 | warning("Not yet implemented for Android."); 12 | module.exports = {}; -------------------------------------------------------------------------------- /RCTMediaPlayer.ios.js: -------------------------------------------------------------------------------- 1 | var VideoPlayer = require('./src/RCTMediaPlayerVideo'); 2 | 3 | module.exports = { 4 | VideoPlayer 5 | }; -------------------------------------------------------------------------------- /RCTMediaPlayer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 950ECAAC1B5E468A0058112E /* RCTMediaPlayerVideoManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 950ECAAB1B5E468A0058112E /* RCTMediaPlayerVideoManager.m */; }; 11 | 950ECAAF1B5E47270058112E /* RCTMediaPlayerVideo.m in Sources */ = {isa = PBXBuildFile; fileRef = 950ECAAE1B5E47270058112E /* RCTMediaPlayerVideo.m */; }; 12 | 950ECAB71B5E4E9D0058112E /* libRNOverlay.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 950ECAB61B5E4E950058112E /* libRNOverlay.a */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXContainerItemProxy section */ 16 | 950ECAB51B5E4E950058112E /* PBXContainerItemProxy */ = { 17 | isa = PBXContainerItemProxy; 18 | containerPortal = 950ECAB11B5E4E940058112E /* RNOverlay.xcodeproj */; 19 | proxyType = 2; 20 | remoteGlobalIDString = 134814201AA4EA6300B7C361; 21 | remoteInfo = RNOverlay; 22 | }; 23 | /* End PBXContainerItemProxy section */ 24 | 25 | /* Begin PBXCopyFilesBuildPhase section */ 26 | 58B511D91A9E6C8500147676 /* CopyFiles */ = { 27 | isa = PBXCopyFilesBuildPhase; 28 | buildActionMask = 2147483647; 29 | dstPath = "include/$(PRODUCT_NAME)"; 30 | dstSubfolderSpec = 16; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXCopyFilesBuildPhase section */ 36 | 37 | /* Begin PBXFileReference section */ 38 | 134814201AA4EA6300B7C361 /* libRCTMediaPlayer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTMediaPlayer.a; sourceTree = BUILT_PRODUCTS_DIR; }; 39 | 950ECAAA1B5E468A0058112E /* RCTMediaPlayerVideoManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMediaPlayerVideoManager.h; sourceTree = ""; }; 40 | 950ECAAB1B5E468A0058112E /* RCTMediaPlayerVideoManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMediaPlayerVideoManager.m; sourceTree = ""; }; 41 | 950ECAAD1B5E47270058112E /* RCTMediaPlayerVideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMediaPlayerVideo.h; sourceTree = ""; }; 42 | 950ECAAE1B5E47270058112E /* RCTMediaPlayerVideo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMediaPlayerVideo.m; sourceTree = ""; }; 43 | 950ECAB11B5E4E940058112E /* RNOverlay.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNOverlay.xcodeproj; path = "node_modules/react-native-overlay/RNOverlay.xcodeproj"; sourceTree = ""; }; 44 | /* End PBXFileReference section */ 45 | 46 | /* Begin PBXFrameworksBuildPhase section */ 47 | 58B511D81A9E6C8500147676 /* Frameworks */ = { 48 | isa = PBXFrameworksBuildPhase; 49 | buildActionMask = 2147483647; 50 | files = ( 51 | 950ECAB71B5E4E9D0058112E /* libRNOverlay.a in Frameworks */, 52 | ); 53 | runOnlyForDeploymentPostprocessing = 0; 54 | }; 55 | /* End PBXFrameworksBuildPhase section */ 56 | 57 | /* Begin PBXGroup section */ 58 | 134814211AA4EA7D00B7C361 /* Products */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 134814201AA4EA6300B7C361 /* libRCTMediaPlayer.a */, 62 | ); 63 | name = Products; 64 | sourceTree = ""; 65 | }; 66 | 58B511D21A9E6C8500147676 = { 67 | isa = PBXGroup; 68 | children = ( 69 | 950ECAB01B5E4E870058112E /* Libraries */, 70 | 950ECAAD1B5E47270058112E /* RCTMediaPlayerVideo.h */, 71 | 950ECAAE1B5E47270058112E /* RCTMediaPlayerVideo.m */, 72 | 950ECAAA1B5E468A0058112E /* RCTMediaPlayerVideoManager.h */, 73 | 950ECAAB1B5E468A0058112E /* RCTMediaPlayerVideoManager.m */, 74 | 134814211AA4EA7D00B7C361 /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 950ECAB01B5E4E870058112E /* Libraries */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 950ECAB11B5E4E940058112E /* RNOverlay.xcodeproj */, 82 | ); 83 | name = Libraries; 84 | sourceTree = ""; 85 | }; 86 | 950ECAB21B5E4E940058112E /* Products */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 950ECAB61B5E4E950058112E /* libRNOverlay.a */, 90 | ); 91 | name = Products; 92 | sourceTree = ""; 93 | }; 94 | /* End PBXGroup section */ 95 | 96 | /* Begin PBXNativeTarget section */ 97 | 58B511DA1A9E6C8500147676 /* RCTMediaPlayer */ = { 98 | isa = PBXNativeTarget; 99 | buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTMediaPlayer" */; 100 | buildPhases = ( 101 | 58B511D71A9E6C8500147676 /* Sources */, 102 | 58B511D81A9E6C8500147676 /* Frameworks */, 103 | 58B511D91A9E6C8500147676 /* CopyFiles */, 104 | ); 105 | buildRules = ( 106 | ); 107 | dependencies = ( 108 | ); 109 | name = RCTMediaPlayer; 110 | productName = RCTDataManager; 111 | productReference = 134814201AA4EA6300B7C361 /* libRCTMediaPlayer.a */; 112 | productType = "com.apple.product-type.library.static"; 113 | }; 114 | /* End PBXNativeTarget section */ 115 | 116 | /* Begin PBXProject section */ 117 | 58B511D31A9E6C8500147676 /* Project object */ = { 118 | isa = PBXProject; 119 | attributes = { 120 | LastUpgradeCheck = 0610; 121 | ORGANIZATIONNAME = Facebook; 122 | TargetAttributes = { 123 | 58B511DA1A9E6C8500147676 = { 124 | CreatedOnToolsVersion = 6.1.1; 125 | }; 126 | }; 127 | }; 128 | buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTMediaPlayer" */; 129 | compatibilityVersion = "Xcode 3.2"; 130 | developmentRegion = English; 131 | hasScannedForEncodings = 0; 132 | knownRegions = ( 133 | en, 134 | ); 135 | mainGroup = 58B511D21A9E6C8500147676; 136 | productRefGroup = 58B511D21A9E6C8500147676; 137 | projectDirPath = ""; 138 | projectReferences = ( 139 | { 140 | ProductGroup = 950ECAB21B5E4E940058112E /* Products */; 141 | ProjectRef = 950ECAB11B5E4E940058112E /* RNOverlay.xcodeproj */; 142 | }, 143 | ); 144 | projectRoot = ""; 145 | targets = ( 146 | 58B511DA1A9E6C8500147676 /* RCTMediaPlayer */, 147 | ); 148 | }; 149 | /* End PBXProject section */ 150 | 151 | /* Begin PBXReferenceProxy section */ 152 | 950ECAB61B5E4E950058112E /* libRNOverlay.a */ = { 153 | isa = PBXReferenceProxy; 154 | fileType = archive.ar; 155 | path = libRNOverlay.a; 156 | remoteRef = 950ECAB51B5E4E950058112E /* PBXContainerItemProxy */; 157 | sourceTree = BUILT_PRODUCTS_DIR; 158 | }; 159 | /* End PBXReferenceProxy section */ 160 | 161 | /* Begin PBXSourcesBuildPhase section */ 162 | 58B511D71A9E6C8500147676 /* Sources */ = { 163 | isa = PBXSourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | 950ECAAF1B5E47270058112E /* RCTMediaPlayerVideo.m in Sources */, 167 | 950ECAAC1B5E468A0058112E /* RCTMediaPlayerVideoManager.m in Sources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXSourcesBuildPhase section */ 172 | 173 | /* Begin XCBuildConfiguration section */ 174 | 58B511ED1A9E6C8500147676 /* Debug */ = { 175 | isa = XCBuildConfiguration; 176 | buildSettings = { 177 | ALWAYS_SEARCH_USER_PATHS = NO; 178 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 179 | CLANG_CXX_LIBRARY = "libc++"; 180 | CLANG_ENABLE_MODULES = YES; 181 | CLANG_ENABLE_OBJC_ARC = YES; 182 | CLANG_WARN_BOOL_CONVERSION = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 185 | CLANG_WARN_EMPTY_BODY = YES; 186 | CLANG_WARN_ENUM_CONVERSION = YES; 187 | CLANG_WARN_INT_CONVERSION = YES; 188 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 189 | CLANG_WARN_UNREACHABLE_CODE = YES; 190 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 191 | COPY_PHASE_STRIP = NO; 192 | ENABLE_STRICT_OBJC_MSGSEND = YES; 193 | GCC_C_LANGUAGE_STANDARD = gnu99; 194 | GCC_DYNAMIC_NO_PIC = NO; 195 | GCC_OPTIMIZATION_LEVEL = 0; 196 | GCC_PREPROCESSOR_DEFINITIONS = ( 197 | "DEBUG=1", 198 | "$(inherited)", 199 | ); 200 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 201 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 202 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 203 | GCC_WARN_UNDECLARED_SELECTOR = YES; 204 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 205 | GCC_WARN_UNUSED_FUNCTION = YES; 206 | GCC_WARN_UNUSED_VARIABLE = YES; 207 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 208 | MTL_ENABLE_DEBUG_INFO = YES; 209 | ONLY_ACTIVE_ARCH = YES; 210 | SDKROOT = iphoneos; 211 | }; 212 | name = Debug; 213 | }; 214 | 58B511EE1A9E6C8500147676 /* Release */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | ALWAYS_SEARCH_USER_PATHS = NO; 218 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 219 | CLANG_CXX_LIBRARY = "libc++"; 220 | CLANG_ENABLE_MODULES = YES; 221 | CLANG_ENABLE_OBJC_ARC = YES; 222 | CLANG_WARN_BOOL_CONVERSION = YES; 223 | CLANG_WARN_CONSTANT_CONVERSION = YES; 224 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 225 | CLANG_WARN_EMPTY_BODY = YES; 226 | CLANG_WARN_ENUM_CONVERSION = YES; 227 | CLANG_WARN_INT_CONVERSION = YES; 228 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 229 | CLANG_WARN_UNREACHABLE_CODE = YES; 230 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 231 | COPY_PHASE_STRIP = YES; 232 | ENABLE_NS_ASSERTIONS = NO; 233 | ENABLE_STRICT_OBJC_MSGSEND = YES; 234 | GCC_C_LANGUAGE_STANDARD = gnu99; 235 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 236 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 237 | GCC_WARN_UNDECLARED_SELECTOR = YES; 238 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 239 | GCC_WARN_UNUSED_FUNCTION = YES; 240 | GCC_WARN_UNUSED_VARIABLE = YES; 241 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 242 | MTL_ENABLE_DEBUG_INFO = NO; 243 | SDKROOT = iphoneos; 244 | VALIDATE_PRODUCT = YES; 245 | }; 246 | name = Release; 247 | }; 248 | 58B511F01A9E6C8500147676 /* Debug */ = { 249 | isa = XCBuildConfiguration; 250 | buildSettings = { 251 | HEADER_SEARCH_PATHS = ( 252 | "$(inherited)", 253 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 254 | "$(SRCROOT)/../../React/**", 255 | "$(SRCROOT)/../react-native/React/**", 256 | "$(SRCROOT)/node_modules/react-native/React/**", 257 | ); 258 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 259 | OTHER_LDFLAGS = "-ObjC"; 260 | PRODUCT_NAME = RCTMediaPlayer; 261 | SKIP_INSTALL = YES; 262 | }; 263 | name = Debug; 264 | }; 265 | 58B511F11A9E6C8500147676 /* Release */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | HEADER_SEARCH_PATHS = ( 269 | "$(inherited)", 270 | /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, 271 | "$(SRCROOT)/../../React/**", 272 | "$(SRCROOT)/../react-native/React/**", 273 | "$(SRCROOT)/node_modules/react-native/React/**", 274 | ); 275 | LIBRARY_SEARCH_PATHS = "$(inherited)"; 276 | OTHER_LDFLAGS = "-ObjC"; 277 | PRODUCT_NAME = RCTMediaPlayer; 278 | SKIP_INSTALL = YES; 279 | }; 280 | name = Release; 281 | }; 282 | /* End XCBuildConfiguration section */ 283 | 284 | /* Begin XCConfigurationList section */ 285 | 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTMediaPlayer" */ = { 286 | isa = XCConfigurationList; 287 | buildConfigurations = ( 288 | 58B511ED1A9E6C8500147676 /* Debug */, 289 | 58B511EE1A9E6C8500147676 /* Release */, 290 | ); 291 | defaultConfigurationIsVisible = 0; 292 | defaultConfigurationName = Release; 293 | }; 294 | 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTMediaPlayer" */ = { 295 | isa = XCConfigurationList; 296 | buildConfigurations = ( 297 | 58B511F01A9E6C8500147676 /* Debug */, 298 | 58B511F11A9E6C8500147676 /* Release */, 299 | ); 300 | defaultConfigurationIsVisible = 0; 301 | defaultConfigurationName = Release; 302 | }; 303 | /* End XCConfigurationList section */ 304 | }; 305 | rootObject = 58B511D31A9E6C8500147676 /* Project object */; 306 | } 307 | -------------------------------------------------------------------------------- /RCTMediaPlayerVideo.h: -------------------------------------------------------------------------------- 1 | // 2 | // RCTMediaPlayerVideo.h 3 | // RCTMediaPlayer 4 | // 5 | // Created by Matteo on 21/07/15. 6 | // Copyright (c) 2015 Facebook. All rights reserved. 7 | // 8 | 9 | #import "RCTView.h" 10 | #import 11 | 12 | extern NSString *const RCTMediaPlayerVideoEndEvent; 13 | 14 | @class RCTEventDispatcher; 15 | 16 | @interface RCTMediaPlayerVideo : UIView 17 | - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher NS_DESIGNATED_INITIALIZER; 18 | @end 19 | -------------------------------------------------------------------------------- /RCTMediaPlayerVideo.m: -------------------------------------------------------------------------------- 1 | // 2 | // RCTMediaPlayerVideo.m 3 | // RCTMediaPlayer 4 | // 5 | // Created by Matteo on 21/07/15. 6 | // Copyright (c) 2015 Facebook. All rights reserved. 7 | // 8 | #import "UIView+React.h" 9 | #import "RCTEventDispatcher.h" 10 | #import "RCTMediaPlayerVideo.h" 11 | 12 | 13 | NSString *const RCTMediaPlayerVideoEndEvent = @"improntaadvance_mediaplayer_videoEnd"; 14 | 15 | 16 | @implementation RCTMediaPlayerVideo { 17 | MPMoviePlayerController *_moviePlayer; 18 | RCTEventDispatcher *_eventDispatcher; 19 | } 20 | 21 | - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher 22 | { 23 | if ((self = [super init])) { 24 | _eventDispatcher = eventDispatcher; 25 | } 26 | 27 | return self; 28 | } 29 | 30 | - (void)setSrc:(NSString *)video 31 | { 32 | NSString *localPath = [[NSBundle mainBundle] pathForResource:video ofType:@"mp4"]; 33 | NSURL *url; 34 | 35 | if(localPath) { 36 | url = [NSURL fileURLWithPath:localPath]; 37 | } else { 38 | url = [NSURL URLWithString:video]; 39 | } 40 | 41 | _moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 42 | _moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 43 | _moviePlayer.movieSourceType = MPMovieSourceTypeFile; 44 | _moviePlayer.shouldAutoplay = YES; 45 | 46 | [self addSubview:_moviePlayer.view]; 47 | [_moviePlayer prepareToPlay]; 48 | [self attachListeners]; 49 | } 50 | 51 | - (void)attachListeners 52 | { 53 | // listen for end of file 54 | [[NSNotificationCenter defaultCenter] addObserver:self 55 | selector:@selector(playbackFinished:) 56 | name:MPMoviePlayerPlaybackDidFinishNotification 57 | object:nil]; 58 | } 59 | 60 | - (void)playbackFinished:(NSNotification*)notification { 61 | [_eventDispatcher sendInputEventWithName:RCTMediaPlayerVideoEndEvent body:@{ 62 | @"target": self.reactTag 63 | }]; 64 | } 65 | 66 | #pragma mark - React View Management 67 | 68 | - (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex 69 | { 70 | //RCTLogError(@"video cannot have any subviews"); 71 | return; 72 | } 73 | 74 | - (void)removeReactSubview:(UIView *)subview 75 | { 76 | //RCTLogError(@"video cannot have any subviews"); 77 | return; 78 | } 79 | 80 | - (void)layoutSubviews 81 | { 82 | [super layoutSubviews]; 83 | [CATransaction begin]; 84 | [CATransaction setAnimationDuration:0]; 85 | _moviePlayer.view.frame = self.bounds; 86 | [CATransaction commit]; 87 | } 88 | 89 | - (void)removeFromSuperview 90 | { 91 | 92 | [_moviePlayer pause]; 93 | _moviePlayer = nil; 94 | _eventDispatcher = nil; 95 | 96 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 97 | 98 | [super removeFromSuperview]; 99 | } 100 | @end 101 | -------------------------------------------------------------------------------- /RCTMediaPlayerVideoManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // RCTMediaPlayerVideoManager.h 3 | // RCTMediaPlayer 4 | // 5 | // Created by Matteo on 21/07/15. 6 | // Copyright (c) 2015 Facebook. All rights reserved. 7 | // 8 | 9 | #import "RCTViewManager.h" 10 | 11 | @interface RCTMediaPlayerVideoManager : RCTViewManager 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /RCTMediaPlayerVideoManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // RCTMediaPlayerVideoManager.m 3 | // RCTMediaPlayer 4 | // 5 | // Created by Matteo on 21/07/15. 6 | // Copyright (c) 2015 Facebook. All rights reserved. 7 | // 8 | 9 | #import "RCTMediaPlayerVideoManager.h" 10 | #import "RCTMediaPlayerVideo.h" 11 | #import "RCTBridge.h" 12 | 13 | 14 | @implementation RCTMediaPlayerVideoManager 15 | 16 | RCT_EXPORT_MODULE(); 17 | 18 | @synthesize bridge = _bridge; 19 | 20 | - (UIView *)view 21 | { 22 | return [[RCTMediaPlayerVideo alloc] initWithEventDispatcher:self.bridge.eventDispatcher]; 23 | } 24 | 25 | - (NSDictionary *)customDirectEventTypes 26 | { 27 | return @{ 28 | RCTMediaPlayerVideoEndEvent: @{ 29 | @"registrationName": @"onVideoEnd" 30 | } 31 | }; 32 | } 33 | 34 | - (dispatch_queue_t)methodQueue 35 | { 36 | return dispatch_get_main_queue(); 37 | } 38 | 39 | RCT_EXPORT_VIEW_PROPERTY(src, NSString); 40 | @end 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-native-media-player 2 | A React Native module that allows you to use the native Media Player Framework Reference to play movies 3 | 4 | ### Add it to your project 5 | 6 | 1. Run `npm install git+https://github.com/ImprontaAdvance/react-native-media-player.git --save` 7 | 2. Open your project in XCode, right click on `Libraries` and click `Add Files to "Your Project Name"` 8 | * ![Screenshot](http://url.brentvatne.ca/jQp8.png) ![Screenshot](http://url.brentvatne.ca/1gqUD.png) (use the RCTMediaPlayer project rather than the one pictured in screenshot). 9 | 3. Add `libRTCMediaPlayer.a` to `Build Phases -> Link Binary With Libraries` 10 | ![(Screenshot)](http://url.brentvatne.ca/g9Wp.png). 11 | 5. Whenever you want to use it within React code now you can: `var { VideoPlayer } = require('react-native-media-player'); 12 | 13 | 14 | ```javascript 15 | // Render it when you want to open video player fullscreen 16 | this.closeVideo()} /> 17 | ```` 18 | 19 | ## Examples 20 | 21 | ```javascript 22 | render() { 23 | var video; 24 | if(this.state.video) 25 | video = this.setState({video: false)} />; 26 | 27 | return ( 28 | 29 | this.setState({video: 'video.mp4'})}> 30 | Click to open video 31 | 32 | {video} 33 | 34 | ); 35 | } 36 | ```` 37 | 38 | 39 | ## TODOS 40 | 41 | - [ ] Improve example 42 | - [ ] Support iPhone resolution 43 | 44 | 45 | 46 | ## NOTES 47 | 48 | I'm not iOS developer, so feel free to send pull requests for fix, coding style and improvements. 49 | 50 | A special thanks to [brentvatne](https://github.com/brentvatne) and his [react-native-video](https://github.com/brentvatne/react-native-video). 51 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-media-player", 3 | "version": "0.0.1", 4 | "main": "RCTMediaPlayer.ios.js", 5 | "author": "Matteo Manchi ", 6 | "keywords": "react-native", 7 | "peerDependencies": { 8 | "react-native": ">=0.6.0 <1.0.0" 9 | }, 10 | "dependencies": { 11 | "react-native-overlay": "^0.2.8" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git@github.com:ImprontaAdvance/react-native-media-player.git" 16 | } 17 | } -------------------------------------------------------------------------------- /src/RCTMediaPlayerVideo.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var React = require('react-native'); 4 | var Overlay = require('react-native-overlay'); 5 | var PropTypes = require('ReactPropTypes'); 6 | 7 | 8 | class RCTMediaPlayerVideo extends React.Component { 9 | render() { 10 | var style = { 11 | width: 1024, 12 | height: 768, 13 | }; 14 | 15 | return ( 16 | 17 | this.props.onEnd()} style={style} /> 18 | 19 | ); 20 | } 21 | } 22 | 23 | RCTMediaPlayerVideo.propTypes = { 24 | src: PropTypes.string 25 | } 26 | 27 | var RCTVideo = React.requireNativeComponent('RCTMediaPlayerVideo', RCTMediaPlayerVideo); 28 | 29 | module.exports = RCTMediaPlayerVideo; --------------------------------------------------------------------------------