Skip to content

Commit

Permalink
#18 Implemented a timeout for recording the video. Note that this onl…
Browse files Browse the repository at this point in the history
…y works

when using a device (tested with iOS) as there's an apparent timeout issue when
using Chrome Debug (see facebook/react-native#4470).
I haven't yet tested it on Android though.
  • Loading branch information
spittet committed Jul 17, 2017
1 parent 36edd4b commit 45cf685
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions src/containers/RecordScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/*
* This is the screen where the user records a capsule
*
* BIG WARNING! The timeout is likely to fail if you're using Chrome Debug.
* Check https://github.com/facebook/react-native/issues/4470 for more details.
* Instead you should run it on your mobile and everythign should be fine.
*
* @flow
*/

Expand All @@ -14,6 +18,8 @@ import styles from './styles';
class RecordScreen extends React.Component {

camera: any;
maxRecordingDuration: number;

state: {
camera: {
aspect: number,
Expand All @@ -22,26 +28,35 @@ class RecordScreen extends React.Component {
orientation: number,
flashMode: number
},
isRecording: boolean
isRecording: boolean,
recordingTimeoutID: ?number
};

constructor(props: Object) {
super(props);

this.camera = null;
this.maxRecordingDuration = 10000; // Number of seconds before timing out


this.state = {
camera: {
aspect: Camera.constants.Aspect.fill,
captureTarget: Camera.constants.CaptureTarget.cameraRoll,
captureTarget: Camera.constants.CaptureTarget.disk,
type: Camera.constants.Type.back,
orientation: Camera.constants.Orientation.auto,
flashMode: Camera.constants.FlashMode.auto,
},
isRecording: false
isRecording: false,
recordingTimeoutID: null

};
}

componentWillUnmount() {
this.clearRecordingTimer();
}

static navigationOptions = {
title: 'Record Screen',
};
Expand All @@ -51,15 +66,41 @@ class RecordScreen extends React.Component {
this.camera.capture({mode: Camera.constants.CaptureMode.video})
.then((data) => console.log(data))
.catch(err => console.error(err));

// Start timer to timeout camera
this.setRecordingTimer();

this.setState({
isRecording: true
});


}
}

setRecordingTimer = () => {
let recordingTimeoutID = setTimeout(() => {
this.stopRecording();
}, this.maxRecordingDuration);

this.setState({
recordingTimeoutID: recordingTimeoutID
});
}

clearRecordingTimer = () => {
this.state.recordingTimeoutID &&
clearTimeout(this.state.recordingTimeoutID);
}



stopRecording = () => {
if (this.camera) {
this.camera.stopCapture();

this.clearRecordingTimer();

this.setState({
isRecording: false
});
Expand Down

0 comments on commit 45cf685

Please sign in to comment.