Add support for repeat prop

This commit is contained in:
Brent Vatne 2015-03-30 23:29:15 -07:00
parent ac3d655651
commit 5408fafff8
5 changed files with 17 additions and 6 deletions

View File

@ -23,7 +23,6 @@
[_player setContentURL:videoURL]; [_player setContentURL:videoURL];
[_player setControlStyle:MPMovieControlStyleNone]; [_player setControlStyle:MPMovieControlStyleNone];
[_player setScalingMode:MPMovieScalingModeNone]; [_player setScalingMode:MPMovieScalingModeNone];
[_player setRepeatMode:MPMovieRepeatModeOne];
[_player prepareToPlay]; [_player prepareToPlay];
[_player play]; [_player play];
} }
@ -33,6 +32,15 @@
[_player setScalingMode:mode]; [_player setScalingMode:mode];
} }
- (void)setRepeat:(BOOL)repeat
{
if (repeat) {
[_player setRepeatMode:MPMovieRepeatModeOne];
} else {
[_player setRepeatMode:MPMovieRepeatModeNone];
}
}
- (NSArray *)reactSubviews - (NSArray *)reactSubviews
{ {
NSArray *subviews = @[_player.view]; NSArray *subviews = @[_player.view];

View File

@ -14,6 +14,7 @@
RCT_EXPORT_VIEW_PROPERTY(src, NSString); RCT_EXPORT_VIEW_PROPERTY(src, NSString);
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSInteger); RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSInteger);
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL);
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {

View File

@ -26,7 +26,7 @@ A <Video> component for react-native, as seen in
```javascript ```javascript
// Within your render function, assuming you have a file called // Within your render function, assuming you have a file called
// "background.mp4" in your project // "background.mp4" in your project
<Video source={"background"} style={styles.backgroundVideo} /> <Video source={"background"} style={styles.backgroundVideo} repeat={true} />
// Later on in your styles.. // Later on in your styles..
var styles = Stylesheet.create({ var styles = Stylesheet.create({
@ -47,5 +47,6 @@ Example code [here](https://github.com/brentvatne/react-native-login/blob/master
- [ ] Support `require('video!...')` - [ ] Support `require('video!...')`
- [ ] Support other extensions than mp4? - [ ] Support other extensions than mp4?
- [ ] Add prop to set repeat (none or forever) - [x] Add prop to set repeat (none or forever)
- [ ] Add support for other props (not sure which yet) - [ ] Add support [for other props](https://developer.apple.com/library/prerelease/ios/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/index.html)
- [ ] Tests..

View File

@ -15,6 +15,7 @@ var Video = React.createClass({
propTypes: { propTypes: {
source: PropTypes.string, source: PropTypes.string,
style: StyleSheetPropType(VideoStylePropTypes), style: StyleSheetPropType(VideoStylePropTypes),
repeat: PropTypes.bool,
}, },
mixins: [NativeMethodsMixin], mixins: [NativeMethodsMixin],
@ -49,7 +50,7 @@ var Video = React.createClass({
}); });
var RCTVideo = createReactIOSNativeComponentClass({ var RCTVideo = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, {src: true, resizeMode: true}), validAttributes: merge(ReactIOSViewAttributes.UIView, {src: true, resizeMode: true, repeat: true}),
uiViewClassName: 'RCTVideo', uiViewClassName: 'RCTVideo',
}); });

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-video", "name": "react-native-video",
"version": "0.1.3", "version": "0.1.4",
"description": "A <Video> element for react-native", "description": "A <Video> element for react-native",
"main": "Video.ios.js", "main": "Video.ios.js",
"author": "Brent Vatne <brentvatne@gmail.com> (https://github.com/brentvatne)", "author": "Brent Vatne <brentvatne@gmail.com> (https://github.com/brentvatne)",