Skip to content

Commit b521fea

Browse files
committed
Fixed deprecated URL.createObjectURL(mediaStream) for MaterialCameraCapture
1 parent ee7c77a commit b521fea

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/main/java/gwt/material/design/addins/client/camera/MaterialCameraCapture.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,23 @@ protected void nativePlay(Element video) {
242242

243243
Navigator.mediaDevices.getUserMedia(constraints).then(streamObj -> {
244244
mediaStream = (MediaStream) streamObj;
245-
if (URL.createObjectURL(mediaStream) != null) {
246-
$(video).attr("src", URL.createObjectURL(mediaStream));
247-
} else if (WebkitURL.createObjectURL(mediaStream) != null) {
248-
$(video).attr("src", WebkitURL.createObjectURL(mediaStream));
249-
}
250-
if (video instanceof VideoElement) {
251-
((VideoElement) video).play();
245+
246+
if (mediaStream != null) {
247+
try {
248+
video.setPropertyObject("srcObject", mediaStream);
249+
} catch (Exception e) {
250+
if (URL.createObjectURL(mediaStream) != null) {
251+
$(video).attr("src", URL.createObjectURL(mediaStream));
252+
} else if (WebkitURL.createObjectURL(mediaStream) != null) {
253+
$(video).attr("src", WebkitURL.createObjectURL(mediaStream));
254+
}
255+
} finally {
256+
if (video instanceof VideoElement) {
257+
((VideoElement) video).play();
258+
}
259+
}
252260
}
261+
253262
onCameraCaptureLoad();
254263
return null;
255264
}).catchException(error -> {

0 commit comments

Comments
 (0)