diff --git a/RCTVideo.m b/RCTVideo.m index 99bc2ef1..ceb74afc 100644 --- a/RCTVideo.m +++ b/RCTVideo.m @@ -18,6 +18,11 @@ id _progressUpdateTimer; int _progressUpdateInterval; NSDate *_prevProgressUpdateTime; + + /* Keep track of any modifiers, need to be applied after each play */ + float _volume; + float _rate; + BOOL _muted; } - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher @@ -84,6 +89,9 @@ }]; [_player play]; + + /* rate and volume must be set after play is called */ + [self applyModifiers]; } - (void)setResizeMode:(NSString*)mode @@ -91,20 +99,52 @@ _playerLayer.videoGravity = mode; } -- (void)setPause:(BOOL)wantsToPause +- (void)setPaused:(BOOL)paused { - if (wantsToPause) { + if (paused) { [_player pause]; } else { [_player play]; } } +- (void)setRate:(float)rate +{ + _rate = rate; + [self applyModifiers]; +} + +- (void)setMuted:(BOOL)muted +{ + _muted = muted; + [self applyModifiers]; +} + +- (void)setVolume:(float)volume { + _volume = volume; + [self applyModifiers]; +} + +- (void)applyModifiers +{ + /* volume must be set to 0 if muted is YES, or the video seems to + * freeze */ + if (_muted) { + [_player setVolume:0]; + [_player setMuted:YES]; + } else { + [_player setVolume:_volume]; + [_player setMuted:NO]; + } + + [_player setRate:_rate]; +} - (void)playerItemDidReachEnd:(NSNotification *)notification { AVPlayerItem *item = [notification object]; [item seekToTime:kCMTimeZero]; [_player play]; + [self applyModifiers]; } diff --git a/RCTVideoManager.m b/RCTVideoManager.m index 6570c3da..27fa5209 100644 --- a/RCTVideoManager.m +++ b/RCTVideoManager.m @@ -29,7 +29,10 @@ RCT_EXPORT_VIEW_PROPERTY(src, NSString); RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString); RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL); -RCT_EXPORT_VIEW_PROPERTY(pause, BOOL); +RCT_EXPORT_VIEW_PROPERTY(paused, BOOL); +RCT_EXPORT_VIEW_PROPERTY(muted, BOOL); +RCT_EXPORT_VIEW_PROPERTY(volume, float); +RCT_EXPORT_VIEW_PROPERTY(rate, float); - (NSDictionary *)constantsToExport { diff --git a/README.md b/README.md index b7ff0646..616e97fb 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,10 @@ Example code [here](https://github.com/brentvatne/react-native-login/blob/master playing videos from phone's camera - [x] Switch to AVPlayer (0.1.6) - [x] Switch resizeMode to prop instead of style (0.1.7) -- [x] Add `pause` prop (0.1.7) -- [ ] Add `playbackRate` prop -- [ ] Add `volume` prop -- [ ] Add `muted` prop +- [x] Add `paused` prop (0.1.7) +- [x] Add `rate` prop +- [x] Add `volume` prop +- [x] Add `muted` prop - [x] Add some way to get back the `currentTime` value (0.1.9 - `onProgress` prop) - [x] Add some way to get back the `duration` value (0.1.8 - `onLoad` prop) - [ ] Add some way to interface with `seekToTime` diff --git a/Video.ios.js b/Video.ios.js index 8cd3eedf..1647ccad 100644 --- a/Video.ios.js +++ b/Video.ios.js @@ -17,7 +17,10 @@ var Video = React.createClass({ style: StyleSheetPropType(VideoStylePropTypes), resizeMode: PropTypes.string, repeat: PropTypes.bool, - pause: PropTypes.bool, + paused: PropTypes.bool, + muted: PropTypes.bool, + volume: PropTypes.number, + rate: PropTypes.number, onLoad: PropTypes.func, onProgress: PropTypes.func, }, @@ -66,7 +69,8 @@ var Video = React.createClass({ var RCTVideo = createReactIOSNativeComponentClass({ validAttributes: merge(ReactIOSViewAttributes.UIView, - {src: true, resizeMode: true, repeat: true, pause: true}), + {src: true, resizeMode: true, repeat: true, paused: true, muted: true, + volume: true, rate: true}), uiViewClassName: 'RCTVideo', }); diff --git a/package.json b/package.json index 85a38631..fa9d0ad6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-video", - "version": "0.2.3", + "version": "0.2.4", "description": "A