mirror of
https://github.com/status-im/react-native-camera.git
synced 2026-08-30 21:21:06 +00:00
Android support for recording video (#262)
* Initial commit with Android video support * stopCapture now works * Bug fixes and parameter enhancements. README updated. * Modified stopCapture parameter count to match iOS * fixed promise bug on stopCapture * Update RCTCameraModule.java In Android preview and recording sizes are different, which can cause an error. This fix detects the difference and chooses a recording resolution that matches. * Update RCTCameraModule.java * Update RCTCamera.java Creating video functions in style/convention of existing * Update RCTCameraModule.java Use new functions for adjusting video capture size and quality * Update RCTCameraModule.java Fixes issue where file not video playable (readable) on older devices * Update AndroidManifest.xml Since we're reading and writing video and pictures, need permissions for it. * Fixed upside down camera (on some platforms), and misc bugs and crashes * Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata * To make merge nicer, temporarily reverting "Added camera-roll and capture to memory support, new options, and support for duration, filesize, and metadata" This reverts commit 9ea1ad409c7e6121cf0197172e752b7523d4b092. * Fixed merge & brought back all improvements from 9ea1ad4 * Fixed logic for video -> camera roll * Updates * Uncommenting setProfile * Fix support for React Native 0.25 * Renamed Camera to index * * Fix after merge android recording * * Fixed android camera roll file saving * Added recording to example * * Android promise rejections with exceptions * Fixed preview, video and photo sizes * Android recording result in new, javascript object, format * * Removed example.index.android.js as there is Example project * * Readme for example * don't force a specific codec * always use cache dir * * Using MediaScannerConnection instead of ACTION_MEDIA_SCANNER_SCAN_FILE intent * * As described in https://github.com/lwansbrough/react-native-camera/pull/262#issuecomment-239622268: - fixed video the wrong direction and recoder start fail at "low,medium" on the nexus 5 x
This commit is contained in:
committed by
Nicolas Charpentier
parent
1e092b5573
commit
e326d51a53
+65
-9
@@ -34,9 +34,11 @@ const styles = StyleSheet.create({
|
||||
bottomOverlay: {
|
||||
bottom: 0,
|
||||
backgroundColor: 'rgba(0,0,0,0.4)',
|
||||
flexDirection: 'row',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
},
|
||||
captureButton: {
|
||||
flex: 1,
|
||||
padding: 15,
|
||||
backgroundColor: 'white',
|
||||
borderRadius: 40,
|
||||
@@ -47,6 +49,9 @@ const styles = StyleSheet.create({
|
||||
flashButton: {
|
||||
padding: 5,
|
||||
},
|
||||
buttonsSpace: {
|
||||
width: 10,
|
||||
},
|
||||
});
|
||||
|
||||
export default class Example extends React.Component {
|
||||
@@ -63,9 +68,12 @@ export default class Example extends React.Component {
|
||||
orientation: Camera.constants.Orientation.auto,
|
||||
flashMode: Camera.constants.FlashMode.auto,
|
||||
},
|
||||
isRecording: false
|
||||
};
|
||||
|
||||
this.takePicture = this.takePicture.bind(this);
|
||||
this.startRecording = this.startRecording.bind(this);
|
||||
this.stopRecording = this.stopRecording.bind(this);
|
||||
this.switchType = this.switchType.bind(this);
|
||||
this.switchFlash = this.switchFlash.bind(this);
|
||||
}
|
||||
@@ -78,6 +86,26 @@ export default class Example extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
if (this.camera) {
|
||||
this.camera.capture({mode: Camera.constants.CaptureMode.video})
|
||||
.then((data) => console.log(data))
|
||||
.catch(err => console.error(err));
|
||||
this.setState({
|
||||
isRecording: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
stopRecording() {
|
||||
if (this.camera) {
|
||||
this.camera.stopCapture();
|
||||
this.setState({
|
||||
isRecording: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
switchType() {
|
||||
let newType;
|
||||
const { back, front } = Camera.constants.Type;
|
||||
@@ -181,14 +209,42 @@ export default class Example extends React.Component {
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
<View style={[styles.overlay, styles.bottomOverlay]}>
|
||||
<TouchableOpacity
|
||||
style={styles.captureButton}
|
||||
onPress={this.takePicture}
|
||||
>
|
||||
<Image
|
||||
source={require('./assets/ic_photo_camera_36pt.png')}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
{
|
||||
!this.state.isRecording
|
||||
&&
|
||||
<TouchableOpacity
|
||||
style={styles.captureButton}
|
||||
onPress={this.takePicture}
|
||||
>
|
||||
<Image
|
||||
source={require('./assets/ic_photo_camera_36pt.png')}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
||
|
||||
null
|
||||
}
|
||||
<View style={styles.buttonsSpace} />
|
||||
{
|
||||
!this.state.isRecording
|
||||
&&
|
||||
<TouchableOpacity
|
||||
style={styles.captureButton}
|
||||
onPress={this.startRecording}
|
||||
>
|
||||
<Image
|
||||
source={require('./assets/ic_videocam_36pt.png')}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
||
|
||||
<TouchableOpacity
|
||||
style={styles.captureButton}
|
||||
onPress={this.stopRecording}
|
||||
>
|
||||
<Image
|
||||
source={require('./assets/ic_stop_36pt.png')}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user