@zxing/library
Advanced tools
Comparing version 0.14.0 to 0.14.1
@@ -97,3 +97,3 @@ import BinaryBitmap from '../core/BinaryBitmap'; | ||
* | ||
* @deprecated Use `discoverVideoInputDevices` instead. | ||
* @deprecated Use `listVideoInputDevices` instead. | ||
*/ | ||
@@ -155,2 +155,11 @@ getVideoInputDevices(): Promise<VideoInputDevice[]>; | ||
/** | ||
* Checks if the given video element is currently playing. | ||
*/ | ||
isVideoPLaying(video: HTMLVideoElement): boolean; | ||
/** | ||
* Just tries to play the video and logs any errors. | ||
* The play call is only made is the video is not already playing. | ||
*/ | ||
tryPlayVideo(videoElement: HTMLVideoElement): Promise<void>; | ||
/** | ||
* Searches and validates a media element. | ||
@@ -157,0 +166,0 @@ */ |
@@ -156,3 +156,3 @@ "use strict"; | ||
* | ||
* @deprecated Use `discoverVideoInputDevices` instead. | ||
* @deprecated Use `listVideoInputDevices` instead. | ||
*/ | ||
@@ -319,3 +319,3 @@ BrowserCodeReader.prototype.getVideoInputDevices = function () { | ||
this.videoEndedListener = function () { return _this.stopStreams(); }; | ||
this.videoCanPlayListener = function () { return element.play(); }; | ||
this.videoCanPlayListener = function () { return _this.tryPlayVideo(element); }; | ||
element.addEventListener('ended', this.videoEndedListener); | ||
@@ -325,5 +325,41 @@ element.addEventListener('canplay', this.videoCanPlayListener); | ||
// if canplay was already fired, we won't know when to play, so just give it a try | ||
element.play(); | ||
this.tryPlayVideo(element); | ||
}; | ||
/** | ||
* Checks if the given video element is currently playing. | ||
*/ | ||
BrowserCodeReader.prototype.isVideoPLaying = function (video) { | ||
return !!(video.currentTime > 0 && !video.paused && !video.ended && video.readyState > 2); | ||
}; | ||
/** | ||
* Just tries to play the video and logs any errors. | ||
* The play call is only made is the video is not already playing. | ||
*/ | ||
BrowserCodeReader.prototype.tryPlayVideo = function (videoElement) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!this.isVideoPLaying(videoElement)) { | ||
console.warn('Trying yo play video that is already playing.'); | ||
return [2 /*return*/]; | ||
} | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, videoElement.play()]; | ||
case 2: | ||
_b.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
_a = _b.sent(); | ||
console.warn('It was not possible to play the video.'); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Searches and validates a media element. | ||
@@ -330,0 +366,0 @@ */ |
{ | ||
"name": "@zxing/library", | ||
"version": "0.14.0", | ||
"version": "0.14.1", | ||
"description": "TypeScript port of ZXing multi-format 1D/2D barcode image processing library.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22268
2688582