1

我对 react-native 和 android 应用程序构建真的很陌生,我正面临这个问题。我几乎一个星期都无法解决这个问题,所以我希望我能在这里得到一些解决方案..

一旦this.refs.cam.capture(options, cb)在 android 上,捕获方法在 android 上什么也不返回。在ios上一切正常。

类似的问题是这个#138

我无法从CameraManager.capture(options);react-native-camera/index.js 中得到任何响应。

这是我与 react-native-camera 相关的整个代码。

CameraView.js

componentWillMount() {
    navigator.geolocation.getCurrentPosition(
        (position) => {
            this.setState({ location: { latitude: position.coords.latitude, longitude: position.coords.longitude} });
        },
        error => console.log(error),
        { enableHighAccuracy: true, timeout: 7000, maximumAge: 1000 }
    )
}

startRecording() {
    const options = { location: this.state.location };

    // this is called
    //    console.log("level 1");

    // capture function is defined
    // console.log(this.camera.capture);

    this.camera.capture({ metadata: options })
        .then((data) => {
            const asset = { isStatic: true };
            if (Platform.OS === 'ios') {
                if (this.props.camera.mode === Camera.constants.CaptureMode.still) {
                    asset.uri = `data:image/jpeg;base64,${data.data}`;
                    asset.path = data.path;
                } else {
                    asset.uri = data.path.replace('file://', '');
                    asset.path = data.path.replace('file://', '');
                }
            } else if (Platform.OS === 'android') {
                if (this.props.camera.mode === Camera.constants.CaptureMode.still) {
                    // Android has no path
                    asset.uri = `data:image/jpeg;base64,${data.data}`;
                } else {
                    // TODO after capturing android
                    asset.uri = data.path.replace('file://', '');
                    asset.path = data.path.replace('file://', '');
                }
            }

            this.props.mediaSelected(asset);
            this.props.updateLatLng(this.state.location);
            if (this.props.camera.mode === Camera.constants.CaptureMode.still) {
                Image.getSize(
                    asset.uri,
                    (width, height) => {
                        this.props.updateAsset({ width, height });
                    }
                );
            }

            RouteActions.EditView();
        })
        .catch((err) => {
            // TODO error handling
            console.log(err);
        });

    this.props.startRecording();
    if (this.props.camera.mode === Camera.constants.CaptureMode.video && this.state.videoMode === 'short') {
        this.timer = setInterval(this.countTimer, 1000);
    }
}

render() {
    const isCamera = this.props.camera.mode === Camera.constants.CaptureMode.still;
    const recording = this.props.camera.isRecording;

    return (
        <View style={styles.cameraContainer}>
            <Camera
                ref={(cam) => { this.camera = cam; }}
                style={styles.preview}
                type={this.props.camera.type}
                captureMode={this.props.camera.mode}
                captureTarget={isCamera ? Camera.constants.CaptureTarget.memory : Camera.constants.CaptureTarget.disk}
                captureQuality="1080p"
                captureAudio={true}
                playSoundOnCapture={true}
                metadata={'location'}
            />

            <View>
                <TouchableOpacity onPress={this.startRecording}>
                    <Image source={require('./path.png')} resizeMode={'contain'} />
                </TouchableOpacity>

            </View>
        </View>

    );

./noed_modules/react-native-camera/index.js

capture(options) {
    const props = convertNativeProps(this.props);
    options = {
        audio: props.captureAudio,
        barCodeTypes: props.barCodeTypes,
        mode: props.captureMode,
        playSoundOnCapture: props.playSoundOnCapture,
        target: props.captureTarget,
        quality: props.captureQuality,
        type: props.type,
        title: '',
        description: '',
        mirrorImage: props.mirrorImage,
        ...options
    };

    // this is called 
    // console.log("check number 1");

    if (options.mode === Camera.constants.CaptureMode.video) {
        options.totalSeconds = (options.totalSeconds > -1 ? options.totalSeconds : -1);
        options.preferredTimeScale = options.preferredTimeScale || 30;
        this.setState({ isRecording: true });
    }

    // this is also called
    // console.log("check number 6");

    // THIS DOES NOT RETURN ANYTHING
    return CameraManager.capture(options);
}

这就是我从 android studio 运行时 logcat 所说的

07-04 15:08:09.053: I/WindowManager(93): createSurface Window{416b4db8 comp.com/comp.com.receipt paused=false}: DRAW NOW PENDING
07-04 15:08:09.133: D/dalvikvm(146): GC_FOR_ALLOC freed 339K, 36% free 10622K/16455K, paused 164ms
07-04 15:08:09.842: W/WindowManager(93): Window freeze timeout expired.
07-04 15:08:09.842: W/WindowManager(93): Force clearing orientation change: Window{416b4db8 comp.com/comp.com.receipt paused=false}
07-04 15:08:09.922: W/NetworkManagementSocketTagger(93): setKernelCountSet(10006, 0) failed with errno -2
07-04 15:08:09.922: I/ActivityManager(93): No longer want com.android.deskclock (pid 358): hidden #16
07-04 15:08:11.153: D/dalvikvm(146): GC_FOR_ALLOC freed 371K, 36% free 10612K/16455K, paused 68ms
07-04 15:08:11.363: I/Process(772): Sending signal. PID: 772 SIG: 9
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37): disableMessage: msg_type = 0xffff
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_ERROR
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_SHUTTER
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_FOCUS
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_ZOOM
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_PREVIEW_FRAME
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_VIDEO_FRAME
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_POSTVIEW_FRAME
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_RAW_IMAGE
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_COMPRESSED_IMAGE
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_RAW_IMAGE_NOTIFY
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_PREVIEW_METADATA
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37): **** Currently enabled messages:
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): doStopPreview
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): cancelPicture
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): releaseCamera
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): doStopPreview
07-04 15:08:11.403: V/EmulatedCamera_FakeDevice(37): disconnectDevice
07-04 15:08:11.403: I/CameraService(37): Destroying camera 1
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): closeCamera
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): doStopPreview

环境

  • 节点版本:7.2.0
  • 反应原生版本:0.43.3
  • 安卓 6.0、安卓 7.0
  • 模拟器 Nexus6、Nexus5 和实际设备 Sony SO-01
  • react-native-camera 版本:0.7.0

谢谢阅读!!

4

0 回答 0