Add volume, rate and muted props

- Also rename pause to paused
- Bump version
This commit is contained in:
Brent Vatne 2015-04-07 20:38:16 -07:00
parent 61508678d4
commit fccfdbfd30
5 changed files with 57 additions and 10 deletions

View File

@ -18,6 +18,11 @@
id _progressUpdateTimer; id _progressUpdateTimer;
int _progressUpdateInterval; int _progressUpdateInterval;
NSDate *_prevProgressUpdateTime; NSDate *_prevProgressUpdateTime;
/* Keep track of any modifiers, need to be applied after each play */
float _volume;
float _rate;
BOOL _muted;
} }
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher - (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
@ -84,6 +89,9 @@
}]; }];
[_player play]; [_player play];
/* rate and volume must be set after play is called */
[self applyModifiers];
} }
- (void)setResizeMode:(NSString*)mode - (void)setResizeMode:(NSString*)mode
@ -91,20 +99,52 @@
_playerLayer.videoGravity = mode; _playerLayer.videoGravity = mode;
} }
- (void)setPause:(BOOL)wantsToPause - (void)setPaused:(BOOL)paused
{ {
if (wantsToPause) { if (paused) {
[_player pause]; [_player pause];
} else { } else {
[_player play]; [_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 { - (void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *item = [notification object]; AVPlayerItem *item = [notification object];
[item seekToTime:kCMTimeZero]; [item seekToTime:kCMTimeZero];
[_player play]; [_player play];
[self applyModifiers];
} }

View File

@ -29,7 +29,10 @@
RCT_EXPORT_VIEW_PROPERTY(src, NSString); RCT_EXPORT_VIEW_PROPERTY(src, NSString);
RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString); RCT_EXPORT_VIEW_PROPERTY(resizeMode, NSString);
RCT_EXPORT_VIEW_PROPERTY(repeat, BOOL); 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 - (NSDictionary *)constantsToExport
{ {

View File

@ -51,10 +51,10 @@ Example code [here](https://github.com/brentvatne/react-native-login/blob/master
playing videos from phone's camera playing videos from phone's camera
- [x] Switch to AVPlayer (0.1.6) - [x] Switch to AVPlayer (0.1.6)
- [x] Switch resizeMode to prop instead of style (0.1.7) - [x] Switch resizeMode to prop instead of style (0.1.7)
- [x] Add `pause` prop (0.1.7) - [x] Add `paused` prop (0.1.7)
- [ ] Add `playbackRate` prop - [x] Add `rate` prop
- [ ] Add `volume` prop - [x] Add `volume` prop
- [ ] Add `muted` 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 `currentTime` value (0.1.9 - `onProgress` prop)
- [x] Add some way to get back the `duration` value (0.1.8 - `onLoad` prop) - [x] Add some way to get back the `duration` value (0.1.8 - `onLoad` prop)
- [ ] Add some way to interface with `seekToTime` - [ ] Add some way to interface with `seekToTime`

View File

@ -17,7 +17,10 @@ var Video = React.createClass({
style: StyleSheetPropType(VideoStylePropTypes), style: StyleSheetPropType(VideoStylePropTypes),
resizeMode: PropTypes.string, resizeMode: PropTypes.string,
repeat: PropTypes.bool, repeat: PropTypes.bool,
pause: PropTypes.bool, paused: PropTypes.bool,
muted: PropTypes.bool,
volume: PropTypes.number,
rate: PropTypes.number,
onLoad: PropTypes.func, onLoad: PropTypes.func,
onProgress: PropTypes.func, onProgress: PropTypes.func,
}, },
@ -66,7 +69,8 @@ var Video = React.createClass({
var RCTVideo = createReactIOSNativeComponentClass({ var RCTVideo = createReactIOSNativeComponentClass({
validAttributes: merge(ReactIOSViewAttributes.UIView, 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', uiViewClassName: 'RCTVideo',
}); });

View File

@ -1,6 +1,6 @@
{ {
"name": "react-native-video", "name": "react-native-video",
"version": "0.2.3", "version": "0.2.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)",