Skip to content

Commit b470b8b

Browse files
committed
add event listener to video element in image classifier
1 parent e92411f commit b470b8b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/ImageClassifier/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ class ImageClassifier {
101101
await tf.nextFrame();
102102

103103
// Classify the image using the selected model
104-
if (this.video) {
105-
if (this.video.readyState >= 2) {
104+
/* eslint arrow-body-style: 0 */
105+
if (this.videoElt && !this.addedListener) {
106+
/* eslint func-names: 0 */
107+
this.video.addEventListener('onloadstart', function () {
106108
return this.model.classify(imgToPredict, numberOfClasses).then((predictions) => {
107109
if (callback) {
108110
callback(predictions);
109111
}
110112
});
111-
}
112-
if (callback) {
113-
callback([]);
114-
}
113+
});
114+
this.addedListener = true;
115115
}
116116
return this.model.classify(imgToPredict, numberOfClasses).then((predictions) => {
117117
if (callback) {

0 commit comments

Comments
 (0)