Skip to content

Commit 7c673a8

Browse files
committed
Make shutdown protected, refs #289
1 parent 6b1ac58 commit 7c673a8

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

webcam-capture-examples/webcam-capture-applet/src/main/java/WebcamAppletExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import javax.swing.JApplet;
44

5+
import com.github.sarxos.webcam.WebcamCaptureFrameworkDestroyer;
56
import com.github.sarxos.webcam.Webcam;
67
import com.github.sarxos.webcam.WebcamPanel;
78
import com.github.sarxos.webcam.WebcamResolution;
@@ -61,7 +62,7 @@ public void start() {
6162
public void destroy() {
6263
System.out.println("Destroy");
6364
webcam.close();
64-
Webcam.shutdown();
65+
WebcamCaptureFrameworkDestroyer.destroy();
6566
System.out.println("Destroyed");
6667
}
6768

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.sarxos.webcam;
2+
3+
/**
4+
* IMPORTANT! This approach should be used only in case of Applets (due to its non standard
5+
* lifecycle).
6+
*
7+
* @author Bartosz Firyn (sarxos)
8+
*/
9+
public class WebcamCaptureFrameworkDestroyer {
10+
11+
public static final void destroy() {
12+
Webcam.shutdown();
13+
}
14+
}

webcam-capture-examples/webcam-capture-javafx-fxml/src/main/java/WebCamPreviewController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ public void startCamera(ActionEvent event) {
222222
public void disposeCamera(ActionEvent event) {
223223
stopCamera = true;
224224
closeCamera();
225-
Webcam.shutdown();
226225
btnStopCamera.setDisable(true);
227226
btnStartCamera.setDisable(true);
228227
}

webcam-capture-examples/webcam-capture-javafx/src/main/java/WebCamAppLauncher.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ public void handle(ActionEvent arg0) {
271271
protected void disposeWebCamCamera() {
272272
stopCamera = true;
273273
webCam.close();
274-
Webcam.shutdown();
275274
btnCamreaStart.setDisable(true);
276275
btnCamreaStop.setDisable(true);
277276
}

webcam-capture/src/main/java/com/github/sarxos/webcam/Webcam.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,9 +1205,11 @@ public WebcamLock getLock() {
12051205
}
12061206

12071207
/**
1208-
* Shutdown webcam framework.
1208+
* Shutdown webcam framework. This method should be used <b>ONLY</b> when you
1209+
* are exiting JVM, but please <b>do not invoke it</b> if you really don't
1210+
* need to.
12091211
*/
1210-
public static void shutdown() {
1212+
protected static void shutdown() {
12111213

12121214
// stop discovery service
12131215
WebcamDiscoveryService discovery = getDiscoveryServiceRef();

0 commit comments

Comments
 (0)