Skip to content

Commit

Permalink
Version 3.19.0
Browse files Browse the repository at this point in the history
commit ea0e9e6
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Thu Feb 27 17:52:07 2020 +0000

    chore(release): 3.19.0 [skip ci]

    # [3.19.0](react-native-camera/react-native-camera@v3.18.0...v3.19.0) (2020-02-27)

    ### Features

    * **ios:** Expose an ability to change the frames per second via an fps option in record. ([react-native-camera#2711](react-native-camera#2711)) ([d60d201](react-native-camera@d60d201))

commit d60d201
Author: cinjon <cinjon.resnick@gmail.com>
Date:   Thu Feb 27 12:47:45 2020 -0500

    feat(ios): Expose an ability to change the frames per second via an fps option in record. (react-native-camera#2711)

commit adae4a2
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Fri Feb 14 02:26:08 2020 +0000

    chore(release): 3.18.0 [skip ci]

    # [3.18.0](react-native-camera/react-native-camera@v3.17.0...v3.18.0) (2020-02-14)

    ### Features

    * **android:** stop/release camera in non-UI thread ([react-native-camera#2685](react-native-camera#2685)) ([ba0e427](react-native-camera@ba0e427))

commit c7e92b2
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Thu Feb 13 23:21:59 2020 -0300

    feature(record): On recording start and end events (react-native-camera#2702)

    * This update tries to improve audio recording interruptions on iOS due to phone calls or background music.

    - Use a more generic event to handle session interruptions. This removes the need to listen to foreground/background events, and stopping the session this way was actually redundant/wrong (see https://forums.developer.apple.com/thread/61406). This also makes session stopping detection more reliable (calls, suspension due to a call or notification, etc., which would previously not set the recording interrupted flag on every case)

    From the above docs: "No, incorrect. You _never_ need to stop your capture session. The capture session automatically stops itself when your app goes to the background and resumes itself when you come back to the foreground."

    - Allow for `captureAudio` updates to also update the audio connections internally so the prop can be correctly updated on the fly without remounting.

    - add onAudioInterrupted and onAudioConnected events so the UI can handle scenarios where audio is wanted but not available. This should also help in keeping the preview active even if audio is interrupted and we have captureAudio={true}. Lastly, it can be used to detect if we can record audio or not due to the dummy implementation of the audio permission on iOS always returning true.

    - check, activate, and release audio sessions (if captureAudio) so we can detect early if audio is available before attempting to connect the input. This will also allow us to detect if we can record even if there was already a call before opening the camera.

    - use proper observer for session error instead of of the strong self block. No benefit, but makes code more readable and allows access to instance variables

    - getDeviceOrientationWithBlock might fire more than once under some circumstances, ending up taking a picture or video twice. Add a lock and additional check to prevent this.

    * no need for change check,

    * do not resume audio if we were hinted not to (e.g., music playback happening)

    * Move heavy work to a dedicated background thread. Improves camera initial loading and resumes from background.

    Details:

    - Use a HandlerThread to delegate heavy tasks to background. The thread is managed by the view, and passed down to the implementation in case it also needs to use it. The view will fire start calls and other possibly heavy operations in this thread to avoid ANRs. Some code sent to this thread:
        - start calls: start is extremely heavy and will cause ANRs on some devices, especially when coming back from background
        - Camera1: some preset changes fire a stop/start sequence. These will now happen in the background thread
        - take picture and start recording (from view class) will also start in this thread

    - Add some extra null checks

    - View was not properly cleaning up itself on destroy (host destroy event was never fired)

    * Fix for a possible crash when changing devices and changing focus. If the new device resets the focus, "defocusing" might not be possible if the new device does not support auto focus. For this reason, we need to do a different cleanup on the focus and exposed flags and events.

    * start session here also on session queue.

    * check for session running before trying to record or capture.
    This should fix a possible race condition where both the session start call happens at the same time as the record call

    * set preview orientation also in session queue

    * no need to set orientation on constructor, and set it on session queue to prevent race conditions

    * move device init and checks also to session queue. This prevents possible double initializations.

    * catch possible errors when starting camera preview. This might still randomly fail on some devices for some reason.

    * delay capture in progress until we have resumed/paused preview.

    * do not crash the app if set texture setup failed

    * more synchronized checks to prevent crashes due to concurrent camera updates

    * remove unused imports

    * Handle audio interruption in session queue. This prevents the session isRunning flag from getting corrupted due to concurrent updates to the session.

    * Fix possible crash when attempting to retrieve camera parameters.

    * Preserve exif/metadata on photo capture. Add a few comments to each step of the capture process

    * orientation must be fixed before mirroring

    * x/y dimensions are redundantly updated (storing the image sets them automatically). However, orientation must be reset on any image change since the final stored image is automatically rotated when it is modified in place.

    * revert mirrorImage order, has to be first since forceUpOrientation adjusts the image afterwards.

    * Minor change: also implement `onPictureTaken` for iOS in case anyone needs the early event.

    * - Improve Android code so skipProcessing is not needed, the code is more in line with iOS, and is "fast" by default. This means that skipProcessing is no longer needed (nor used), and adding additional options will "slow down" the capture as expected, rather than having always a lot of processing. This shouldn't be a breaking change.

    - document the writeExif option, and implement it for iOS as well.

    * This is a fix for events possibly being fired not on the main thread, which could cause the whole app to freeze.

    * Fire events on the right thread. No need to use UI thread, and fix the still works

    * Release CF object which could cause a memleak

    * Fix Objects.equals that is only available after API 19

    * allow for audio session to be kept even after unmounts

    * readme typo

    * readme typo

    * Make camera ready events to fire also on camera/device change to be consistent with Android. Fire unmount error when session or device fails to start.

    * update example app to properly use camera ready event

    * Make camera ready events to fire also on camera/device change to be consistent with Android. Fire unmount error when session or device fails to start. Update advanced example app to use camera ready event instead.

    * Android crash fixes. Make sure no unsupported aspect ratio is used, and do not crash when there are no cameras available.

    * stop/release camera in non-UI thread so we prevent ANRs and UI freezing.

    Some phones may take up to a second to release the camera and preview.

    * move codec, max duration, and max file size settings to the session queue.

    This might prevent a race condition when changing presets/quality.

    * android crash fix

    * Add onRecordingStart and onRecordingEnd events

    * fix for surface destroy and resume events.

    * add missing types

    * fix for surface destroy and resume events.

    * add missing types

    Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>

commit ba0e427
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Thu Feb 13 18:02:39 2020 -0300

    feat(android): stop/release camera in non-UI thread (react-native-camera#2685)

    * stop/release camera in non-UI thread so we prevent ANRs and UI freezing.

    Some phones may take up to a second to release the camera and preview.

    * fix for surface destroy and resume events.

    Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>

commit c683076
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Wed Feb 5 15:53:24 2020 +0000

    chore(release): 3.17.0 [skip ci]

    # [3.17.0](react-native-camera/react-native-camera@v3.16.0...v3.17.0) (2020-02-05)

    ### Bug Fixes

    * **record:** android crash fix ([react-native-camera#2697](react-native-camera#2697)) ([7c2572d](react-native-camera@7c2572d))

    ### Features

    * **codec:** move codec, max duration, and max file size settings to the session queue. ([react-native-camera#2694](react-native-camera#2694)) ([9b4af8e](react-native-camera@9b4af8e))

commit 7c2572d
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Wed Feb 5 12:46:02 2020 -0300

    fix(record): android crash fix (react-native-camera#2697)

    Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>

commit 9b4af8e
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Wed Feb 5 12:45:42 2020 -0300

    feat(codec): move codec, max duration, and max file size settings to the session queue. (react-native-camera#2694)

    This might prevent a race condition when changing presets/quality.

    Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>

commit 7806f84
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Mon Jan 27 20:18:11 2020 +0000

    chore(release): 3.16.0 [skip ci]

    # [3.16.0](react-native-camera/react-native-camera@v3.15.1...v3.16.0) (2020-01-27)

    ### Bug Fixes

    * **android:** crash fix for android sdk < 18 ([react-native-camera#2674](react-native-camera#2674)) ([dea3371](react-native-camera@dea3371))

    ### Features

    * **RNCameraManager:** expose videoStabilizationMode from native ([react-native-camera#2681](react-native-camera#2681)) ([cd4c8f2](react-native-camera@cd4c8f2))

commit 8761fe0
Merge: cd4c8f2 ea05b14
Author: Simon Stern <simon160@gmail.com>
Date:   Mon Jan 27 15:12:05 2020 -0500

    Merge pull request react-native-camera#2684 from jackiewung/patch-1

    add pictureSize type to RNCameraProps

commit ea05b14
Author: Jackie Wung <34897095+jackiewung@users.noreply.github.com>
Date:   Thu Jan 23 14:38:49 2020 -0800

    add pictureSize type

commit cd4c8f2
Author: mauriciopf <mauricio.perezflores@gmail.com>
Date:   Wed Jan 22 12:42:20 2020 -0500

    feat(RNCameraManager): expose videoStabilizationMode from native (react-native-camera#2681)

    * fix(RNCameraManager) expose videoStabilizationMode from native

    * refactor(types): add videoStabilization to the module declaration

commit dea3371
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Mon Jan 13 14:41:29 2020 -0300

    fix(android): crash fix for android sdk < 18 (react-native-camera#2674)

    Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>

commit b575388
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Tue Dec 31 15:35:49 2019 +0000

    chore(release): 3.15.1 [skip ci]

    ## [3.15.1](react-native-camera/react-native-camera@v3.15.0...v3.15.1) (2019-12-31)

    ### Bug Fixes

    * **android:** android  crash fixes. Make sure no unsupported aspect ratio is used, and do not crash when there are no cameras available. ([react-native-camera#2662](react-native-camera#2662)) ([db7b9e4](react-native-camera@db7b9e4))

commit db7b9e4
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Tue Dec 31 12:30:01 2019 -0300

    fix(android): android  crash fixes. Make sure no unsupported aspect ratio is used, and do not crash when there are no cameras available. (react-native-camera#2662)

commit d84127f
Merge: acfa7bd e7aa6a3
Author: Simon Stern <simon160@gmail.com>
Date:   Sat Dec 28 14:44:16 2019 -0500

    Merge pull request react-native-camera#2650 from kant/patch-1

    Semantic issue on line 50

commit acfa7bd
Merge: 5de4bc5 2cde2e7
Author: Simon Stern <simon160@gmail.com>
Date:   Sat Dec 28 14:43:36 2019 -0500

    Merge pull request react-native-camera#2657 from react-native-community/docs/api

    Docs: Added several properties to docs and organized the reference with an index

commit 5de4bc5
Merge: 2788b9d 1fa0441
Author: Simon Stern <simon160@gmail.com>
Date:   Sat Dec 28 14:04:38 2019 -0500

    Merge pull request react-native-camera#2659 from react-native-community/dependabot/npm_and_yarn/handlebars-4.5.3

    chore(deps): bump handlebars from 4.1.2 to 4.5.3

commit 1fa0441
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sat Dec 28 17:54:22 2019 +0000

    chore(deps): bump handlebars from 4.1.2 to 4.5.3

    Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.1.2 to 4.5.3.
    - [Release notes](https://github.com/wycats/handlebars.js/releases)
    - [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md)
    - [Commits](handlebars-lang/handlebars.js@v4.1.2...v4.5.3)

    Signed-off-by: dependabot[bot] <support@github.com>

commit 2788b9d
Merge: e274842 fc387c2
Author: Mateus Andrade <mateus.andrade47@outlook.com>
Date:   Sat Dec 28 14:53:39 2019 -0300

    Merge pull request react-native-camera#2658 from react-native-community/dependabot/npm_and_yarn/examples/basic/handlebars-4.5.3

    chore(deps): bump handlebars from 4.1.2 to 4.5.3 in /examples/basic

commit fc387c2
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Sat Dec 28 01:38:45 2019 +0000

    chore(deps): bump handlebars from 4.1.2 to 4.5.3 in /examples/basic

    Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.1.2 to 4.5.3.
    - [Release notes](https://github.com/wycats/handlebars.js/releases)
    - [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md)
    - [Commits](handlebars-lang/handlebars.js@v4.1.2...v4.5.3)

    Signed-off-by: dependabot[bot] <support@github.com>

commit e274842
Merge: 84cf1df 2bb2540
Author: Mateus Andrade <mateus.andrade47@outlook.com>
Date:   Thu Dec 26 17:43:15 2019 -0300

    Merge pull request react-native-camera#2651 from kant/patch-2

    Fixed typo on line 91

commit 84cf1df
Merge: 44661fc 81fcbcc
Author: Mateus Andrade <mateus.andrade47@outlook.com>
Date:   Thu Dec 26 17:15:20 2019 -0300

    Merge pull request react-native-camera#2655 from MateusAndrade/fix-ci-build

    Fix ci build

commit 81fcbcc
Author: MateusAndrade <mateus.andrade47@outlook.com>
Date:   Thu Dec 26 16:56:50 2019 -0300

    ci: adding clean to gradlew scripts

commit ae687d0
Merge: 4075cdf 44661fc
Author: Mateus Andrade <mateus.andrade47@outlook.com>
Date:   Thu Dec 26 16:51:43 2019 -0300

    Merge pull request react-native-camera#8 from react-native-community/master

    update fork

commit 2cde2e7
Author: simistern <simon160@gmail.com>
Date:   Wed Dec 25 16:00:52 2019 -0500

    Docs: Added several properties and collected the methods into an index

commit 2bb2540
Author: Darío Hereñú <magallania@gmail.com>
Date:   Wed Dec 25 02:30:25 2019 -0300

    Fixed typo on line 91

commit e7aa6a3
Author: Darío Hereñú <magallania@gmail.com>
Date:   Wed Dec 25 02:24:40 2019 -0300

    Semantic issue on line 50

commit 44661fc
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Dec 13 15:07:23 2019 -0300

    chore(deps): bump npm from 6.4.1 to 6.13.4 (react-native-camera#2643)

    Bumps [npm](https://github.com/npm/cli) from 6.4.1 to 6.13.4.
    - [Release notes](https://github.com/npm/cli/releases)
    - [Changelog](https://github.com/npm/cli/blob/latest/CHANGELOG.md)
    - [Commits](npm/cli@v6.4.1...v6.13.4)

    Signed-off-by: dependabot[bot] <support@github.com>

commit c235435
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Fri Dec 13 17:55:53 2019 +0000

    chore(release): 3.15.0 [skip ci]

    # [3.15.0](react-native-camera/react-native-camera@v3.14.0...v3.15.0) (2019-12-13)

    ### Features

    * **ios:** Make camera ready events to fire also on camera/device change to be consistent with Android. Fire unmount error when session or device fails to start. Update advanced example app to use camera ready event instead. ([react-native-camera#2642](react-native-camera#2642)) ([7abf3f7](react-native-camera@7abf3f7))

commit 7abf3f7
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Fri Dec 13 14:51:50 2019 -0300

    feat(ios): Make camera ready events to fire also on camera/device change to be consistent with Android. Fire unmount error when session or device fails to start. Update advanced example app to use camera ready event instead. (react-native-camera#2642)

commit 0745fb9
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Tue Dec 10 14:07:04 2019 +0000

    chore(release): 3.14.0 [skip ci]

    # [3.14.0](react-native-camera/react-native-camera@v3.13.1...v3.14.0) (2019-12-10)

    ### Bug Fixes

    * **android:** Fix Objects.equals that is only available after API 19 ([react-native-camera#2635](react-native-camera#2635)) ([8c6a26f](react-native-camera@8c6a26f))
    * **example:** fixes and updates in mlkit example ([react-native-camera#2618](react-native-camera#2618)) ([72c5624](react-native-camera@72c5624))
    * **ts:** fixed incorrect type definition file path ([react-native-camera#2622](react-native-camera#2622)) ([047bbea](react-native-camera@047bbea))

    ### Features

    * **android:** Load Android Gradle Plugin conditionally ([react-native-camera#2623](react-native-camera#2623)) ([d8cf6c9](react-native-camera@d8cf6c9))
    * **android:** restore state when useCamera2api is enabled ([react-native-camera#2603](react-native-camera#2603)) ([1f8b863](react-native-camera@1f8b863))
    * **docs:** update onBarCodeRead on Android and add additional SubView library ([react-native-camera#2616](react-native-camera#2616)) ([fe84811](react-native-camera@fe84811))
    * **iOS:** allow for audio session to be kept ([react-native-camera#2636](react-native-camera#2636)) ([fe5d11d](react-native-camera@fe5d11d))

commit fe5d11d
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Tue Dec 10 11:02:45 2019 -0300

    feat(iOS): allow for audio session to be kept (react-native-camera#2636)

    * allow for audio session to be kept even after unmounts

    * readme typo

commit 8c6a26f
Author: cristianoccazinsp <48869228+cristianoccazinsp@users.noreply.github.com>
Date:   Tue Dec 10 11:02:16 2019 -0300

    fix(android): Fix Objects.equals that is only available after API 19 (react-native-camera#2635)

commit 047bbea
Author: SaeedZhiany <SaeedZhiany@users.noreply.github.com>
Date:   Tue Dec 3 22:40:26 2019 +0330

    fix(ts): fixed incorrect type definition file path (react-native-camera#2622)

commit d8cf6c9
Author: SaeedZhiany <SaeedZhiany@users.noreply.github.com>
Date:   Tue Dec 3 22:39:23 2019 +0330

    feat(android): Load Android Gradle Plugin conditionally (react-native-camera#2623)

commit 1f8b863
Author: Märt Lõhmus <martlohmus12@gmail.com>
Date:   Mon Dec 2 14:28:13 2019 +0200

    feat(android): restore state when useCamera2api is enabled (react-native-camera#2603)

commit fe84811
Author: Chau Tran <ctch5@mail.umsl.edu>
Date:   Mon Dec 2 06:27:17 2019 -0600

    feat(docs): update onBarCodeRead on Android and add additional SubView library (react-native-camera#2616)

commit 72c5624
Author: Stanimir <sytolk@gmail.com>
Date:   Mon Dec 2 14:24:12 2019 +0200

    fix(example): fixes and updates in mlkit example (react-native-camera#2618)

commit 0af8ea9
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Sun Dec 1 23:56:03 2019 +0000

    chore(release): 3.13.1 [skip ci]

    ## [3.13.1](react-native-camera/react-native-camera@v3.13.0...v3.13.1) (2019-12-01)

    ### Bug Fixes

    * **android:** barcode option passing to mlkit for Android ([react-native-camera#2614](react-native-camera#2614)) ([32355f4](react-native-camera@32355f4))

commit 32355f4
Author: Kyle Johnson <1007162+kyle-johnson@users.noreply.github.com>
Date:   Sun Dec 1 15:50:57 2019 -0800

    fix(android): barcode option passing to mlkit for Android (react-native-camera#2614)

    * pass barcode options to mlkit

    * rm doubled FORMAT_ALL_FORMATS

commit c728529
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Fri Nov 29 22:04:16 2019 +0000

    chore(release): 3.13.0 [skip ci]

    # [3.13.0](react-native-camera/react-native-camera@v3.12.0...v3.13.0) (2019-11-29)

    ### Features

    * **types:** Add "URL" to Barcode types & export additional TS types ([react-native-camera#2613](react-native-camera#2613)) ([3f1334c](react-native-camera@3f1334c))

commit 3f1334c
Author: Kyle Johnson <1007162+kyle-johnson@users.noreply.github.com>
Date:   Fri Nov 29 14:00:10 2019 -0800

    feat(types): Add "URL" to Barcode types & export additional TS types (react-native-camera#2613)

    * Add "URL" to flow types

    * add "URL" to barcodes & export additional TS types

    * add optional format to flow

    * add optionl format prop to TS

commit ecb2071
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Fri Nov 29 21:18:30 2019 +0000

    chore(release): 3.12.0 [skip ci]

    # [3.12.0](react-native-camera/react-native-camera@v3.11.1...v3.12.0) (2019-11-29)

    ### Bug Fixes

    * **ios:** camera is not detecting any faces ([react-native-camera#2611](react-native-camera#2611)) ([b3d0ebe](react-native-camera@b3d0ebe))

    ### Features

    * **docs:** Feature/simplify installtion ([react-native-camera#2606](react-native-camera#2606)) ([a39e8a8](react-native-camera@a39e8a8))

commit a39e8a8
Author: mieszko4 <mieszko4@gmail.com>
Date:   Fri Nov 29 22:14:31 2019 +0100

    feat(docs): Feature/simplify installtion (react-native-camera#2606)

    * docs: split installation into 2 main sections, simplify required steps

    * doc: structure Additional installation steps

    * docs: Hide firebase additional android steps

    * docs: Highlight code snippets, add link to Windows

commit b3d0ebe
Author: annakoro <ann.korostelev@gmail.com>
Date:   Fri Nov 29 17:02:25 2019 +0300

    fix(ios): camera is not detecting any faces (react-native-camera#2611)
  • Loading branch information
susanapons89 committed Mar 10, 2020
1 parent 7f53746 commit a80210f
Show file tree
Hide file tree
Showing 17 changed files with 523 additions and 134 deletions.
108 changes: 88 additions & 20 deletions android/src/main/java/com/google/android/cameraview/Camera1.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
private boolean mIsScanning;

private boolean mustUpdateSurface;
private boolean surfaceWasDestroyed;

private SurfaceTexture mPreviewTexture;

Expand All @@ -133,12 +134,56 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
preview.setCallback(new PreviewImpl.Callback() {
@Override
public void onSurfaceChanged() {
updateSurface();

// if we got our surface destroyed
// we must re-start the camera and surface
// otherwise, just update our surface


synchronized(Camera1.this){
if(!surfaceWasDestroyed){
updateSurface();
}
else{
mBgHandler.post(new Runnable() {
@Override
public void run() {
start();
}
});
}
}
}

@Override
public void onSurfaceDestroyed() {
stop();

// need to this early so we don't get buffer errors due to sufrace going away.
// Then call stop in bg thread since it might be quite slow and will freeze
// the UI or cause an ANR while it is happening.
synchronized(Camera1.this){
if(mCamera != null){

// let the instance know our surface was destroyed
// and we might need to re-create it and restart the camera
surfaceWasDestroyed = true;

try{
mCamera.setPreviewCallback(null);
// note: this might give a debug message that can be ignored.
mCamera.setPreviewDisplay(null);
}
catch(Exception e){
Log.e("CAMERA_1::", "onSurfaceDestroyed preview cleanup failed", e);
}
}
}
mBgHandler.post(new Runnable() {
@Override
public void run() {
stop();
}
});
}
});
}
Expand Down Expand Up @@ -228,15 +273,22 @@ void stop() {
mMediaRecorder = null;

if (mIsRecording.get()) {
mCallback.onRecordingEnd();

int deviceOrientation = displayOrientationToOrientationEnum(mDeviceOrientation);
mCallback.onVideoRecorded(mVideoPath, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
}
}

if (mCamera != null) {
mIsPreviewActive = false;
mCamera.stopPreview();
mCamera.setPreviewCallback(null);
try{
mCamera.stopPreview();
mCamera.setPreviewCallback(null);
}
catch(Exception e){
Log.e("CAMERA_1::", "stop preview cleanup failed", e);
}
}

releaseCamera();
Expand All @@ -247,6 +299,8 @@ void stop() {
@SuppressLint("NewApi")
void setUpPreview() {
try {
surfaceWasDestroyed = false;

if(mCamera != null){
if (mPreviewTexture != null) {
mCamera.setPreviewTexture(mPreviewTexture);
Expand Down Expand Up @@ -754,6 +808,10 @@ boolean record(String path, int maxDuration, int maxFileSize, boolean recordAudi
Log.e("CAMERA_1::", "Record setParameters failed", e);
}

int deviceOrientation = displayOrientationToOrientationEnum(mDeviceOrientation);
mCallback.onRecordingStart(path, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);


return true;
} catch (Exception e) {
mIsRecording.set(false);
Expand Down Expand Up @@ -1414,26 +1472,36 @@ private void setUpMediaRecorder(String path, int maxDuration, int maxFileSize, b

private void stopMediaRecorder() {

if (mMediaRecorder != null) {
try {
mMediaRecorder.stop();
} catch (RuntimeException ex) {
Log.e("CAMERA_1::", "stopMediaRecorder failed", ex);
synchronized(this){
if (mMediaRecorder != null) {
try {
mMediaRecorder.stop();
} catch (RuntimeException ex) {
Log.e("CAMERA_1::", "stopMediaRecorder stop failed", ex);
}

try{
mMediaRecorder.reset();
mMediaRecorder.release();
} catch (RuntimeException ex) {
Log.e("CAMERA_1::", "stopMediaRecorder reset failed", ex);
}

mMediaRecorder = null;
}
mMediaRecorder.reset();
mMediaRecorder.release();
mMediaRecorder = null;
}

int deviceOrientation = displayOrientationToOrientationEnum(mDeviceOrientation);
if (mVideoPath == null || !new File(mVideoPath).exists()) {
mCallback.onVideoRecorded(null, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
return;
}
mCallback.onRecordingEnd();

int deviceOrientation = displayOrientationToOrientationEnum(mDeviceOrientation);

mCallback.onVideoRecorded(mVideoPath, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
mVideoPath = null;
if (mVideoPath == null || !new File(mVideoPath).exists()) {
mCallback.onVideoRecorded(null, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
return;
}

mCallback.onVideoRecorded(mVideoPath, mOrientation != Constants.ORIENTATION_AUTO ? mOrientation : deviceOrientation, deviceOrientation);
mVideoPath = null;
}
}

private void setCamcorderProfile(CamcorderProfile profile, boolean recordAudio) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ void stop() {
mMediaRecorder = null;

if (mIsRecording) {
mCallback.onRecordingEnd();

// @TODO: implement videoOrientation and deviceOrientation calculation
mCallback.onVideoRecorded(mVideoPath, 0, 0);
mIsRecording = false;
Expand Down Expand Up @@ -577,6 +579,11 @@ boolean record(String path, int maxDuration, int maxFileSize, boolean recordAudi
mSessionCallback, null);
mMediaRecorder.start();
mIsRecording = true;

// @TODO: implement videoOrientation and deviceOrientation calculation
// same TODO as onVideoRecorded
mCallback.onRecordingStart(mVideoPath, 0, 0);

return true;
} catch (CameraAccessException | IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -1366,6 +1373,8 @@ private void stopMediaRecorder() {
mMediaRecorder.release();
mMediaRecorder = null;

mCallback.onRecordingEnd();

if (mVideoPath == null || !new File(mVideoPath).exists()) {
// @TODO: implement videoOrientation and deviceOrientation calculation
mCallback.onVideoRecorded(null, 0 , 0);
Expand Down
47 changes: 37 additions & 10 deletions android/src/main/java/com/google/android/cameraview/CameraView.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ public void takePicture(ReadableMap options) {
* @param maxDuration Maximum duration of the recording, in seconds.
* @param maxFileSize Maximum recording file size, in bytes.
* @param profile Quality profile of the recording.
*
* fires {@link Callback#onRecordingStart(CameraView, String, int, int)} and {@link Callback#onRecordingEnd(CameraView)}.
*/
public boolean record(String path, int maxDuration, int maxFileSize,
boolean recordAudio, CamcorderProfile profile, int orientation) {
Expand Down Expand Up @@ -672,6 +674,20 @@ public void onPictureTaken(byte[] data, int deviceOrientation) {
}
}

@Override
public void onRecordingStart(String path, int videoOrientation, int deviceOrientation) {
for (Callback callback : mCallbacks) {
callback.onRecordingStart(CameraView.this, path, videoOrientation, deviceOrientation);
}
}

@Override
public void onRecordingEnd() {
for (Callback callback : mCallbacks) {
callback.onRecordingEnd(CameraView.this);
}
}

@Override
public void onVideoRecorded(String path, int videoOrientation, int deviceOrientation) {
for (Callback callback : mCallbacks) {
Expand Down Expand Up @@ -788,37 +804,48 @@ public abstract static class Callback {
*
* @param cameraView The associated {@link CameraView}.
*/
public void onCameraOpened(CameraView cameraView) {
}
public void onCameraOpened(CameraView cameraView) {}

/**
* Called when camera is closed.
*
* @param cameraView The associated {@link CameraView}.
*/
public void onCameraClosed(CameraView cameraView) {
}
public void onCameraClosed(CameraView cameraView) {}

/**
* Called when a picture is taken.
*
* @param cameraView The associated {@link CameraView}.
* @param data JPEG data.
*/
public void onPictureTaken(CameraView cameraView, byte[] data, int deviceOrientation) {
}
public void onPictureTaken(CameraView cameraView, byte[] data, int deviceOrientation) {}

/**
* Called when a video recording starts
*
* @param cameraView The associated {@link CameraView}.
* @param path Path to recoredd video file.
*/
public void onRecordingStart(CameraView cameraView, String path, int videoOrientation, int deviceOrientation) {}

/**
* Called when a video recording ends, but before video is saved/processed.
*
* @param cameraView The associated {@link CameraView}.
* @param path Path to recoredd video file.
*/
public void onRecordingEnd(CameraView cameraView){}

/**
* Called when a video is recorded.
*
* @param cameraView The associated {@link CameraView}.
* @param path Path to recoredd video file.
*/
public void onVideoRecorded(CameraView cameraView, String path, int videoOrientation, int deviceOrientation) {
}
public void onVideoRecorded(CameraView cameraView, String path, int videoOrientation, int deviceOrientation) {}

public void onFramePreview(CameraView cameraView, byte[] data, int width, int height, int orientation) {
}
public void onFramePreview(CameraView cameraView, byte[] data, int width, int height, int orientation) {}

public void onMountError(CameraView cameraView) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ interface Callback {

void onVideoRecorded(String path, int videoOrientation, int deviceOrientation);

void onRecordingStart(String path, int videoOrientation, int deviceOrientation);

void onRecordingEnd();

void onFramePreview(byte[] data, int width, int height, int orientation);

void onMountError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public enum Events {
EVENT_ON_BARCODE_DETECTION_ERROR("onGoogleVisionBarcodeDetectionError"),
EVENT_ON_TEXT_RECOGNIZED("onTextRecognized"),
EVENT_ON_PICTURE_TAKEN("onPictureTaken"),
EVENT_ON_PICTURE_SAVED("onPictureSaved");
EVENT_ON_PICTURE_SAVED("onPictureSaved"),
EVENT_ON_RECORDING_START("onRecordingStart"),
EVENT_ON_RECORDING_END("onRecordingEnd");

private final String mName;

Expand Down
Loading

0 comments on commit a80210f

Please sign in to comment.