Add volume, rate and muted props
- Also rename pause to paused - Bump version
This commit is contained in:
parent
61508678d4
commit
fccfdbfd30
44
RCTVideo.m
44
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];
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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`
|
||||
|
@ -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',
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-video",
|
||||
"version": "0.2.3",
|
||||
"version": "0.2.4",
|
||||
"description": "A <Video> element for react-native",
|
||||
"main": "Video.ios.js",
|
||||
"author": "Brent Vatne <brentvatne@gmail.com> (https://github.com/brentvatne)",
|
||||
|
Loading…
Reference in New Issue
Block a user