Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plain Green image returned on some android devices #331

Open
glayn2bukman opened this issue Jun 20, 2022 · 0 comments
Open

Plain Green image returned on some android devices #331

glayn2bukman opened this issue Jun 20, 2022 · 0 comments

Comments

@glayn2bukman
Copy link

glayn2bukman commented Jun 20, 2022

Some android devices (Infinix phones in particular) only get a plain green/black image returned as base64Data in Webcam.snap.
The issue as it turns out was caused by canvas.toDataURL. The way around it was first use canvas.toBlob, then use a FileReader to read the blob as readAsDataURL (ie base64). In brief, in snap, I replaced

user_callback(
    user_canvas ? null : canvas.toDataURL('image/' + params.image_format, params.jpeg_quality / 100 ),
    canvas,
    context
);

with

if(!user_canvas){
    canvas.toBlob(function(data){
        var reader = new FileReader();
        reader.readAsDataURL(data); 
        reader.onloadend = function() {
          user_callback(reader.result,canvas,context);
        }
    }, 'image/' + params.image_format, params.jpeg_quality / 100);
}else{
   user_callback(null,canvas,context);
}

This issue has forced me to revisit every userMedia code i every wrote and update it to drop canvas.toDataURL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant