Skip to content

Commit 5fb2ee9

Browse files
committed
Merge branch 'capacitor/v6'
2 parents b1de48e + ddfdfb3 commit 5fb2ee9

File tree

6 files changed

+79
-15
lines changed

6 files changed

+79
-15
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ The demo app can be found in the Example folder of this repo
126126
* [`destroy()`](#destroy)
127127
* [`flipCamera()`](#flipcamera)
128128
* [`toggleFlash()`](#toggleflash)
129+
* [`enableFlash()`](#enableflash)
130+
* [`disableFlash()`](#disableflash)
129131
* [`isFlashAvailable()`](#isflashavailable)
130132
* [`isFlashEnabled()`](#isflashenabled)
131133
* [`addPreviewFrameConfig(...)`](#addpreviewframeconfig)
@@ -185,6 +187,24 @@ toggleFlash() => Promise<void>
185187
--------------------
186188

187189

190+
### enableFlash()
191+
192+
```typescript
193+
enableFlash() => Promise<void>
194+
```
195+
196+
--------------------
197+
198+
199+
### disableFlash()
200+
201+
```typescript
202+
disableFlash() => Promise<void>
203+
```
204+
205+
--------------------
206+
207+
188208
### isFlashAvailable()
189209

190210
```typescript

android/src/main/java/com/capacitorcommunity/videorecorder/VideoRecorderPlugin.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class VideoRecorderPlugin extends Plugin {
4444
private Timer audioFeedbackTimer;
4545
private boolean timerStarted;
4646
private Integer videoBitrate = 3000000;
47+
private boolean _isFlashEnabled = false;
4748

4849
PluginCall getCall() {
4950
return call;
@@ -124,6 +125,9 @@ public void initialize(final PluginCall call) {
124125

125126
this.videoBitrate = call.getInt("videoBitrate", 3000000);
126127

128+
// flash is turned off by default when initializing camera
129+
this._isFlashEnabled = false;
130+
127131
fancyCamera = new FancyCamera(this.getContext());
128132
fancyCamera.setMaxVideoBitrate(this.videoBitrate);
129133
fancyCamera.setDisableHEVC(true);
@@ -274,13 +278,25 @@ public void togglePip(PluginCall call) {
274278
@PluginMethod()
275279
public void startRecording(PluginCall call) {
276280
fancyCamera.setAutoFocus(true);
281+
282+
// turn on flash if flash is enabled and camera is back camera
283+
if (this._isFlashEnabled && fancyCamera.getCameraPosition() == 0) {
284+
fancyCamera.enableFlash();
285+
}
286+
277287
fancyCamera.startRecording();
278288
call.resolve();
279289
}
280290

281291
@PluginMethod()
282292
public void stopRecording(PluginCall call) {
283293
this.call = call;
294+
295+
// turn off flash if flash is enabled and camera is back camera
296+
if (this._isFlashEnabled && fancyCamera.getCameraPosition() == 0) {
297+
fancyCamera.disableFlash();
298+
}
299+
284300
fancyCamera.stopRecording();
285301
}
286302

@@ -290,24 +306,36 @@ public void flipCamera(PluginCall call) {
290306
call.resolve();
291307
}
292308

309+
@PluginMethod()
310+
public void enableFlash(PluginCall call) {
311+
this._isFlashEnabled = true;
312+
call.success();
313+
}
314+
315+
@PluginMethod()
316+
public void disableFlash(PluginCall call) {
317+
this._isFlashEnabled = false;
318+
call.success();
319+
}
320+
293321
@PluginMethod()
294322
public void toggleFlash(PluginCall call) {
295-
fancyCamera.toggleFlash();
323+
this._isFlashEnabled = !this._isFlashEnabled;
296324
call.resolve();
297325
}
298326

299327
@PluginMethod()
300328
public void isFlashEnabled(PluginCall call) {
301329
JSObject object = new JSObject();
302-
object.put("isEnabled", fancyCamera.flashEnabled());
330+
object.put("isEnabled", this._isFlashEnabled);
303331
call.resolve(object);
304332
}
305333

306334
@PluginMethod()
307335
public void isFlashAvailable(PluginCall call) {
308336
JSObject object = new JSObject();
309337
object.put("isAvailable", fancyCamera.hasFlash());
310-
call.success(object);
338+
call.resolve(object);
311339
}
312340

313341
@PluginMethod()

ios/Plugin/Plugin.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
CAP_PLUGIN_METHOD(destroy, CAPPluginReturnPromise);
99
CAP_PLUGIN_METHOD(flipCamera, CAPPluginReturnPromise);
1010
CAP_PLUGIN_METHOD(toggleFlash, CAPPluginReturnPromise);
11+
CAP_PLUGIN_METHOD(enableFlash, CAPPluginReturnPromise);
12+
CAP_PLUGIN_METHOD(disableFlash, CAPPluginReturnPromise);
1113
CAP_PLUGIN_METHOD(isFlashAvailable, CAPPluginReturnPromise);
1214
CAP_PLUGIN_METHOD(isFlashEnabled, CAPPluginReturnPromise);
1315
CAP_PLUGIN_METHOD(addPreviewFrameConfig, CAPPluginReturnPromise);

ios/Plugin/Plugin.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public class VideoRecorder: CAPPlugin, AVCaptureFileOutputRecordingDelegate {
218218
// log to console for initializing
219219
print("Initializing camera")
220220

221-
// flash is turned off by default when initializing camera to match android behavior
221+
// flash is turned off by default when initializing camera
222222
self._isFlashEnabled = false;
223223

224224
if (self.captureSession?.isRunning != true) {
@@ -685,19 +685,21 @@ public class VideoRecorder: CAPPlugin, AVCaptureFileOutputRecordingDelegate {
685685
}
686686

687687
@objc func isFlashEnabled(_ call: CAPPluginCall) {
688-
if (self.currentCamera == 0) {
689-
call.resolve(["isEnabled": false])
690-
} else {
691-
call.resolve(["isEnabled": self._isFlashEnabled])
692-
}
688+
call.resolve(["isEnabled": self._isFlashEnabled])
689+
}
690+
691+
@objc func enableFlash(_ call: CAPPluginCall) {
692+
self._isFlashEnabled = true
693+
call.resolve()
694+
}
695+
696+
@objc func disableFlash(_ call: CAPPluginCall) {
697+
self._isFlashEnabled = false
698+
call.resolve()
693699
}
694700

695701
@objc func toggleFlash(_ call: CAPPluginCall) {
696-
if (self.currentCamera == 0) {
697-
call.reject("Flash not available on front camera")
698-
} else {
699-
self._isFlashEnabled = !self._isFlashEnabled
700-
call.resolve()
701-
}
702+
self._isFlashEnabled = !self._isFlashEnabled
703+
call.resolve()
702704
}
703705
}

src/definitions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface VideoRecorderPlugin {
55
destroy(): Promise<void>;
66
flipCamera(): Promise<void>;
77
toggleFlash(): Promise<void>;
8+
enableFlash(): Promise<void>;
9+
disableFlash(): Promise<void>;
810
isFlashAvailable(): Promise<{ isAvailable: boolean }>;
911
isFlashEnabled(): Promise<{ isEnabled: boolean }>;
1012
addPreviewFrameConfig(config: VideoRecorderPreviewFrame): Promise<void>;

src/web.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ export class VideoRecorderWeb extends WebPlugin implements VideoRecorderPlugin {
192192
return Promise.resolve();
193193
}
194194

195+
enableFlash(): Promise<void> {
196+
console.warn('VideoRecorder: No web mock available for enableFlash');
197+
return Promise.resolve();
198+
}
199+
200+
disableFlash(): Promise<void> {
201+
console.warn('VideoRecorder: No web mock available for disableFlash');
202+
return Promise.resolve();
203+
}
204+
195205
isFlashEnabled(): Promise<{ isEnabled: boolean; }> {
196206
console.warn('VideoRecorder: No web mock available for isFlashEnabled');
197207
return Promise.resolve({ isEnabled: false });

0 commit comments

Comments
 (0)